If user supplies filename in URL when downloading from media repo, use that name in Content Disposition
This commit is contained in:
parent
9beaedd164
commit
12b83f1a0d
|
@ -42,7 +42,10 @@ def parse_media_id(request):
|
|||
# This allows users to append e.g. /test.png to the URL. Useful for
|
||||
# clients that parse the URL to see content type.
|
||||
server_name, media_id = request.postpath[:2]
|
||||
return (server_name, media_id)
|
||||
if len(request.postpath) > 2 and is_ascii(request.postpath[-1]):
|
||||
return server_name, media_id, request.postpath[-1]
|
||||
else:
|
||||
return server_name, media_id, None
|
||||
except:
|
||||
raise SynapseError(
|
||||
404,
|
||||
|
|
|
@ -32,14 +32,16 @@ class DownloadResource(BaseMediaResource):
|
|||
@request_handler
|
||||
@defer.inlineCallbacks
|
||||
def _async_render_GET(self, request):
|
||||
server_name, media_id = parse_media_id(request)
|
||||
server_name, media_id, name = parse_media_id(request)
|
||||
if server_name == self.server_name:
|
||||
yield self._respond_local_file(request, media_id)
|
||||
yield self._respond_local_file(request, media_id, name)
|
||||
else:
|
||||
yield self._respond_remote_file(request, server_name, media_id)
|
||||
yield self._respond_remote_file(
|
||||
request, server_name, media_id, name
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _respond_local_file(self, request, media_id):
|
||||
def _respond_local_file(self, request, media_id, name):
|
||||
media_info = yield self.store.get_local_media(media_id)
|
||||
if not media_info:
|
||||
self._respond_404(request)
|
||||
|
@ -47,7 +49,7 @@ class DownloadResource(BaseMediaResource):
|
|||
|
||||
media_type = media_info["media_type"]
|
||||
media_length = media_info["media_length"]
|
||||
upload_name = media_info["upload_name"]
|
||||
upload_name = name if name else media_info["upload_name"]
|
||||
file_path = self.filepaths.local_media_filepath(media_id)
|
||||
|
||||
yield self._respond_with_file(
|
||||
|
@ -56,13 +58,13 @@ class DownloadResource(BaseMediaResource):
|
|||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _respond_remote_file(self, request, server_name, media_id):
|
||||
def _respond_remote_file(self, request, server_name, media_id, name):
|
||||
media_info = yield self._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 = media_info["upload_name"]
|
||||
upload_name = name if name else media_info["upload_name"]
|
||||
|
||||
file_path = self.filepaths.remote_media_filepath(
|
||||
server_name, filesystem_id
|
||||
|
|
|
@ -36,7 +36,7 @@ class ThumbnailResource(BaseMediaResource):
|
|||
@request_handler
|
||||
@defer.inlineCallbacks
|
||||
def _async_render_GET(self, request):
|
||||
server_name, media_id = parse_media_id(request)
|
||||
server_name, media_id, _ = parse_media_id(request)
|
||||
width = parse_integer(request, "width")
|
||||
height = parse_integer(request, "height")
|
||||
method = parse_string(request, "method", "scale")
|
||||
|
|
Loading…
Reference in New Issue