Commit 9e3107b6 authored by nekk's avatar nekk
Browse files

[preview] try guessing MIME type if server can not

Makes webp/avif/jxl work on older servers with outdated mime databases.
Also makes it perform content sniffing for cases where file extensions
are totally wrong.
parent 84b7ff9f
Pipeline #7726 failed with stage
......@@ -464,6 +464,9 @@ class UrlImagePreviewPlugin(GajimPlugin):
if preview.is_aes_encrypted:
data = aes_decrypt(preview, data)
if preview.mime_type == 'application/octet-stream':
preview.mime_type = self._guess_mime_type(preview.orig_path, data)
......@@ -505,11 +508,11 @@ class UrlImagePreviewPlugin(GajimPlugin):
self._update_textview(preview, pixbuf)
def _guess_mime_type(file_path):
def _guess_mime_type(file_path, data = None):
mime_type, _ = mimetypes.MimeTypes().guess_type(str(file_path))
if mime_type is None:
# Try to guess MIME type by file name
mime_type, _ = Gio.content_type_guess(str(file_path), None)
mime_type, _ = Gio.content_type_guess(str(file_path), data)
log.debug('Guessed MIME type: %s', str(mime_type))
return mime_type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment