fix(adapter): deduplicate file/attachment entries by file_id
This commit is contained in:
+8
-2
@@ -483,16 +483,18 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
attachments = msg_obj.get("attachments", [])
|
attachments = msg_obj.get("attachments", [])
|
||||||
if file_info or attachments:
|
if file_info or attachments:
|
||||||
file_details = []
|
file_details = []
|
||||||
|
seen_ids = set()
|
||||||
base_url = self.base_url.rstrip("/")
|
base_url = self.base_url.rstrip("/")
|
||||||
# Process file object if present
|
# Process file object if present (has precise MIME type)
|
||||||
if file_info and isinstance(file_info, dict):
|
if file_info and isinstance(file_info, dict):
|
||||||
filename = file_info.get("name", "unknown")
|
filename = file_info.get("name", "unknown")
|
||||||
filetype = file_info.get("type", "unknown")
|
filetype = file_info.get("type", "unknown")
|
||||||
file_id = file_info.get("_id")
|
file_id = file_info.get("_id")
|
||||||
if file_id and filename:
|
if file_id and filename:
|
||||||
|
seen_ids.add(file_id)
|
||||||
download_url = f"{base_url}/file-upload/{file_id}/{filename}"
|
download_url = f"{base_url}/file-upload/{file_id}/{filename}"
|
||||||
file_details.append(f"[FILE] {filename} ({filetype})\nDownload: {download_url}")
|
file_details.append(f"[FILE] {filename} ({filetype})\nDownload: {download_url}")
|
||||||
# Process attachments if present
|
# Process attachments if present (skip duplicates already covered by file_info)
|
||||||
if attachments and isinstance(attachments, list):
|
if attachments and isinstance(attachments, list):
|
||||||
for attachment in attachments:
|
for attachment in attachments:
|
||||||
if isinstance(attachment, dict) and attachment.get("type") == "file":
|
if isinstance(attachment, dict) and attachment.get("type") == "file":
|
||||||
@@ -503,6 +505,10 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
download_url = f"{base_url}{title_link}"
|
download_url = f"{base_url}{title_link}"
|
||||||
else:
|
else:
|
||||||
download_url = f"{base_url}/{title_link}"
|
download_url = f"{base_url}/{title_link}"
|
||||||
|
# Extract file_id from title_link to detect duplicates
|
||||||
|
link_id = title_link.split("/")[2] if title_link.startswith("/file-upload/") else None
|
||||||
|
if link_id and link_id in seen_ids:
|
||||||
|
continue # Already covered by precise file_info
|
||||||
file_details.append(f"[FILE] {title} (file)\nDownload: {download_url}")
|
file_details.append(f"[FILE] {title} (file)\nDownload: {download_url}")
|
||||||
# Add file information to message text
|
# Add file information to message text
|
||||||
if file_details:
|
if file_details:
|
||||||
|
|||||||
Reference in New Issue
Block a user