mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 05:39:05 +08:00
feat(FileStorage): enhance open dialog to handle large files by retur… (#7568)
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 文件报错的问题
This commit is contained in:
parent
8723bbeaf8
commit
0160655dba
@ -363,7 +363,7 @@ class FileStorage {
|
|||||||
public open = async (
|
public open = async (
|
||||||
_: Electron.IpcMainInvokeEvent,
|
_: Electron.IpcMainInvokeEvent,
|
||||||
options: OpenDialogOptions
|
options: OpenDialogOptions
|
||||||
): Promise<{ fileName: string; filePath: string; content: Buffer } | null> => {
|
): Promise<{ fileName: string; filePath: string; content?: Buffer; size: number } | null> => {
|
||||||
try {
|
try {
|
||||||
const result: OpenDialogReturnValue = await dialog.showOpenDialog({
|
const result: OpenDialogReturnValue = await dialog.showOpenDialog({
|
||||||
title: '打开文件',
|
title: '打开文件',
|
||||||
@ -375,8 +375,16 @@ class FileStorage {
|
|||||||
if (!result.canceled && result.filePaths.length > 0) {
|
if (!result.canceled && result.filePaths.length > 0) {
|
||||||
const filePath = result.filePaths[0]
|
const filePath = result.filePaths[0]
|
||||||
const fileName = filePath.split('/').pop() || ''
|
const fileName = filePath.split('/').pop() || ''
|
||||||
const content = await readFile(filePath)
|
const stats = await fs.promises.stat(filePath)
|
||||||
return { fileName, filePath, content }
|
|
||||||
|
// 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
|
return null
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user