From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目
---
src/utils/file.ts | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/src/utils/file.ts b/src/utils/file.ts
new file mode 100644
index 0000000..e406519
--- /dev/null
+++ b/src/utils/file.ts
@@ -0,0 +1,37 @@
+/** 浠� URL 涓彁鍙栨枃浠跺悕 */
+export const getFileNameFromUrl = (url: string): string => {
+ try {
+ const urlObj = new URL(url)
+ const pathname = urlObj.pathname
+ const fileName = pathname.split('/').pop() || 'unknown'
+ return decodeURIComponent(fileName)
+ } catch {
+ // 濡傛灉 URL 瑙f瀽澶辫触锛屽皾璇曚粠瀛楃涓蹭腑鎻愬彇
+ const parts = url.split('/')
+ return parts[parts.length - 1] || 'unknown'
+ }
+}
+
+/** 鍒ゆ柇鏄惁涓哄浘鐗� */
+export const isImage = (filename: string): boolean => {
+ const ext = filename.split('.').pop()?.toLowerCase() || ''
+ return ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'].includes(ext)
+}
+
+/** 鏍煎紡鍖栨枃浠跺ぇ灏� */
+export const formatFileSize = (bytes: number): string => {
+ if (bytes === 0) return '0 B'
+ const k = 1024
+ const sizes = ['B', 'KB', 'MB', 'GB']
+ const i = Math.floor(Math.log(bytes) / Math.log(k))
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
+}
+
+/** 鑾峰彇鏂囦欢鍥炬爣 */
+export const getFileIcon = (filename: string): string => {
+ const ext = filename.split('.').pop()?.toLowerCase() || ''
+ if (isImage(ext)) {
+ return 'ep:picture'
+ }
+ return 'ep:document'
+}
--
Gitblit v1.8.0