Merge branch 'patch_i90'

This commit is contained in:
Damir Jelić 2021-07-06 10:35:23 +02:00
commit 3dcaad8a9f

View File

@ -835,9 +835,7 @@ class ProxyDaemon:
body=await response.read(), body=await response.read(),
) )
def _get_upload_and_media_info(self, content_key, content): def _get_upload_and_media_info(self, content_uri: str):
content_uri = content[content_key]
try: try:
upload_info = self.upload_info[content_uri] upload_info = self.upload_info[content_uri]
except KeyError: except KeyError:
@ -847,7 +845,6 @@ class ProxyDaemon:
self.upload_info[content_uri] = upload_info self.upload_info[content_uri] = upload_info
content_uri = content[content_key]
mxc = urlparse(content_uri) mxc = urlparse(content_uri)
mxc_server = mxc.netloc.strip("/") mxc_server = mxc.netloc.strip("/")
mxc_path = mxc.path.strip("/") mxc_path = mxc.path.strip("/")
@ -860,8 +857,8 @@ class ProxyDaemon:
return upload_info, media_info return upload_info, media_info
async def _map_decrypted_uri(self, content_key, content, request, client): async def _decrypt_uri(self, content_uri, client):
upload_info, media_info = self._get_upload_and_media_info(content_key, content) upload_info, media_info = self._get_upload_and_media_info(content_uri)
if not upload_info or not media_info: if not upload_info or not media_info:
raise NotDecryptedAvailableError raise NotDecryptedAvailableError
@ -877,7 +874,7 @@ class ProxyDaemon:
decrypted_upload, _ = await client.upload( decrypted_upload, _ = await client.upload(
data_provider=BufferedReader(BytesIO(decrypted_file)), data_provider=BufferedReader(BytesIO(decrypted_file)),
content_type=response.content_type, content_type=upload_info.mimetype,
filename=upload_info.filename, filename=upload_info.filename,
encrypt=False, encrypt=False,
filesize=len(decrypted_file), filesize=len(decrypted_file),
@ -886,9 +883,7 @@ class ProxyDaemon:
if not isinstance(decrypted_upload, UploadResponse): if not isinstance(decrypted_upload, UploadResponse):
raise NotDecryptedAvailableError raise NotDecryptedAvailableError
content[content_key] = decrypted_upload.content_uri return decrypted_upload.content_uri
return content
async def send_message(self, request): async def send_message(self, request):
access_token = self.get_access_token(request) access_token = self.get_access_token(request)
@ -930,9 +925,9 @@ class ProxyDaemon:
or msgtype == "m.room.avatar" or msgtype == "m.room.avatar"
): ):
try: try:
content = await self._map_decrypted_uri( content["url"] = await self._decrypt_uri(content["url"], client)
"url", content, request, client if "info" in content and "thumbnail_url" in content["info"]:
) content["info"]["thumbnail_url"] = await self._decrypt_uri(content["info"]["thumbnail_url"], client)
return await self.forward_to_web( return await self.forward_to_web(
request, data=json.dumps(content), token=client.access_token request, data=json.dumps(content), token=client.access_token
) )
@ -952,9 +947,7 @@ class ProxyDaemon:
content_msgtype in ["m.image", "m.video", "m.audio", "m.file"] content_msgtype in ["m.image", "m.video", "m.audio", "m.file"]
or msgtype == "m.room.avatar" or msgtype == "m.room.avatar"
): ):
upload_info, media_info = self._get_upload_and_media_info( upload_info, media_info = self._get_upload_and_media_info(content["url"])
"url", content
)
if not upload_info or not media_info: if not upload_info or not media_info:
response = await client.room_send( response = await client.room_send(
room_id, msgtype, content, txnid, ignore_unverified room_id, msgtype, content, txnid, ignore_unverified
@ -973,7 +966,7 @@ class ProxyDaemon:
thumb_upload_info, thumb_upload_info,
thumb_media_info, thumb_media_info,
) = self._get_upload_and_media_info( ) = self._get_upload_and_media_info(
"thumbnail_url", content["info"] content["info"]["thumbnail_url"]
) )
if thumb_upload_info and thumb_media_info: if thumb_upload_info and thumb_media_info:
thumb_media_info.to_thumbnail( thumb_media_info.to_thumbnail(
@ -1272,9 +1265,7 @@ class ProxyDaemon:
return self._not_json return self._not_json
try: try:
content = await self._map_decrypted_uri( content["avatar_url"] = await self._decrypt_uri(content["avatar_url"], client)
"avatar_url", content, request, client
)
return await self.forward_to_web( return await self.forward_to_web(
request, data=json.dumps(content), token=client.access_token request, data=json.dumps(content), token=client.access_token
) )