From 5b1d225af231e6983242b89a3e0ca15c1664005d Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Sat, 21 May 2022 15:52:42 -0600 Subject: [PATCH] media/{download,thumbnail}: code cleanup and throw errors more aggresively --- synapse/rest/media/v1/download_resource.py | 8 ++------ synapse/rest/media/v1/thumbnail_resource.py | 12 ++++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/synapse/rest/media/v1/download_resource.py b/synapse/rest/media/v1/download_resource.py index 474bee1ed701..f01b587f574d 100644 --- a/synapse/rest/media/v1/download_resource.py +++ b/synapse/rest/media/v1/download_resource.py @@ -54,12 +54,8 @@ async def _async_render_GET(self, request: SynapseRequest) -> None: request.setHeader(b"X-Content-Security-Policy", b"sandbox;") request.setHeader(b"Referrer-Policy", b"no-referrer") server_name, media_id, name = parse_media_id(request) - max_stall_ms = ( - parse_integer( - request, "fi.mau.msc2246.max_stall_ms", default=DEFAULT_MSC2246_DELAY - ) - if self.enable_msc2246 - else DEFAULT_MSC2246_DELAY + max_stall_ms = parse_integer( + request, "fi.mau.msc2246.max_stall_ms", default=DEFAULT_MSC2246_DELAY ) if server_name == self.server_name: diff --git a/synapse/rest/media/v1/thumbnail_resource.py b/synapse/rest/media/v1/thumbnail_resource.py index 65bb8b258784..6a0b7a1fadce 100644 --- a/synapse/rest/media/v1/thumbnail_resource.py +++ b/synapse/rest/media/v1/thumbnail_resource.py @@ -65,12 +65,8 @@ async def _async_render_GET(self, request: SynapseRequest) -> None: height = parse_integer(request, "height", required=True) method = parse_string(request, "method", "scale") m_type = parse_string(request, "type", "image/png") - max_stall_ms = ( - parse_integer( - request, "fi.mau.msc2246.max_stall_ms", default=DEFAULT_MSC2246_DELAY - ) - if self.enable_msc2246 - else DEFAULT_MSC2246_DELAY + max_stall_ms = parse_integer( + request, "fi.mau.msc2246.max_stall_ms", default=DEFAULT_MSC2246_DELAY ) if server_name == self.server_name: @@ -115,6 +111,7 @@ async def _respond_local_thumbnail( request, media_id, max_stall_ms ) if not media_info: + respond_404(request) return thumbnail_infos = await self.store.get_local_media_thumbnails(media_id) @@ -145,6 +142,7 @@ async def _select_or_generate_local_thumbnail( request, media_id, max_stall_ms ) if not media_info: + respond_404(request) return thumbnail_infos = await self.store.get_local_media_thumbnails(media_id) @@ -208,6 +206,7 @@ async def _select_or_generate_remote_thumbnail( server_name, media_id, max_stall_ms ) if not media_info: + respond_404(request) return thumbnail_infos = await self.store.get_remote_media_thumbnails( @@ -279,6 +278,7 @@ async def _respond_remote_thumbnail( server_name, media_id, max_stall_ms ) if not media_info: + respond_404(request) return thumbnail_infos = await self.store.get_remote_media_thumbnails(