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

More robust handling of the Content-Type header for thumbnail generation #9788

Merged
merged 3 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -71,6 +71,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 @@ -468,6 +468,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