chore: 删除重复的formatFileSize函数,统一用formatBytes
This commit is contained in:
@@ -721,12 +721,6 @@
|
|||||||
// ===== File Size Limit =====
|
// ===== File Size Limit =====
|
||||||
const MAX_FILE_SIZE = 20 * 1024 * 1024; // 20MB
|
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 =====
|
// ===== File Operations =====
|
||||||
async function handleOpenFile() {
|
async function handleOpenFile() {
|
||||||
if (typeof window.electronAPI !== 'undefined') {
|
if (typeof window.electronAPI !== 'undefined') {
|
||||||
@@ -744,7 +738,7 @@
|
|||||||
const ext = file.name.substring(file.name.lastIndexOf('.')).toLowerCase();
|
const ext = file.name.substring(file.name.lastIndexOf('.')).toLowerCase();
|
||||||
if (!['.md', '.markdown', '.txt'].includes(ext)) return;
|
if (!['.md', '.markdown', '.txt'].includes(ext)) return;
|
||||||
if (file.size > MAX_FILE_SIZE) {
|
if (file.size > MAX_FILE_SIZE) {
|
||||||
alert(`"${file.name}" 过大(${formatFileSize(file.size)}),暂不支持超过 20MB 的文件`);
|
alert(`"${file.name}" 过大(${formatBytes(file.size)}),暂不支持超过 20MB 的文件`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
@@ -911,7 +905,7 @@
|
|||||||
if (!allowedExts.includes(ext)) continue;
|
if (!allowedExts.includes(ext)) continue;
|
||||||
// Electron 主进程已有文件大小检查,此处为浏览器模式兜底
|
// Electron 主进程已有文件大小检查,此处为浏览器模式兜底
|
||||||
if (file.size > MAX_FILE_SIZE) {
|
if (file.size > MAX_FILE_SIZE) {
|
||||||
alert(`"${file.name}" 过大(${formatFileSize(file.size)}),暂不支持超过 20MB 的文件`);
|
alert(`"${file.name}" 过大(${formatBytes(file.size)}),暂不支持超过 20MB 的文件`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (filePath && typeof window.electronAPI !== 'undefined') {
|
if (filePath && typeof window.electronAPI !== 'undefined') {
|
||||||
|
|||||||
Reference in New Issue
Block a user