From c382f541b4c2df6ca45c8dd78552d02537f81559 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: Fri, 14 Feb 2025 17:41:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF=E5=B9=B6?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=B8=8B=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/onebot/api/msg.ts | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/onebot/api/msg.ts b/src/onebot/api/msg.ts index 4c9aa21d..4f4a2e7b 100644 --- a/src/onebot/api/msg.ts +++ b/src/onebot/api/msg.ts @@ -996,24 +996,17 @@ export class OneBotMsgApi { this.core.context.logger.logError('文件消息缺少参数', inputdata); throw new Error('文件消息缺少参数'); } - - const downloadFile = async (uri: string) => { - const { path, fileName, errMsg, success } = await uriToLocalFile(this.core.NapCatTempPath, uri); - if (!success) { - this.core.context.logger.logError('文件下载失败', errMsg); - throw new Error('文件下载失败: ' + errMsg); - } - return { path, fileName }; - }; + realUri = await this.handleObfuckName(realUri) ?? realUri; try { - const { path, fileName } = await downloadFile(realUri); - deleteAfterSentFiles.push(path); - return { path, fileName: inputdata.name ?? fileName }; - } catch { - realUri = await this.handleObfuckName(realUri); - const { path, fileName } = await downloadFile(realUri); + const { path, fileName, errMsg, success } = await uriToLocalFile(this.core.NapCatTempPath, realUri); + if (!success) { + this.core.context.logger.logError('文件处理失败', errMsg); + throw new Error('文件处理失败: ' + errMsg); + } deleteAfterSentFiles.push(path); return { path, fileName: inputdata.name ?? fileName }; + } catch (e: unknown) { + throw new Error((e as Error).message); } } @@ -1038,7 +1031,7 @@ export class OneBotMsgApi { } return url !== '' ? url : await this.core.apis.FileApi.downloadMedia(msgId, peer.chatType, peer.peerUid, elementId, '', ''); } - throw new Error('文件名解析失败'); + return undefined; } groupChangDecreseType2String(type: number): GroupDecreaseSubType {