webp thumbnail support with png fallback

This commit is contained in:
Michael Shamoon
2022-06-10 01:39:20 -07:00
parent e4a26164de
commit 58f2c6a5fc
3 changed files with 15 additions and 5 deletions

View File

@@ -362,7 +362,12 @@ class DocumentViewSet(
handle = doc.thumbnail_file
# TODO: Send ETag information and use that to send new thumbnails
# if available
return HttpResponse(handle, content_type="image/png")
content_type = (
"image/webp"
if os.path.splitext(doc.thumbnail_path)[1] == ".webp"
else "image/png"
)
return HttpResponse(handle, content_type=content_type)
except (FileNotFoundError, Document.DoesNotExist):
raise Http404()