Verified Commit bb5e5460 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Fix #848: Fixed invalid file extension for transcoded tracks

parent ac11b64f
......@@ -870,7 +870,14 @@ class UploadVersion(models.Model):
@property
def filename(self):
return self.upload.filename
try:
return (
self.upload.track.full_name
+ "."
+ utils.MIMETYPE_TO_EXTENSION[self.mimetype]
)
except KeyError:
return self.upload.filename
@property
def audio_file_path(self):
......
......@@ -285,6 +285,11 @@ def should_transcode(upload, format, max_bitrate=None):
return format_need_transcoding or bitrate_need_transcoding
def get_content_disposition(filename):
filename = "filename*=UTF-8''{}".format(urllib.parse.quote(filename))
return "attachment; {}".format(filename)
def handle_serve(upload, user, format=None, max_bitrate=None, proxy_media=True):
f = upload
# we update the accessed_date
......@@ -342,8 +347,7 @@ def handle_serve(upload, user, format=None, max_bitrate=None, proxy_media=True):
mapping = {"nginx": "X-Accel-Redirect", "apache2": "X-Sendfile"}
file_header = mapping[settings.REVERSE_PROXY_TYPE]
response[file_header] = file_path
filename = "filename*=UTF-8''{}".format(urllib.parse.quote(filename))
response["Content-Disposition"] = "attachment; {}".format(filename)
response["Content-Disposition"] = get_content_disposition(filename)
if mt:
response["Content-Type"] = mt
......
import io
import magic
import os
import urllib.parse
import pytest
from django.urls import reverse
......@@ -412,7 +413,7 @@ def test_handle_serve_create_mp3_version(factories, now):
user = factories["users.User"]()
upload = factories["music.Upload"](bitrate=42)
response = views.handle_serve(upload, user, format="mp3")
expected_filename = upload.track.full_name + ".mp3"
version = upload.versions.latest("id")
assert version.mimetype == "audio/mpeg"
......@@ -421,7 +422,9 @@ def test_handle_serve_create_mp3_version(factories, now):
assert version.audio_file_path.endswith(".mp3")
assert version.size == version.audio_file.size
assert magic.from_buffer(version.audio_file.read(), mime=True) == "audio/mpeg"
assert response["Content-Disposition"] == "attachment; filename*=UTF-8''{}".format(
urllib.parse.quote(expected_filename)
)
assert response.status_code == 200
......
Fixed invalid file extension for transcoded tracks (#848)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment