chore: 文件大小限制调整为20MB
This commit is contained in:
@@ -3,7 +3,7 @@ const path = require('path');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { readFile, stat } = require('fs/promises');
|
const { readFile, stat } = require('fs/promises');
|
||||||
|
|
||||||
const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
|
const MAX_FILE_SIZE = 20 * 1024 * 1024; // 20MB
|
||||||
|
|
||||||
let mainWindow = null;
|
let mainWindow = null;
|
||||||
let activeFilePath = null; // Currently active tab's file path
|
let activeFilePath = null; // Currently active tab's file path
|
||||||
@@ -156,7 +156,7 @@ async function readFileContent(filePath) {
|
|||||||
// 文件大小检查
|
// 文件大小检查
|
||||||
const stats = await stat(filePath);
|
const stats = await stat(filePath);
|
||||||
if (stats.size > MAX_FILE_SIZE) {
|
if (stats.size > MAX_FILE_SIZE) {
|
||||||
throw new Error(`文件过大(${(stats.size / 1024 / 1024).toFixed(1)} MB),暂不支持超过 10MB 的文件`);
|
throw new Error(`文件过大(${(stats.size / 1024 / 1024).toFixed(1)} MB),暂不支持超过 20MB 的文件`);
|
||||||
}
|
}
|
||||||
let content = await readFile(filePath, 'utf-8');
|
let content = await readFile(filePath, 'utf-8');
|
||||||
// 剥离 UTF-8 BOM(Windows 某些编辑器会添加)
|
// 剥离 UTF-8 BOM(Windows 某些编辑器会添加)
|
||||||
|
|||||||
@@ -660,7 +660,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ===== File Size Limit =====
|
// ===== File Size Limit =====
|
||||||
const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
|
const MAX_FILE_SIZE = 20 * 1024 * 1024; // 20MB
|
||||||
|
|
||||||
function formatFileSize(bytes) {
|
function formatFileSize(bytes) {
|
||||||
if (bytes < 1024) return bytes + ' B';
|
if (bytes < 1024) return bytes + ' B';
|
||||||
@@ -685,7 +685,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)}),暂不支持超过 10MB 的文件`);
|
alert(`"${file.name}" 过大(${formatFileSize(file.size)}),暂不支持超过 20MB 的文件`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
@@ -850,7 +850,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)}),暂不支持超过 10MB 的文件`);
|
alert(`"${file.name}" 过大(${formatFileSize(file.size)}),暂不支持超过 20MB 的文件`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (filePath && typeof window.electronAPI !== 'undefined') {
|
if (filePath && typeof window.electronAPI !== 'undefined') {
|
||||||
|
|||||||
Reference in New Issue
Block a user