From cb861bc9553c14722139a6f15942f4bdd759da40 Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Wed, 15 Oct 2025 16:50:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9file=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增基于filename获取拓展名的函数 - 将文件大小格式化由以KB为基准修改为以Byte为基准 --- app/utils/file.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/utils/file.ts b/app/utils/file.ts index a79aad5..f21e33a 100644 --- a/app/utils/file.ts +++ b/app/utils/file.ts @@ -1,12 +1,19 @@ -export function formatFileSize(sizeInKB: number): string { - if (sizeInKB < 1024) { +export function formatFileSize(sizeInBytes: number): string { + if (sizeInBytes < 1024) { + return `${sizeInBytes.toFixed(2)} B`; + } else if (sizeInBytes < 1024 * 1024) { + const sizeInKB = sizeInBytes / 1024; return `${sizeInKB.toFixed(2)} KB`; } else { - const sizeInMB = sizeInKB / 1024; + const sizeInMB = sizeInBytes / 1024 / 1024; return `${sizeInMB.toFixed(2)} MB`; } } +export function getFileExtension(filename: string): string { + return filename.split('.').pop() || ''; +} + export function formatFileExtension(ext: string): string { return ext.startsWith('.') ? ext.slice(1).toUpperCase() : ext.toUpperCase(); }