feat: pdf reader

This commit is contained in:
2026-06-03 22:46:38 -05:00
parent d9c66e68a6
commit f091386974
29 changed files with 29469 additions and 2593 deletions
+9 -4
View File
@@ -168,18 +168,23 @@ class EBookViewSet(viewsets.ModelViewSet):
@action(detail=True, methods=["get"])
def file(self, request: Request, pk: int | None = None) -> FileResponse | Response:
"""Stream the EPUB file for authenticated in-browser reading."""
"""Stream the ebook file for authenticated in-browser reading."""
ebook = self.get_object()
if ebook.format != "epub":
content_types = {
"epub": "application/epub+zip",
"pdf": "application/pdf",
}
content_type = content_types.get(ebook.format)
if not content_type:
return Response(
{"error": "Reader supports EPUB only."},
{"error": "Unsupported format for in-browser reading."},
status=status.HTTP_400_BAD_REQUEST,
)
if not ebook.file:
return Response({"error": "No file found for this e-book."}, status=status.HTTP_400_BAD_REQUEST)
return FileResponse(
ebook.file.open("rb"),
content_type="application/epub+zip",
content_type=content_type,
filename=ebook.filename(),
)