From f7f6e4736a5534630d80dd2ebff6dc28fa01171f 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: Sun, 8 Sep 2024 10:24:36 +0800 Subject: [PATCH] fix #349 --- src/common/file.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/file.ts b/src/common/file.ts index 14f58fd7..bb5f3a23 100644 --- a/src/common/file.ts +++ b/src/common/file.ts @@ -215,6 +215,10 @@ export async function checkUriType(Uri: string) { } return { Uri: filePath, Type: FileUriType.Local }; } + if (uri.startsWith('data:')) { + let data = uri.split(',')[1]; + if (data) return { Uri: data, Type: FileUriType.Base64 }; + } }, Uri); if (OtherFileRet) return OtherFileRet; @@ -231,7 +235,8 @@ export async function uri2local(dir: string, uri: string, filename: string | und //解析File协议和本地文件 if (UriType == FileUriType.Local) { const fileExt = path.extname(HandledUri); - const filename = path.basename(HandledUri, fileExt); + let filename = path.basename(HandledUri, fileExt); + filename += fileExt; return { success: true, errMsg: '', fileName: filename, ext: fileExt, path: HandledUri, isLocal: true }; } //接下来都要有文件名 @@ -251,7 +256,7 @@ export async function uri2local(dir: string, uri: string, filename: string | und const filePath = path.join(dir, filename); const buffer = await httpDownload(HandledUri); fs.writeFileSync(filePath, buffer); - return { success: true, errMsg: '', fileName: filename, ext: fileExt, path: filePath, isLocal: true }; + return { success: true, errMsg: '', fileName: filename, ext: fileExt, path: filePath, isLocal: false }; } //解析Base64 if (UriType == FileUriType.Base64) { @@ -266,7 +271,7 @@ export async function uri2local(dir: string, uri: string, filename: string | und fileExt = ext; filename = filename + '.' + ext; } - return { success: true, errMsg: '', fileName: filename, ext: fileExt, path: filePath, isLocal: true }; + return { success: true, errMsg: '', fileName: filename, ext: fileExt, path: filePath, isLocal: false }; } return { success: false, errMsg: '未知文件类型', fileName: '', ext: '', path: '', isLocal: false }; }