From 83745f83a52e834690a40390e5ff4ee06bfe5781 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 13 Apr 2025 15:29:56 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E5=AF=B9=E9=A3=9E?= =?UTF-8?q?=E4=B9=A6=E9=80=82=E9=85=8D=E5=99=A8=20base64=20=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E6=95=B0=E6=8D=AE=E5=85=88=E4=BF=9D=E5=AD=98=E5=88=B0?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/message/components.py | 2 ++ astrbot/core/pipeline/respond/stage.py | 1 + astrbot/core/platform/sources/lark/lark_event.py | 7 +++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/astrbot/core/message/components.py b/astrbot/core/message/components.py index 7a6284a83..781dfafca 100644 --- a/astrbot/core/message/components.py +++ b/astrbot/core/message/components.py @@ -193,6 +193,7 @@ class Record(BaseMessageComponent): bs64_data = file_to_base64(self.file) else: raise Exception(f"not a valid file: {self.file}") + bs64_data = bs64_data.removeprefix("base64://") return bs64_data @@ -397,6 +398,7 @@ class Image(BaseMessageComponent): bs64_data = file_to_base64(url) else: raise Exception(f"not a valid file: {url}") + bs64_data = bs64_data.removeprefix("base64://") return bs64_data diff --git a/astrbot/core/pipeline/respond/stage.py b/astrbot/core/pipeline/respond/stage.py index 4f8db2623..be13370f4 100644 --- a/astrbot/core/pipeline/respond/stage.py +++ b/astrbot/core/pipeline/respond/stage.py @@ -202,6 +202,7 @@ class RespondStage(Stage): try: await event.send(result) except Exception as e: + logger.error(traceback.format_exc()) logger.error(f"发送消息失败: {e} chain: {result.chain}") await event._post_send() logger.info( diff --git a/astrbot/core/platform/sources/lark/lark_event.py b/astrbot/core/platform/sources/lark/lark_event.py index fdb873ce3..b1aee548e 100644 --- a/astrbot/core/platform/sources/lark/lark_event.py +++ b/astrbot/core/platform/sources/lark/lark_event.py @@ -37,9 +37,12 @@ class LarkMessageEvent(AstrMessageEvent): image_file_path = await download_image_by_url(comp.file) file_path = image_file_path elif comp.file and comp.file.startswith("base64://"): - base64_str = comp.file[9:] + base64_str = comp.file.removeprefix("base64://") image_data = base64.b64decode(base64_str) - image_file = BytesIO(image_data).getvalue() + # save as temp file + file_path = f"data/temp/{uuid.uuid4()}_test.jpg" + with open(file_path, "wb") as f: + f.write(BytesIO(image_data).getvalue()) else: file_path = comp.file