Skip to content

Commit a56e43d

Browse files
authored
fix: chatui cannot persist file segment (#5386)
1 parent e357d9d commit a56e43d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

astrbot/core/platform/sources/webchat/webchat_event.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
from .webchat_queue_mgr import webchat_queue_mgr
1313

14-
imgs_dir = os.path.join(get_astrbot_data_path(), "webchat", "imgs")
14+
attachments_dir = os.path.join(get_astrbot_data_path(), "attachments")
1515

1616

1717
class WebChatMessageEvent(AstrMessageEvent):
1818
def __init__(self, message_str, message_obj, platform_meta, session_id) -> None:
1919
super().__init__(message_str, message_obj, platform_meta, session_id)
20-
os.makedirs(imgs_dir, exist_ok=True)
20+
os.makedirs(attachments_dir, exist_ok=True)
2121

2222
@staticmethod
2323
async def _send(
@@ -69,7 +69,7 @@ async def _send(
6969
elif isinstance(comp, Image):
7070
# save image to local
7171
filename = f"{str(uuid.uuid4())}.jpg"
72-
path = os.path.join(imgs_dir, filename)
72+
path = os.path.join(attachments_dir, filename)
7373
image_base64 = await comp.convert_to_base64()
7474
with open(path, "wb") as f:
7575
f.write(base64.b64decode(image_base64))
@@ -85,7 +85,7 @@ async def _send(
8585
elif isinstance(comp, Record):
8686
# save record to local
8787
filename = f"{str(uuid.uuid4())}.wav"
88-
path = os.path.join(imgs_dir, filename)
88+
path = os.path.join(attachments_dir, filename)
8989
record_base64 = await comp.convert_to_base64()
9090
with open(path, "wb") as f:
9191
f.write(base64.b64decode(record_base64))
@@ -104,7 +104,7 @@ async def _send(
104104
original_name = comp.name or os.path.basename(file_path)
105105
ext = os.path.splitext(original_name)[1] or ""
106106
filename = f"{uuid.uuid4()!s}{ext}"
107-
dest_path = os.path.join(imgs_dir, filename)
107+
dest_path = os.path.join(attachments_dir, filename)
108108
shutil.copy2(file_path, dest_path)
109109
data = f"[FILE]{filename}"
110110
await web_chat_back_queue.put(

astrbot/dashboard/routes/chat.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,13 @@ async def _create_attachment_from_file(
215215
filename: 存储的文件名
216216
attach_type: 附件类型 (image, record, file, video)
217217
"""
218-
file_path = os.path.join(self.attachments_dir, os.path.basename(filename))
219-
if not os.path.exists(file_path):
218+
basename = os.path.basename(filename)
219+
candidate_paths = [
220+
os.path.join(self.attachments_dir, basename),
221+
os.path.join(self.legacy_img_dir, basename),
222+
]
223+
file_path = next((p for p in candidate_paths if os.path.exists(p)), None)
224+
if not file_path:
220225
return None
221226

222227
# guess mime type

0 commit comments

Comments
 (0)