summary refs log tree commit diff
path: root/synapse/rest/media/v1/download_resource.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-01-08 17:52:06 +0000
committerErik Johnston <erik@matrix.org>2018-01-09 16:15:07 +0000
commit9e20840e0296eb9b814bb0e7130342c5c9a19e3d (patch)
treedeb960eba6942bbedd1ee8d630079a7a8e68f697 /synapse/rest/media/v1/download_resource.py
parentUse MediaStorage for local files (diff)
downloadsynapse-9e20840e0296eb9b814bb0e7130342c5c9a19e3d.tar.xz
Use MediaStorage for remote media
Diffstat (limited to 'synapse/rest/media/v1/download_resource.py')
-rw-r--r--synapse/rest/media/v1/download_resource.py43
1 files changed, 11 insertions, 32 deletions
diff --git a/synapse/rest/media/v1/download_resource.py b/synapse/rest/media/v1/download_resource.py
index 2a5afa9ff4..5dc92972cf 100644
--- a/synapse/rest/media/v1/download_resource.py
+++ b/synapse/rest/media/v1/download_resource.py
@@ -14,7 +14,7 @@
 # limitations under the License.
 import synapse.http.servlet
 
-from ._base import parse_media_id, respond_with_file, respond_404
+from ._base import parse_media_id, respond_404
 from twisted.web.resource import Resource
 from synapse.http.server import request_handler, set_cors_headers
 
@@ -59,35 +59,14 @@ class DownloadResource(Resource):
         if server_name == self.server_name:
             yield self.media_repo.get_local_media(request, media_id, name)
         else:
-            yield self._respond_remote_file(
-                request, server_name, media_id, name
-            )
+            allow_remote = synapse.http.servlet.parse_boolean(
+                request, "allow_remote", default=True)
+            if not allow_remote:
+                logger.info(
+                    "Rejecting request for remote media %s/%s due to allow_remote",
+                    server_name, media_id,
+                )
+                respond_404(request)
+                return
 
-    @defer.inlineCallbacks
-    def _respond_remote_file(self, request, server_name, media_id, name):
-        # don't forward requests for remote media if allow_remote is false
-        allow_remote = synapse.http.servlet.parse_boolean(
-            request, "allow_remote", default=True)
-        if not allow_remote:
-            logger.info(
-                "Rejecting request for remote media %s/%s due to allow_remote",
-                server_name, media_id,
-            )
-            respond_404(request)
-            return
-
-        media_info = yield self.media_repo.get_remote_media(server_name, media_id)
-
-        media_type = media_info["media_type"]
-        media_length = media_info["media_length"]
-        filesystem_id = media_info["filesystem_id"]
-        upload_name = name if name else media_info["upload_name"]
-
-        file_path = self.filepaths.remote_media_filepath(
-            server_name, filesystem_id
-        )
-
-        yield respond_with_file(
-            request, media_type, file_path, media_length,
-            upload_name=upload_name,
-        )
+            yield self.media_repo.get_remote_media(request, server_name, media_id, name)