fix(feishu): replace file.get with message_resource.get to fix file download permission issue
This commit is contained in:
@@ -555,23 +555,29 @@ class FeishuChannel(BaseChannel):
|
|||||||
filename = f"{image_key[:16]}.jpg"
|
filename = f"{image_key[:16]}.jpg"
|
||||||
|
|
||||||
|
|
||||||
elif msg_type in ("audio", "file"):
|
|
||||||
|
|
||||||
|
elif msg_type in ("audio", "file", "media"):
|
||||||
file_key = content_json.get("file_key")
|
file_key = content_json.get("file_key")
|
||||||
|
|
||||||
if file_key and message_id:
|
if file_key and message_id:
|
||||||
data, filename = await loop.run_in_executor(
|
data, filename = await loop.run_in_executor(
|
||||||
None, self._download_file_sync, message_id, file_key, msg_type
|
None, self._download_file_sync, message_id, file_key
|
||||||
)
|
)
|
||||||
if not filename:
|
if not filename:
|
||||||
ext = ".opus" if msg_type == "audio" else ""
|
if msg_type == "audio":
|
||||||
|
ext = ".opus"
|
||||||
|
elif msg_type == "media":
|
||||||
|
ext = ".mp4"
|
||||||
|
else:
|
||||||
|
ext = ""
|
||||||
filename = f"{file_key[:16]}{ext}"
|
filename = f"{file_key[:16]}{ext}"
|
||||||
|
|
||||||
if data and filename:
|
if data and filename:
|
||||||
file_path = media_dir / filename
|
file_path = media_dir / filename
|
||||||
|
|
||||||
file_path.write_bytes(data)
|
file_path.write_bytes(data)
|
||||||
|
|
||||||
logger.debug("Downloaded {} to {}", msg_type, file_path)
|
logger.debug("Downloaded {} to {}", msg_type, file_path)
|
||||||
|
|
||||||
return str(file_path), f"[{msg_type}: {filename}]"
|
return str(file_path), f"[{msg_type}: {filename}]"
|
||||||
|
|
||||||
return None, f"[{msg_type}: download failed]"
|
return None, f"[{msg_type}: download failed]"
|
||||||
@@ -698,7 +704,7 @@ class FeishuChannel(BaseChannel):
|
|||||||
if text:
|
if text:
|
||||||
content_parts.append(text)
|
content_parts.append(text)
|
||||||
|
|
||||||
elif msg_type in ("image", "audio", "file"):
|
elif msg_type in ("image", "audio", "file", "media"):
|
||||||
file_path, content_text = await self._download_and_save_media(msg_type, content_json, message_id)
|
file_path, content_text = await self._download_and_save_media(msg_type, content_json, message_id)
|
||||||
if file_path:
|
if file_path:
|
||||||
media_paths.append(file_path)
|
media_paths.append(file_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user