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.
This commit is contained in:
Richard van der Hoff 2020-10-02 12:29:29 +01:00 committed by GitHub
parent 695240d34a
commit 73d93039ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 20 deletions

1
changelog.d/8438.bugfix Normal file
View File

@ -0,0 +1 @@
Fix a regression in v1.21.0rc1 which broke thumbnails of remote media.

View File

@ -141,31 +141,34 @@ class MediaStorage:
Returns: Returns:
Returns a Responder if the file was found, otherwise None. Returns a Responder if the file was found, otherwise None.
""" """
paths = [self._file_info_to_path(file_info)]
path = self._file_info_to_path(file_info) # fallback for remote thumbnails with no method in the filename
local_path = os.path.join(self.local_media_directory, path)
if os.path.exists(local_path):
return FileResponder(open(local_path, "rb"))
# Fallback for paths without method names
# Should be removed in the future
if file_info.thumbnail and file_info.server_name: if file_info.thumbnail and file_info.server_name:
legacy_path = self.filepaths.remote_media_thumbnail_rel_legacy( paths.append(
server_name=file_info.server_name, self.filepaths.remote_media_thumbnail_rel_legacy(
file_id=file_info.file_id, server_name=file_info.server_name,
width=file_info.thumbnail_width, file_id=file_info.file_id,
height=file_info.thumbnail_height, width=file_info.thumbnail_width,
content_type=file_info.thumbnail_type, height=file_info.thumbnail_height,
content_type=file_info.thumbnail_type,
)
) )
legacy_local_path = os.path.join(self.local_media_directory, legacy_path)
if os.path.exists(legacy_local_path): for path in paths:
return FileResponder(open(legacy_local_path, "rb")) local_path = os.path.join(self.local_media_directory, path)
if os.path.exists(local_path):
logger.debug("responding with local file %s", local_path)
return FileResponder(open(local_path, "rb"))
logger.debug("local file %s did not exist", local_path)
for provider in self.storage_providers: for provider in self.storage_providers:
res = await provider.fetch(path, file_info) # type: Any for path in paths:
if res: res = await provider.fetch(path, file_info) # type: Any
logger.debug("Streaming %s from %s", path, provider) if res:
return res logger.debug("Streaming %s from %s", path, provider)
return res
logger.debug("%s not found on %s", path, provider)
return None return None