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 generation
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Shpikin <rkfg@rkfg.me>
  • Loading branch information
rkfg committed Apr 11, 2021
1 parent 0b31121 commit 796a91d
Show file tree
Hide file tree
Showing 3 changed files with 6 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.
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
4 changes: 4 additions & 0 deletions synapse/rest/media/v1/preview_url_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ async def _download_url(self, url: str, user: str) -> Dict[str, Any]:

if b"Content-Type" in headers:
media_type = headers[b"Content-Type"][0].decode("ascii")
if media_type.startswith("image/"):
scpos = media_type.find(";")
if scpos > 0:
media_type = media_type[:scpos]
else:
media_type = "application/octet-stream"

Expand Down

0 comments on commit 796a91d

Please sign in to comment.