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

Commit

Permalink
Fix thumbnailing remote files
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Jan 16, 2018
1 parent 1159abb commit a4c5e4a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions synapse/rest/media/v1/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,34 @@ def get_remote_media(self, request, server_name, media_id, name):
else:
respond_404(request)

@defer.inlineCallbacks
def get_remote_media_info(self, server_name, media_id):
"""Gets the media info associated with the remote file, downloading
if necessary.
Args:
server_name (str): Remote server_name where the media originated.
media_id (str): The media ID of the content (as defined by the
remote server).
Returns:
Deferred[dict]: The media_info of the file
"""
# We linearize here to ensure that we don't try and download remote
# media multiple times concurrently
key = (server_name, media_id)
with (yield self.remote_media_linearizer.queue(key)):
responder, media_info = yield self._get_remote_media_impl(
server_name, media_id,
)

# Ensure we actually use the responder so that it releases resources
if responder:
with responder:
pass

defer.returnValue(media_info)

@defer.inlineCallbacks
def _get_remote_media_impl(self, server_name, media_id):
"""Looks for media in local cache, if not there then attempt to
Expand Down
4 changes: 2 additions & 2 deletions synapse/rest/media/v1/thumbnail_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _select_or_generate_local_thumbnail(self, request, media_id, desired_width,
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,
Expand Down Expand Up @@ -216,7 +216,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)
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,
Expand Down

0 comments on commit a4c5e4a

Please sign in to comment.