From c46ec32bd6396c992365d992c750ffd78e6239c3 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: Sat, 4 Jan 2025 13:12:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AE=80=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/onebot/action/extends/OCRImage.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/onebot/action/extends/OCRImage.ts b/src/onebot/action/extends/OCRImage.ts index 4957663a3..35c1a6a67 100644 --- a/src/onebot/action/extends/OCRImage.ts +++ b/src/onebot/action/extends/OCRImage.ts @@ -14,22 +14,23 @@ class OCRImageBase extends OneBotAction { payloadSchema = SchemaData; async _handle(payload: Payload) { - const { path, success } = (await uriToLocalFile(this.core.NapCatTempPath, payload.image)); + const { path, success } = await uriToLocalFile(this.core.NapCatTempPath, payload.image); if (!success) { - throw new Error(`OCR ${payload.image}失败,image字段可能格式不正确`); + throw new Error(`OCR ${payload.image}失败, image字段可能格式不正确`); } if (path) { - await checkFileExist(path, 5000); // 避免崩溃 - const ret = await this.core.apis.SystemApi.ocrImage(path); - fs.unlink(path, () => { }); - - if (!ret) { - throw new Error(`OCR ${payload.image}失败`); + try { + await checkFileExist(path, 5000); // 避免崩溃 + const ret = await this.core.apis.SystemApi.ocrImage(path); + if (!ret) { + throw new Error(`OCR ${payload.image}失败`); + } + return ret.result; + } finally { + fs.unlink(path, () => { }); } - return ret.result; } - fs.unlink(path, () => { }); - throw new Error(`OCR ${payload.image}失败,文件可能不存在`); + throw new Error(`OCR ${payload.image}失败, 文件可能不存在`); } } @@ -39,4 +40,4 @@ export class OCRImage extends OCRImageBase { export class IOCRImage extends OCRImageBase { actionName = ActionName.IOCRImage; -} +} \ No newline at end of file