Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mélanie Chauvel
funkwhale
Commits
300e24db
Verified
Commit
300e24db
authored
6 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Ensure we return correct paths when using Apache as a reverse proxy
parent
ad43d160
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/funkwhale_api/music/views.py
+28
-13
28 additions, 13 deletions
api/funkwhale_api/music/views.py
api/tests/music/test_views.py
+25
-0
25 additions, 0 deletions
api/tests/music/test_views.py
deploy/env.prod.sample
+4
-0
4 additions, 0 deletions
deploy/env.prod.sample
with
57 additions
and
13 deletions
api/funkwhale_api/music/views.py
+
28
−
13
View file @
300e24db
...
...
@@ -205,6 +205,25 @@ class TrackViewSet(
return
Response
(
serializer
.
data
)
def
get_file_path
(
audio_file
):
t
=
settings
.
REVERSE_PROXY_TYPE
if
t
==
'
nginx
'
:
# we have to use the internal locations
try
:
path
=
audio_file
.
url
except
AttributeError
:
# a path was given
path
=
'
/music
'
+
audio_file
return
settings
.
PROTECT_FILES_PATH
+
path
if
t
==
'
apache2
'
:
try
:
path
=
audio_file
.
path
except
AttributeError
:
# a path was given
path
=
audio_file
return
path
class
TrackFileViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
queryset
=
(
models
.
TrackFile
.
objects
.
all
().
order_by
(
'
-id
'
))
serializer_class
=
serializers
.
TrackFileSerializer
...
...
@@ -243,24 +262,20 @@ class TrackFileViewSet(viewsets.ReadOnlyModelViewSet):
library_track
=
qs
.
get
(
pk
=
library_track
.
pk
)
library_track
.
download_audio
()
audio_file
=
library_track
.
audio_file
file_path
=
'
{}{}
'
.
format
(
settings
.
PROTECT_FILES_PATH
,
audio_file
.
url
)
file_path
=
get_file_path
(
audio_file
)
mt
=
library_track
.
audio_mimetype
elif
audio_file
:
file_path
=
'
{}{}
'
.
format
(
settings
.
PROTECT_FILES_PATH
,
audio_file
.
url
)
file_path
=
get_file_path
(
audio_file
)
elif
f
.
source
and
f
.
source
.
startswith
(
'
file://
'
):
file_path
=
'
{}{}
'
.
format
(
settings
.
PROTECT_FILES_PATH
+
'
/music
'
,
f
.
serve_from_source_path
)
file_path
=
get_file_path
(
f
.
serve_from_source_path
)
response
=
Response
()
filename
=
f
.
filename
if
settings
.
REVERSE_PROXY_TYPE
==
'
apache2
'
:
response
[
'
X-Sendfile
'
]
=
file_path
elif
settings
.
REVERSE_PROXY_TYPE
==
'
nginx
'
:
response
[
'
X-Accel-Redirect
'
]
=
file_path
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
)
...
...
This diff is collapsed.
Click to expand it.
api/tests/music/test_views.py
+
25
−
0
View file @
300e24db
...
...
@@ -76,6 +76,31 @@ def test_can_serve_track_file_as_remote_library_deny_not_following(
assert
response
.
status_code
==
403
def
test_serve_file_apache
(
factories
,
api_client
,
settings
):
settings
.
PROTECT_AUDIO_FILES
=
False
settings
.
REVERSE_PROXY_TYPE
=
'
apache2
'
tf
=
factories
[
'
music.TrackFile
'
]()
response
=
api_client
.
get
(
tf
.
path
)
assert
response
.
status_code
==
200
assert
response
[
'
X-Sendfile
'
]
==
tf
.
audio_file
.
path
def
test_serve_file_apache_in_place
(
factories
,
api_client
,
settings
):
settings
.
PROTECT_AUDIO_FILES
=
False
settings
.
REVERSE_PROXY_TYPE
=
'
apache2
'
settings
.
MUSIC_DIRECTORY_PATH
=
'
/music
'
settings
.
MUSIC_DIRECTORY_SERVE_PATH
=
'
/host/music
'
track_file
=
factories
[
'
music.TrackFile
'
](
in_place
=
True
,
source
=
'
file:///music/test.ogg
'
)
response
=
api_client
.
get
(
track_file
.
path
)
assert
response
.
status_code
==
200
assert
response
[
'
X-Sendfile
'
]
==
'
/host/music/test.ogg
'
def
test_can_proxy_remote_track
(
factories
,
settings
,
api_client
,
r_mock
):
settings
.
PROTECT_AUDIO_FILES
=
False
...
...
This diff is collapsed.
Click to expand it.
deploy/env.prod.sample
+
4
−
0
View file @
300e24db
...
...
@@ -41,6 +41,10 @@ FUNKWHALE_API_PORT=5000
# your instance
FUNKWHALE_URL=https://yourdomain.funwhale
# Depending on the reverse proxy used in front of your funkwhale instance,
# the API will use different kind of headers to serve audio files
# Allowed values: nginx, apache2
REVERSE_PROXY_TYPE=nginx
# API/Django configuration
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment