This repository has been 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
Fix thumbnailing remote files #2789
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a4c5e4a
Fix thumbnailing remote files
erikjohnston c5b589f
Log when we respond with 404
erikjohnston 9795b9e
Correctly use server_name/file_id when generating/fetching remote thu…
erikjohnston 307f88d
Fix up log lines
erikjohnston 5dfc837
Fix typo
erikjohnston 0a90d9e
Move setting of file_id up to caller
erikjohnston 6368e5c
Change _generate_thumbnails to take media_type
erikjohnston d863f68
Use local vars
erikjohnston d728c47
Add docstring
erikjohnston 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 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 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 |
---|---|---|
|
@@ -185,8 +185,10 @@ def _do_preview(self, url, user, ts): | |
logger.debug("got media_info of '%s'" % media_info) | ||
|
||
if _is_media(media_info['media_type']): | ||
file_id = media_info['filesystem_id'] | ||
dims = yield self.media_repo._generate_thumbnails( | ||
None, media_info['filesystem_id'], media_info, url_cache=True, | ||
None, file_id, file_id, media_info["media_type"], | ||
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. would be nice to factor out a local |
||
url_cache=True, | ||
) | ||
|
||
og = { | ||
|
@@ -231,8 +233,10 @@ def _do_preview(self, url, user, ts): | |
|
||
if _is_media(image_info['media_type']): | ||
# TODO: make sure we don't choke on white-on-transparent images | ||
file_id = image_info['filesystem_id'] | ||
dims = yield self.media_repo._generate_thumbnails( | ||
None, image_info['filesystem_id'], image_info, url_cache=True, | ||
None, file_id, file_id, image_info["media_type"], | ||
url_cache=True, | ||
) | ||
if dims: | ||
og["og:image:width"] = dims['width'] | ||
|
This file contains 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 |
---|---|---|
|
@@ -84,7 +84,11 @@ def _respond_local_thumbnail(self, request, media_id, width, height, | |
method, m_type): | ||
media_info = yield self.store.get_local_media(media_id) | ||
|
||
if not media_info or media_info["quarantined_by"]: | ||
if not media_info: | ||
respond_404(request) | ||
return | ||
if media_info["quarantined_by"]: | ||
logger.info("Media is quarantined") | ||
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. we don't know for sure it is quarantined here |
||
respond_404(request) | ||
return | ||
|
||
|
@@ -111,6 +115,7 @@ def _respond_local_thumbnail(self, request, media_id, width, height, | |
responder = yield self.media_storage.fetch_media(file_info) | ||
yield respond_with_responder(request, responder, t_type, t_length) | ||
else: | ||
logger.info("Couldn't find any generated thumbnails") | ||
respond_404(request) | ||
|
||
@defer.inlineCallbacks | ||
|
@@ -119,7 +124,11 @@ def _select_or_generate_local_thumbnail(self, request, media_id, desired_width, | |
desired_type): | ||
media_info = yield self.store.get_local_media(media_id) | ||
|
||
if not media_info or media_info["quarantined_by"]: | ||
if not media_info: | ||
respond_404(request) | ||
return | ||
if media_info["quarantined_by"]: | ||
logger.info("Media is quarantined") | ||
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. ditto |
||
respond_404(request) | ||
return | ||
|
||
|
@@ -149,7 +158,7 @@ def _select_or_generate_local_thumbnail(self, request, media_id, desired_width, | |
yield respond_with_responder(request, responder, t_type, t_length) | ||
return | ||
|
||
logger.debug("We don't have a local thumbnail of that size. Generating") | ||
logger.debug("We don't have a thumbnail of that size. Generating") | ||
|
||
# Okay, so we generate one. | ||
file_path = yield self.media_repo.generate_local_exact_thumbnail( | ||
|
@@ -159,13 +168,14 @@ def _select_or_generate_local_thumbnail(self, request, media_id, desired_width, | |
if file_path: | ||
yield respond_with_file(request, desired_type, file_path) | ||
else: | ||
logger.warn("Failed to generate thumbnail") | ||
respond_404(request) | ||
|
||
@defer.inlineCallbacks | ||
def _select_or_generate_remote_thumbnail(self, request, server_name, media_id, | ||
desired_width, desired_height, | ||
desired_method, desired_type): | ||
media_info = yield self.media_repo.get_remote_media(server_name, media_id) | ||
media_info = yield self.media_repo.get_remote_media_info(server_name, media_id) | ||
|
||
thumbnail_infos = yield self.store.get_remote_media_thumbnails( | ||
server_name, media_id, | ||
|
@@ -181,7 +191,7 @@ def _select_or_generate_remote_thumbnail(self, request, server_name, media_id, | |
|
||
if t_w and t_h and t_method and t_type: | ||
file_info = FileInfo( | ||
server_name=None, file_id=media_id, | ||
server_name=server_name, file_id=media_info["filesystem_id"], | ||
thumbnail=True, | ||
thumbnail_width=info["thumbnail_width"], | ||
thumbnail_height=info["thumbnail_height"], | ||
|
@@ -197,7 +207,7 @@ def _select_or_generate_remote_thumbnail(self, request, server_name, media_id, | |
yield respond_with_responder(request, responder, t_type, t_length) | ||
return | ||
|
||
logger.debug("We don't have a local thumbnail of that size. Generating") | ||
logger.debug("We don't have a thumbnail of that size. Generating") | ||
|
||
# Okay, so we generate one. | ||
file_path = yield self.media_repo.generate_remote_exact_thumbnail( | ||
|
@@ -208,6 +218,7 @@ def _select_or_generate_remote_thumbnail(self, request, server_name, media_id, | |
if file_path: | ||
yield respond_with_file(request, desired_type, file_path) | ||
else: | ||
logger.warn("Failed to generate thumbnail") | ||
respond_404(request) | ||
|
||
@defer.inlineCallbacks | ||
|
@@ -216,7 +227,7 @@ def _respond_remote_thumbnail(self, request, server_name, media_id, width, | |
# TODO: Don't download the whole remote file | ||
# We should proxy the thumbnail from the remote server instead of | ||
# downloading the remote file and generating our own thumbnails. | ||
yield self.media_repo.get_remote_media(server_name, media_id) | ||
media_info = yield self.media_repo.get_remote_media_info(server_name, media_id) | ||
|
||
thumbnail_infos = yield self.store.get_remote_media_thumbnails( | ||
server_name, media_id, | ||
|
@@ -227,7 +238,7 @@ def _respond_remote_thumbnail(self, request, server_name, media_id, width, | |
width, height, method, m_type, thumbnail_infos | ||
) | ||
file_info = FileInfo( | ||
server_name=None, file_id=media_id, | ||
server_name=server_name, file_id=media_info["filesystem_id"], | ||
thumbnail=True, | ||
thumbnail_width=thumbnail_info["thumbnail_width"], | ||
thumbnail_height=thumbnail_info["thumbnail_height"], | ||
|
@@ -241,6 +252,7 @@ def _respond_remote_thumbnail(self, request, server_name, media_id, width, | |
responder = yield self.media_storage.fetch_media(file_info) | ||
yield respond_with_responder(request, responder, t_type, t_length) | ||
else: | ||
logger.info("Failed to find any generated thumbnails") | ||
respond_404(request) | ||
|
||
def _select_thumbnail(self, desired_width, desired_height, desired_method, | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc, please!