소스 검색

Use converted mimetype when generating filename for media from Signal

Tulir Asokan 3 년 전
부모
커밋
09586c023d
1개의 변경된 파일7개의 추가작업 그리고 1개의 파일을 삭제
  1. 7 1
      mautrix_signal/portal.py

+ 7 - 1
mautrix_signal/portal.py

@@ -864,8 +864,14 @@ class Portal(DBPortal, BasePortal):
             msgtype = MessageType.FILE
             info = FileInfo(mimetype=attachment.content_type)
         if not attachment.custom_filename:
-            ext = mimetypes.guess_extension(attachment.content_type) or ""
+            ext = mimetypes.guess_extension(info.mimetype) or ""
             attachment.custom_filename = attachment.id + ext
+        else:
+            for ext in mimetypes.guess_all_extensions(info.mimetype):
+                if attachment.custom_filename.endswith(ext):
+                    break
+            else:
+                attachment.custom_filename += mimetypes.guess_extension(info.mimetype)
         if attachment.blurhash:
             info["blurhash"] = attachment.blurhash
             info["xyz.amorgan.blurhash"] = attachment.blurhash