diff --git a/core/files/media_v2.py b/core/files/media_v2.py index 39bca8a..2e8661d 100644 --- a/core/files/media_v2.py +++ b/core/files/media_v2.py @@ -12,10 +12,10 @@ from files.models import File @swagger_auto_schema(method='GET', auto_schema=None) @api_view(['GET']) -def media_urls(request, hash_path): +def media_urls(request, hash): try: - file = File.objects.get(file=hash_path) - + file = File.objects.get(hash=hash) + hash_path = file.file return HttpResponse(status=status.HTTP_200_OK, content_type=file.mime_type, headers={ @@ -29,16 +29,17 @@ def media_urls(request, hash_path): @swagger_auto_schema(method='GET', auto_schema=None) @api_view(['GET']) -def thumbnail_urls(request, size, hash_path): +def thumbnail_urls(request, size, hash): if size not in [32, 64, 256]: return Response(status=status.HTTP_404_NOT_FOUND) try: - file = File.objects.get(file=hash_path) + file = File.objects.get(hash=hash) + hash_path = file.file if not os.path.exists(MEDIA_ROOT + f'/thumbnails/{size}/{hash_path}'): from PIL import Image - iamge = Image.open(file.file) - iamge.thumbnail((size, size)) - iamge.save(MEDIA_ROOT + f'/media/thumbnails/{size}/{hash_path}', quality=90) + image = Image.open(file.file) + image.thumbnail((size, size)) + image.save(MEDIA_ROOT + f'/media/thumbnails/{size}/{hash_path}', quality=90) return HttpResponse(status=status.HTTP_200_OK, content_type=file.mime_type, @@ -52,6 +53,6 @@ def thumbnail_urls(request, size, hash_path): urlpatterns = [ - path('//', thumbnail_urls), - path('/', media_urls), + path('//', thumbnail_urls), + path('/', media_urls), ] diff --git a/web/src/components/Lightbox.vue b/web/src/components/Lightbox.vue index 97c0c46..b1933bb 100644 --- a/web/src/components/Lightbox.vue +++ b/web/src/components/Lightbox.vue @@ -3,7 +3,7 @@