Documentation
¶
Overview ¶
Package covers centralizes cover-file selection and serving so that the books, series, ereader, and OPDS handlers don't drift independently.
Index ¶
Constants ¶
const ( CacheControlImmutable = "private, max-age=31536000, immutable" CacheControlNoCache = "private, no-cache" )
Variables ¶
This section is empty.
Functions ¶
func CacheKey ¶ added in v0.0.46
CacheKey returns a stable cache key for the cover that would be served for the given files and aspect ratio. The key only changes when the selected cover file changes (different file selected, or the file's UpdatedAt bumps after a cover upload/regeneration). Returns "" when no cover exists.
func SelectFile ¶
SelectFile picks the file whose cover should represent a book based on the library's preferred cover aspect ratio. It always falls back across types when the preferred kind has no covers — a book-only library still gets a cover for an audiobook-only book, and vice versa. Supplements are excluded from selection regardless of cover state — they don't represent the book.
func ServeBookCover ¶
func ServeBookCover(c echo.Context, files []*models.File, coverAspectRatio string, cacheControl string) error
ServeBookCover selects the cover file from `files` using the library's preferred aspect ratio and serves it. Callers must perform any auth and library-access checks before calling. Returns errcodes.NotFound when no suitable cover exists or the cover image is missing on disk.
The cover is resolved via the file's parent directory rather than the book's filepath because book.Filepath can be a synthetic organized-folder path that never exists on disk for root-level books.
cacheControl sets the Cache-Control header. API callers should pass CacheControlImmutable (the frontend uses ?v=cover_cache_key to bust cache); external callers (OPDS, eReader, Kobo) should pass CacheControlNoCache.
Conditional GET uses an ETag of `"<file_id>-<mtime_unix>"` and intentionally omits Last-Modified. SelectFile's choice depends on the library's CoverAspectRatio and which files belong to the book, so the served file's identity can change without any change to the new cover's mtime — flipping CoverAspectRatio on a hybrid book (EPUB + M4B) swaps which file's cover is served, and the new cover may have an older mtime than the previously-served one. Mtime-only revalidation would return stale 304s in that case; baking the file ID into the validator ensures it bumps whenever selection changes.
Types ¶
This section is empty.