🐛 fix: 对飞书适配器 base64 格式数据先保存到本地

This commit is contained in:
Soulter
2025-04-13 15:29:56 +08:00
parent c9079b9299
commit 83745f83a5
3 changed files with 8 additions and 2 deletions
+2
View File
@@ -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
+1
View File
@@ -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(
@@ -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