Add media mimetype to emxc:// urls

This commit is contained in:
Antoine Pietri 2021-07-13 14:47:38 +02:00
parent 79805d02c4
commit 82d25e88ae
3 changed files with 5 additions and 3 deletions

View file

@ -1375,7 +1375,7 @@ class RoomBuffer(object):
else: else:
data = Render.encrypted_media( data = Render.encrypted_media(
event.url, event.body, event.key["k"], event.hashes["sha256"], event.url, event.body, event.key["k"], event.hashes["sha256"],
event.iv, self.homeserver.geturl() event.iv, self.homeserver.geturl(), event.mimetype,
) )
extra_prefix = (self.warning_prefix if event.decrypted extra_prefix = (self.warning_prefix if event.decrypted

View file

@ -42,14 +42,15 @@ class Render(object):
return Render._media(url, description) return Render._media(url, description)
@staticmethod @staticmethod
def encrypted_media(mxc, body, key, hash, iv, homeserver=None): def encrypted_media(mxc, body, key, hash, iv, homeserver=None, mime=None):
"""Render a mxc media URI of an encrypted file.""" """Render a mxc media URI of an encrypted file."""
http_url = Api.encrypted_mxc_to_plumb( http_url = Api.encrypted_mxc_to_plumb(
mxc, mxc,
key, key,
hash, hash,
iv, iv,
homeserver homeserver,
mime,
) )
url = http_url if http_url else mxc url = http_url if http_url else mxc
description = "{}".format(body) if body else "file" description = "{}".format(body) if body else "file"

View file

@ -214,6 +214,7 @@ class Upload(object):
self.file_keys["key"]["k"], self.file_keys["key"]["k"],
self.file_keys["hashes"]["sha256"], self.file_keys["hashes"]["sha256"],
self.file_keys["iv"], self.file_keys["iv"],
mimetype=self.file_keys.get("mimetype"),
) )
return Render.media(self.content_uri, self.file_name) return Render.media(self.content_uri, self.file_name)