Now return media files with absolute URL

merge-requests/154/head
Eliot Berriot 2017-07-11 09:14:54 +02:00
rodzic e8eaf6db94
commit da4c76ace8
5 zmienionych plików z 17 dodań i 3 usunięć

Wyświetl plik

@ -313,7 +313,8 @@ REST_FRAMEWORK = {
} }
ATOMIC_REQUESTS = False ATOMIC_REQUESTS = False
USE_X_FORWARDED_HOST = True
USE_X_FORWARDED_PORT = True
# Wether we should check user permission before serving audio files (meaning # Wether we should check user permission before serving audio files (meaning
# return an obfuscated url) # return an obfuscated url)
# This require a special configuration on the reverse proxy side # This require a special configuration on the reverse proxy side

Wyświetl plik

@ -31,11 +31,20 @@ class ImportBatchSerializer(serializers.ModelSerializer):
model = models.ImportBatch model = models.ImportBatch
fields = ('id', 'jobs', 'status', 'creation_date') fields = ('id', 'jobs', 'status', 'creation_date')
class TrackFileSerializer(serializers.ModelSerializer): class TrackFileSerializer(serializers.ModelSerializer):
path = serializers.SerializerMethodField()
class Meta: class Meta:
model = models.TrackFile model = models.TrackFile
fields = ('id', 'path', 'duration', 'source', 'filename') fields = ('id', 'path', 'duration', 'source', 'filename')
def get_path(self, o):
request = self.context.get('request')
url = o.path
if request:
url = request.build_absolute_uri(url)
return url
class SimpleAlbumSerializer(serializers.ModelSerializer): class SimpleAlbumSerializer(serializers.ModelSerializer):

Wyświetl plik

@ -41,6 +41,8 @@ server {
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Port $server_port;
proxy_redirect off; proxy_redirect off;
proxy_pass http://funkwhale-api/api/; proxy_pass http://funkwhale-api/api/;
} }

Wyświetl plik

@ -63,4 +63,4 @@ services:
- ./docker/nginx/conf.dev:/etc/nginx/nginx.conf - ./docker/nginx/conf.dev:/etc/nginx/nginx.conf
- ./api/funkwhale_api/media:/protected/media - ./api/funkwhale_api/media:/protected/media
ports: ports:
- "0.0.0.0:6001:80" - "0.0.0.0:6001:6001"

Wyświetl plik

@ -28,7 +28,7 @@ http {
#gzip on; #gzip on;
server { server {
listen 80; listen 6001;
charset utf-8; charset utf-8;
location /_protected/media { location /_protected/media {
@ -40,6 +40,8 @@ http {
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Port $server_port;
proxy_redirect off; proxy_redirect off;
proxy_pass http://api:12081/; proxy_pass http://api:12081/;
} }