Skip to content

Commit b0a463f

Browse files
committed
fix remote thumbnails?
1 parent 8a8d01d commit b0a463f

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

synapse/rest/media/v1/media_storage.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,9 @@ async def fetch_media(self, file_info: FileInfo) -> Optional[Responder]:
143143
"""
144144

145145
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"))
149146

150-
# Fallback for paths without method names
151-
# Should be removed in the future
147+
# fallback for remote thumbnails with no method in the filename
148+
legacy_path = None
152149
if file_info.thumbnail and file_info.server_name:
153150
legacy_path = self.filepaths.remote_media_thumbnail_rel_legacy(
154151
server_name=file_info.server_name,
@@ -157,15 +154,34 @@ async def fetch_media(self, file_info: FileInfo) -> Optional[Responder]:
157154
height=file_info.thumbnail_height,
158155
content_type=file_info.thumbnail_type,
159156
)
157+
158+
local_path = os.path.join(self.local_media_directory, path)
159+
if os.path.exists(local_path):
160+
logger.debug("responding with local file %s", local_path)
161+
return FileResponder(open(local_path, "rb"))
162+
163+
if legacy_path:
164+
logger.debug(
165+
"local file %s did not exist; checking legacy name", local_path
166+
)
160167
legacy_local_path = os.path.join(self.local_media_directory, legacy_path)
161168
if os.path.exists(legacy_local_path):
169+
logger.debug("responding with local file %s", legacy_local_path)
162170
return FileResponder(open(legacy_local_path, "rb"))
163171

164172
for provider in self.storage_providers:
165173
res = await provider.fetch(path, file_info) # type: Any
166174
if res:
167175
logger.debug("Streaming %s from %s", path, provider)
168176
return res
177+
if legacy_path:
178+
logger.debug(
179+
"Provider %s did not find %s; checking legacy name", provider, path
180+
)
181+
res = await provider.fetch(legacy_path, file_info)
182+
if res:
183+
logger.debug("Streaming %s from %s", legacy_path, provider)
184+
return res
169185

170186
return None
171187

0 commit comments

Comments
 (0)