From 16fa87e7dd70003b5e7530dbd8114c91470a4d72 Mon Sep 17 00:00:00 2001 From: thzxx Date: Thu, 21 May 2026 13:05:21 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=88=A0=E9=99=A4=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E7=9A=84formatFileSize=E5=87=BD=E6=95=B0=EF=BC=8C=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E7=94=A8formatBytes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- renderer/renderer.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/renderer/renderer.js b/renderer/renderer.js index 6cc75c5..9930d0e 100644 --- a/renderer/renderer.js +++ b/renderer/renderer.js @@ -721,12 +721,6 @@ // ===== File Size Limit ===== const MAX_FILE_SIZE = 20 * 1024 * 1024; // 20MB - function formatFileSize(bytes) { - if (bytes < 1024) return bytes + ' B'; - if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB'; - return (bytes / (1024 * 1024)).toFixed(1) + ' MB'; - } - // ===== File Operations ===== async function handleOpenFile() { if (typeof window.electronAPI !== 'undefined') { @@ -744,7 +738,7 @@ const ext = file.name.substring(file.name.lastIndexOf('.')).toLowerCase(); if (!['.md', '.markdown', '.txt'].includes(ext)) return; if (file.size > MAX_FILE_SIZE) { - alert(`"${file.name}" 过大(${formatFileSize(file.size)}),暂不支持超过 20MB 的文件`); + alert(`"${file.name}" 过大(${formatBytes(file.size)}),暂不支持超过 20MB 的文件`); return; } const reader = new FileReader(); @@ -911,7 +905,7 @@ if (!allowedExts.includes(ext)) continue; // Electron 主进程已有文件大小检查,此处为浏览器模式兜底 if (file.size > MAX_FILE_SIZE) { - alert(`"${file.name}" 过大(${formatFileSize(file.size)}),暂不支持超过 20MB 的文件`); + alert(`"${file.name}" 过大(${formatBytes(file.size)}),暂不支持超过 20MB 的文件`); continue; } if (filePath && typeof window.electronAPI !== 'undefined') {