From 5cafba16d202c483883181d600c7c4d9c4e5a683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B2=A9=E6=B5=86?= Date: Sun, 11 Aug 2024 02:03:34 +0800 Subject: [PATCH 1/2] fix: ENOENT caused by function fileToBase64() --- src/adapter/onebot/11/convert.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapter/onebot/11/convert.ts b/src/adapter/onebot/11/convert.ts index 1ea97d60..a48af97b 100644 --- a/src/adapter/onebot/11/convert.ts +++ b/src/adapter/onebot/11/convert.ts @@ -66,7 +66,7 @@ function fileToBase64 (file: string, bot: AdapterOneBot11): string { if (!bot || !file.startsWith('file://') || !bot.adapter.connect) return file const list = ['127.0.0.1', 'localhost'] const url = new URL(bot.adapter.connect) - return list.includes(url.hostname) ? `base64://${fs.readFileSync(file).toString('base64')}` : file + return list.includes(url.hostname) ? `base64://${fs.readFileSync(file.replace(/^file:\/\//, '')).toString('base64')}` : file } /** From c72682b88c4a9f150542d84f83c8a1ffd90e51ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B2=A9=E6=B5=86?= Date: Sun, 11 Aug 2024 04:09:41 +0800 Subject: [PATCH 2/2] fix: ENOENT caused by Common.base64() --- src/utils/common/common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/common/common.ts b/src/utils/common/common.ts index c518bd58..9e408b04 100644 --- a/src/utils/common/common.ts +++ b/src/utils/common/common.ts @@ -270,7 +270,7 @@ class Common { /** file:// */ const files = file.replace(/^file:\/\//, '') - if (fs.existsSync(files)) return fs.readFileSync(file).toString('base64') + if (fs.existsSync(files)) return fs.readFileSync(files).toString('base64') /** 无前缀base64:// */ return Buffer.from(file, 'base64').toString('base64')