Skip to content

Commit 73d9303

Browse files
authored
Fix bug in remote thumbnail search (#8438)
#7124 changed the behaviour of remote thumbnails so that the thumbnailing method was included in the filename of the thumbnail. To support existing files, it included a fallback so that we would check the old filename if the new filename didn't exist. Unfortunately, it didn't apply this logic to storage providers, so any thumbnails stored on such a storage provider was broken.
1 parent 695240d commit 73d9303

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

changelog.d/8438.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a regression in v1.21.0rc1 which broke thumbnails of remote media.

synapse/rest/media/v1/media_storage.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,31 +141,34 @@ async def fetch_media(self, file_info: FileInfo) -> Optional[Responder]:
141141
Returns:
142142
Returns a Responder if the file was found, otherwise None.
143143
"""
144+
paths = [self._file_info_to_path(file_info)]
144145

145-
path = self._file_info_to_path(file_info)
146-
local_path = os.path.join(self.local_media_directory, path)
147-
if os.path.exists(local_path):
148-
return FileResponder(open(local_path, "rb"))
149-
150-
# Fallback for paths without method names
151-
# Should be removed in the future
146+
# fallback for remote thumbnails with no method in the filename
152147
if file_info.thumbnail and file_info.server_name:
153-
legacy_path = self.filepaths.remote_media_thumbnail_rel_legacy(
154-
server_name=file_info.server_name,
155-
file_id=file_info.file_id,
156-
width=file_info.thumbnail_width,
157-
height=file_info.thumbnail_height,
158-
content_type=file_info.thumbnail_type,
148+
paths.append(
149+
self.filepaths.remote_media_thumbnail_rel_legacy(
150+
server_name=file_info.server_name,
151+
file_id=file_info.file_id,
152+
width=file_info.thumbnail_width,
153+
height=file_info.thumbnail_height,
154+
content_type=file_info.thumbnail_type,
155+
)
159156
)
160-
legacy_local_path = os.path.join(self.local_media_directory, legacy_path)
161-
if os.path.exists(legacy_local_path):
162-
return FileResponder(open(legacy_local_path, "rb"))
157+
158+
for path in paths:
159+
local_path = os.path.join(self.local_media_directory, path)
160+
if os.path.exists(local_path):
161+
logger.debug("responding with local file %s", local_path)
162+
return FileResponder(open(local_path, "rb"))
163+
logger.debug("local file %s did not exist", local_path)
163164

164165
for provider in self.storage_providers:
165-
res = await provider.fetch(path, file_info) # type: Any
166-
if res:
167-
logger.debug("Streaming %s from %s", path, provider)
168-
return res
166+
for path in paths:
167+
res = await provider.fetch(path, file_info) # type: Any
168+
if res:
169+
logger.debug("Streaming %s from %s", path, provider)
170+
return res
171+
logger.debug("%s not found on %s", path, provider)
169172

170173
return None
171174

0 commit comments

Comments
 (0)