From cfdb9d64adbcb2a0ae309e691ac53868b85e77d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Wed, 22 Jan 2025 14:45:02 +0800 Subject: [PATCH] fix: #722 --- src/common/file.ts | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/common/file.ts b/src/common/file.ts index 2abf0689..e3ee6c46 100644 --- a/src/common/file.ts +++ b/src/common/file.ts @@ -181,28 +181,28 @@ export async function uriToLocalFile(dir: string, uri: string, filename: string const filePath = path.join(dir, filename); switch (UriType) { - case FileUriType.Local: { - const fileExt = path.extname(HandledUri); - const localFileName = path.basename(HandledUri, fileExt) + fileExt; - const tempFilePath = path.join(dir, filename + fileExt); - fs.copyFileSync(HandledUri, tempFilePath); - return { success: true, errMsg: '', fileName: localFileName, path: tempFilePath }; - } + case FileUriType.Local: { + const fileExt = path.extname(HandledUri); + const localFileName = path.basename(HandledUri, fileExt) + fileExt; + const tempFilePath = path.join(dir, filename + fileExt); + fs.copyFileSync(HandledUri, tempFilePath); + return { success: true, errMsg: '', fileName: localFileName, path: tempFilePath }; + } - case FileUriType.Remote: { - const buffer = await httpDownload({ url: HandledUri, headers: headers }); - fs.writeFileSync(filePath, buffer, { flag: 'wx' }); - return { success: true, errMsg: '', fileName: filename, path: filePath }; - } + case FileUriType.Remote: { + const buffer = await httpDownload({ url: HandledUri, headers: headers }); + fs.writeFileSync(filePath, buffer); + return { success: true, errMsg: '', fileName: filename, path: filePath }; + } - case FileUriType.Base64: { - const base64 = HandledUri.replace(/^base64:\/\//, ''); - const base64Buffer = Buffer.from(base64, 'base64'); - fs.writeFileSync(filePath, base64Buffer, { flag: 'wx' }); - return { success: true, errMsg: '', fileName: filename, path: filePath }; - } + case FileUriType.Base64: { + const base64 = HandledUri.replace(/^base64:\/\//, ''); + const base64Buffer = Buffer.from(base64, 'base64'); + fs.writeFileSync(filePath, base64Buffer); + return { success: true, errMsg: '', fileName: filename, path: filePath }; + } - default: - return { success: false, errMsg: `识别URL失败, uri= ${uri}`, fileName: '', path: '' }; + default: + return { success: false, errMsg: `识别URL失败, uri= ${uri}`, fileName: '', path: '' }; } }