This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Provide more info why we don't have any thumbnails to serve #13038
Merged
MadLittleMods
merged 17 commits into
develop
from
madlittlemods/13016-better-thumbnail-error-response
Jul 15, 2022
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4dc6e1a
Provide more info when we don't have any thumbnails to serve
MadLittleMods 4bf53bc
Add changelog
MadLittleMods 9348242
Fix lints
MadLittleMods a3362a5
Merge branch 'develop' into madlittlemods/13016-better-thumbnail-erro…
MadLittleMods 9381001
Merge branch 'develop' into madlittlemods/13016-better-thumbnail-erro…
MadLittleMods 74aaf9c
Merge branch 'develop' into madlittlemods/13016-better-thumbnail-erro…
MadLittleMods 9a6b85b
Clarify why gif -> png
MadLittleMods f881c39
Document what the map represents
MadLittleMods ad5aa80
Just assert the environment we expect this function to be run in
MadLittleMods ac9285f
Add docstrings
MadLittleMods 67c13ab
Simpler dynamic thumbnail disabled error message
MadLittleMods ff73222
Merge branch 'develop' into madlittlemods/13016-better-thumbnail-erro…
MadLittleMods d3308f8
Fix copy-paste error
MadLittleMods 990450f
Inline requirements
MadLittleMods 6a42925
More clear comment
MadLittleMods 52ee48f
Update error to be a little bit more generic and friendly
MadLittleMods 06405db
Updated description of why no thumbnail
MadLittleMods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Provide more info why we don't have any thumbnails to serve. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,11 @@ | |
import logging | ||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple | ||
|
||
from synapse.api.errors import SynapseError | ||
from synapse.api.errors import Codes, SynapseError, cs_error | ||
from synapse.config.repository import THUMBNAIL_SUPPORTED_MEDIA_FORMAT_MAP | ||
from synapse.http.server import ( | ||
DirectServeJsonResource, | ||
respond_with_json, | ||
set_corp_headers, | ||
set_cors_headers, | ||
) | ||
|
@@ -309,6 +311,19 @@ async def _select_and_respond_with_thumbnail( | |
url_cache: True if this is from a URL cache. | ||
server_name: The server name, if this is a remote thumbnail. | ||
""" | ||
logger.debug( | ||
"_select_and_respond_with_thumbnail: media_id=%s desired=%sx%s (%s) thumbnail_infos=%s", | ||
media_id, | ||
desired_width, | ||
desired_height, | ||
desired_method, | ||
thumbnail_infos, | ||
) | ||
|
||
# If `dynamic_thumbnails` is enabled, we expect Synapse to go down a | ||
# different code path to handle it. | ||
assert not self.dynamic_thumbnails | ||
|
||
if thumbnail_infos: | ||
file_info = self._select_thumbnail( | ||
desired_width, | ||
|
@@ -384,8 +399,29 @@ async def _select_and_respond_with_thumbnail( | |
file_info.thumbnail.length, | ||
) | ||
else: | ||
# This might be because: | ||
# 1. We can't create thumbnails for the given media (corrupted or | ||
# unsupported file type), or | ||
# 2. The thumbnailing process never ran or errored out initially | ||
# when the media was first uploaded (these bugs should be | ||
# reported and fixed). | ||
# Note that we don't attempt to generate a thumbnail now because | ||
# `dynamic_thumbnails` is disabled. | ||
logger.info("Failed to find any generated thumbnails") | ||
respond_404(request) | ||
|
||
respond_with_json( | ||
request, | ||
400, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still think this should be a 404 and M_NOT_FOUND. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The spec says no right now, matrix-org/matrix-spec#1122 It does make sense to me in some cases:
In the cases I ran into, |
||
cs_error( | ||
"Cannot find any thumbnails for the requested media (%r). This might mean the media is not a supported_media_format=(%s) or that thumbnailing failed for some other reason. (Dynamic thumbnails are disabled on this server.)" | ||
% ( | ||
request.postpath, | ||
", ".join(THUMBNAIL_SUPPORTED_MEDIA_FORMAT_MAP.keys()), | ||
), | ||
code=Codes.UNKNOWN, | ||
), | ||
send_cors=True, | ||
) | ||
|
||
def _select_thumbnail( | ||
self, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.