From 0160655dbaa7722f1bb2c3f030bd04062a3bf1d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=A2=E5=A5=8B=E7=8C=AB?= Date: Thu, 26 Jun 2025 16:48:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(FileStorage):=20enhance=20open=20dialog=20?= =?UTF-8?q?to=20handle=20large=20files=20by=20retur=E2=80=A6=20(#7568)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(FileStorage): enhance open dialog to handle large files by returning size without reading content - Updated the open method to return file size for files larger than 2GB without reading their content. - Modified return type to include an optional content field and size property for better file handling. 修复恢复备份的时候选择超过 2GB 文件报错的问题 --- src/main/services/FileStorage.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/services/FileStorage.ts b/src/main/services/FileStorage.ts index 437f25f78c..2d8810adca 100644 --- a/src/main/services/FileStorage.ts +++ b/src/main/services/FileStorage.ts @@ -363,7 +363,7 @@ class FileStorage { public open = async ( _: Electron.IpcMainInvokeEvent, options: OpenDialogOptions - ): Promise<{ fileName: string; filePath: string; content: Buffer } | null> => { + ): Promise<{ fileName: string; filePath: string; content?: Buffer; size: number } | null> => { try { const result: OpenDialogReturnValue = await dialog.showOpenDialog({ title: '打开文件', @@ -375,8 +375,16 @@ class FileStorage { if (!result.canceled && result.filePaths.length > 0) { const filePath = result.filePaths[0] const fileName = filePath.split('/').pop() || '' - const content = await readFile(filePath) - return { fileName, filePath, content } + const stats = await fs.promises.stat(filePath) + + // If the file is less than 2GB, read the content + if (stats.size < 2 * 1024 * 1024 * 1024) { + const content = await readFile(filePath) + return { fileName, filePath, content, size: stats.size } + } + + // For large files, only return file information, do not read content + return { fileName, filePath, size: stats.size } } return null