diff --git a/docs/developer/api/api-reference.md b/docs/developer/api/api-reference.md index e9ec59e..134b423 100644 --- a/docs/developer/api/api-reference.md +++ b/docs/developer/api/api-reference.md @@ -89,7 +89,7 @@ See [Media Item Operations](media-items/) - GET /api/media-items/:id - Get media item details - POST /api/media-items/bulk-delete - Bulk delete media items - POST /api/media-items/bulk-update - Bulk update media items (tags/contributors with normalization) -- GET /api/media-items/:uuid/download - Download media item file +- GET /uploads/library-{library_id}/{file_path} - Download book file / cover (JWT; see [Download Media Item](media-items/download_media_item.md)) - POST /api/media-items/:id/rating - Create rating - GET /api/media-items/:id/rating - Get rating - PUT /api/media-items/:id/rating - Update rating diff --git a/docs/developer/api/media-items/download_media_item.md b/docs/developer/api/media-items/download_media_item.md index f3b7347..1f1e8d7 100644 --- a/docs/developer/api/media-items/download_media_item.md +++ b/docs/developer/api/media-items/download_media_item.md @@ -2,15 +2,19 @@ Download a media item file (EPUB, PDF, etc.) from the Bookhoard server. -**Endpoint**: `GET /api/media-items/:uuid/download` -**Auth**: None (public endpoint for Kobo devices) -**Content-Type**: Binary file download +Book files are served by the authenticated file route, the same one the web reader uses. Build the URL from the media item's `library_id` and relative `file_path` (both returned by the media item list/get endpoints): + +**Endpoint**: `GET /uploads/library-{library_id}/{file_path}` +**Auth**: Required (JWT - Bearer header or session cookie) + +The `file_path` segments are URL-escaped individually; slashes are preserved. `cover_image_path` uses the same route. ## Path Parameters -| Parameter | Type | Required | Description | -| --------- | ------ | -------- | --------------- | -| uuid | string | Yes | Media item UUID | +| Parameter | Type | Required | Description | +| ----------- | ------ | -------- | ------------------------------------ | +| library_id | string | Yes | Library UUID (the item's library) | +| file_path | string | Yes | The item's relative `file_path` | ## Response @@ -18,25 +22,27 @@ Download a media item file (EPUB, PDF, etc.) from the Bookhoard server. **Response Headers**: -- `Content-Type`: `application/epub+zip`, `application/pdf`, or appropriate MIME type -- `Content-Disposition`: `attachment; filename="filename.epub"` +- `Content-Type`: MIME type by file extension (`application/epub+zip`, `application/pdf`, …; `application/octet-stream` fallback) +- `Cache-Control`: `public, max-age=86400` ## Error Responses -| Code | Description | -| ---- | --------------------------------- | -| 404 | Media item not found | -| 500 | Server error during file download | +| Code | Description | +| ---- | --------------------------- | +| 400 | Invalid library ID or path | +| 401 | Missing/invalid token | +| 404 | File not found on disk | ## Example ```bash -curl -O http://localhost:8765/api/media-items/550e8400-e29b-41d4-a716-446655440000/download +curl -O -H "Authorization: Bearer $TOKEN" \ + "http://localhost:8765/uploads/library/550e8400-.../books/1984.epub" ``` +(URL shape: `/uploads/library-{uuid}/{escaped-relative-path}`.) + ## Notes -- **Public endpoint**: No authentication required for Kobo device downloads -- **File format**: Returns the original file format (EPUB, PDF, etc.) -- **Kobo integration**: Designed for direct downloads from Kobo e-readers -- **Cover images**: Use `/api/media-items/:uuid/cover` for cover images +- **Do not rely on `GET /api/media-items/:id/download`** — it appears in older docs but is **not registered**; `MediaHandler.DownloadBook` exists as dead code. Use the file route above. +- OPDS-capable devices may alternatively use the device-authenticated `GET /opds/devices/{deviceId}/download/{bookId}`, which supports on-the-fly format conversion (epub, kepub, pdf, cbz).