Use NGINX X-Accel-Redirect to protect media

This commit is contained in:
Alexandre Iooss 2021-10-21 21:06:51 +02:00
parent 29e9dba141
commit eb03db2dff
3 changed files with 22 additions and 4 deletions

View file

@ -2,10 +2,20 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import ListView
from django.views.generic import ListView, View
from django.http import HttpResponse
from photologue.models import Gallery
class MediaAccess(LoginRequiredMixin, View):
def get(self, request, path):
response = HttpResponse()
# Content-type will be detected by nginx
del response['Content-Type']
response['X-Accel-Redirect'] = '/protected/media/' + path
return response
class IndexView(LoginRequiredMixin, ListView):
queryset = Gallery.objects.on_site().is_public()
paginate_by = 4