Commit 5e1d0c2f authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Merge branch '924-in-place-percent' into 'develop'

Fix #924: in-place imported files not playing under nginx when filename contains ? or %

Closes #924

See merge request !910
parents db2e006b f0bea39d
import datetime
import logging
import urllib
import urllib.parse
from django.conf import settings
from django.db import transaction
......@@ -321,6 +321,8 @@ def get_file_path(audio_file):
path = "/music" + audio_file.replace(prefix, "", 1)
if path.startswith("http://") or path.startswith("https://"):
return (settings.PROTECT_FILES_PATH + "/media/" + path).encode("utf-8")
# needed to serve files with % or ? chars
path = urllib.parse.quote(path)
return (settings.PROTECT_FILES_PATH + path).encode("utf-8")
if t == "apache2":
try:
......
......@@ -226,13 +226,34 @@ def test_serve_file_in_place(
assert response[headers[proxy]] == expected
def test_serve_file_in_place_nginx_encode_url(
factories, api_client, preferences, settings
):
preferences["common__api_authentication_required"] = False
settings.PROTECT_FILE_PATH = "/_protected/music"
settings.REVERSE_PROXY_TYPE = "nginx"
settings.MUSIC_DIRECTORY_PATH = "/app/music"
settings.MUSIC_DIRECTORY_SERVE_PATH = "/app/music"
upload = factories["music.Upload"](
in_place=True,
import_status="finished",
source="file:///app/music/hello/world%?.mp3",
library__privacy_level="everyone",
)
response = api_client.get(upload.track.listen_url)
expected = "/_protected/music/hello/world%25%3F.mp3"
assert response.status_code == 200
assert response["X-Accel-Redirect"] == expected
@pytest.mark.parametrize(
"proxy,serve_path,expected",
[
("apache2", "/host/music", "/host/music/hello/worldéà.mp3"),
("apache2", "/app/music", "/app/music/hello/worldéà.mp3"),
("nginx", "/host/music", "/_protected/music/hello/worldéà.mp3"),
("nginx", "/app/music", "/_protected/music/hello/worldéà.mp3"),
("nginx", "/host/music", "/_protected/music/hello/world%C3%A9%C3%A0.mp3"),
("nginx", "/app/music", "/_protected/music/hello/world%C3%A9%C3%A0.mp3"),
],
)
def test_serve_file_in_place_utf8(
......
Fixed in-place imported files not playing under nginx when filename contains ? or % (#924)
Markdown is supported
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