add item images

This commit is contained in:
j3d1 2024-08-31 02:50:08 +02:00
parent 0af1f40b07
commit 448c166507
18 changed files with 826 additions and 15 deletions

View file

@ -7,6 +7,7 @@ from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from authentication.signature_auth import SignatureAuthentication
from backend import settings
from files.models import File
@ -19,12 +20,21 @@ def media_urls(request, hash_path):
file = File.objects.filter(connected_items__owner__in=request.user.friends_or_self()).distinct().get(
file=hash_path)
return HttpResponse(status=status.HTTP_200_OK,
content_type=file.mime_type,
headers={
'X-Accel-Redirect': f'/redirect_media/{hash_path}',
'Access-Control-Allow-Origin': '*',
}) # TODO Expires and Cache-Control
if settings.SERVE_X_ACCEL_REDIRECT:
return HttpResponse(status=status.HTTP_200_OK,
content_type=file.mime_type,
headers={
'X-Accel-Redirect': f'/redirect_media/{hash_path}',
'Access-Control-Allow-Origin': '*',
}) # TODO Expires and Cache-Control
else:
return HttpResponse(status=status.HTTP_200_OK,
content_type=file.mime_type,
headers={
'Access-Control-Allow-Origin': '*',
},
content=open(file.file.path, 'rb').read())
except File.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)