Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
efb26916 by wurstsalat at 2022-09-18T13:56:12+02:00
imprv: Preview: Improve mime type detection
Fixes #11150
- - - - -
1 changed file:
- gajim/common/preview.py
Changes:
=====================================
gajim/common/preview.py
=====================================
@@ -237,8 +237,13 @@ def _accept_uri(urlparts: ParseResult,
if urlparts.scheme in ('https', 'http'):
if app.settings.get('preview_allow_all_images'):
mime_type = guess_mime_type(uri)
- if (mime_type not in MIME_TYPES or
- mime_type == 'application/octet-stream'):
+ if mime_type not in MIME_TYPES:
+ return False
+
+ if mime_type == 'application/octet-stream' and uri != oob_url:
+ # guess_mime_type yields 'application/octet-stream' for
+ # paths without suffix. Check oob_url to make sure we
+ # display a preview for files sent via http upload.
return False
return True
@@ -345,7 +350,7 @@ def _on_orig_load_finished(self,
log.error('%s: %s', preview.orig_path.name, error)
return
- preview.mime_type = guess_mime_type(preview.orig_path)
+ preview.mime_type = guess_mime_type(preview.orig_path, data)
preview.file_size = os.path.getsize(preview.orig_path)
if preview.is_previewable:
if preview.create_thumbnail(data):
@@ -368,7 +373,7 @@ def _on_thumb_load_finished(data: Optional[bytes],
return
preview.thumbnail = data
- preview.mime_type = guess_mime_type(preview.orig_path)
+ preview.mime_type = guess_mime_type(preview.orig_path, data)
preview.file_size = os.path.getsize(preview.orig_path)
try:
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/efb269164b7c563777f1e684771cd40f76fa857d
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/efb269164b7c563777f1e684771cd40f76fa857d
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits