Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
More robust handling of the Content-Type header for thumbnail generat…
Browse files Browse the repository at this point in the history
…ion (#9788)

Signed-off-by: Sergey Shpikin <rkfg@rkfg.me>
  • Loading branch information
rkfg authored Apr 14, 2021
1 parent 4b965c8 commit c9a2b5d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/9788.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix thumbnail generation for some sites with non-standard content types. Contributed by @rkfg.
1 change: 1 addition & 0 deletions synapse/config/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def parse_thumbnail_requirements(thumbnail_sizes):
jpeg_thumbnail = ThumbnailRequirement(width, height, method, "image/jpeg")
png_thumbnail = ThumbnailRequirement(width, height, method, "image/png")
requirements.setdefault("image/jpeg", []).append(jpeg_thumbnail)
requirements.setdefault("image/jpg", []).append(jpeg_thumbnail)
requirements.setdefault("image/webp", []).append(jpeg_thumbnail)
requirements.setdefault("image/gif", []).append(png_thumbnail)
requirements.setdefault("image/png", []).append(png_thumbnail)
Expand Down
3 changes: 3 additions & 0 deletions synapse/rest/media/v1/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ async def _download_remote_file(
return media_info

def _get_thumbnail_requirements(self, media_type):
scpos = media_type.find(";")
if scpos > 0:
media_type = media_type[:scpos]
return self.thumbnail_requirements.get(media_type, ())

def _generate_thumbnail(
Expand Down

0 comments on commit c9a2b5d

Please sign in to comment.