From 4a9673b6193eb69c2449a2427bda3d40b6ff96ae Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Fri, 27 Feb 2026 10:20:05 -0500 Subject: [PATCH] docs: update cover image serving plan with corrections --- cover_image_serving_plan.md | 57 ++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/cover_image_serving_plan.md b/cover_image_serving_plan.md index 7079d27..4bad8b8 100644 --- a/cover_image_serving_plan.md +++ b/cover_image_serving_plan.md @@ -299,12 +299,12 @@ func (mh *MediaHandler) ServeFile(c echo.Context) error { ### File: `internal/router/media.go` -**Location**: After existing media routes +**Location**: After existing media routes (NOT in the protected group) ```go -// File serving - authenticated +// File serving - authenticated (registered on Echo to avoid /api prefix) // Note: Must be registered LAST as it's a wildcard route -protected.GET("/uploads/library-:id/*", cfg.MediaHandler.ServeFile) +e.GET("/uploads/library-:id/*", createJWTMiddleware(cfg), cfg.MediaHandler.ServeFile) ``` **Important**: This route must be registered LAST because `/*` is a wildcard that matches everything. @@ -439,6 +439,42 @@ func (mh *MediaHandler) resolveMediaURL(libraryID pgtype.UUID, relativePath stri --- +### Step 1b: Add libraryService to CollectionHandler + +**File**: `internal/handlers/collections.go` + +Add `libraryService` field to CollectionHandler struct (near line 10): + +```go +type CollectionHandler struct { + db *database.Queries + collectionService *services.CollectionService + libraryService *services.LibraryService // ADD THIS + connManager *wsync.ConnectionManager +} +``` + +Update constructor to accept and set libraryService: + +```go +func NewCollectionHandler(db *database.Queries, libraryService *services.LibraryService, connManager *wsync.ConnectionManager) *CollectionHandler { + return &CollectionHandler{ + db: db, + collectionService: services.NewCollectionService(db), + libraryService: libraryService, // ADD THIS + connManager: connManager, + } +} +``` + +**Update router** where CollectionHandler is instantiated (likely in router/collections.go or similar): + +```go +cfg.CollectionHandler, err = handlers.NewCollectionHandler(cfg.Queries, cfg.LibraryService, cfg.ConnManager) +``` + +--- + ### Step 2: Update collections.go - GetCollectionBooks (line ~199) **File**: `internal/handlers/collections.go` @@ -618,11 +654,11 @@ func (h *CollectionHandler) resolveFileURL(libraryID pgtype.UUID, filePath pgtyp **File**: `internal/handlers/progress.go` -First, add helper methods to ProgressHandler struct (find struct definition and add after it): +First, add helper methods to Handler struct (defined in `scanner.go`, used by progress.go): ```go // resolveCoverURL resolves a relative cover path to a full URL -func (h *ProgressHandler) resolveCoverURL(libraryID pgtype.UUID, coverPath pgtype.Text) string { +func (h *Handler) resolveCoverURL(libraryID pgtype.UUID, coverPath pgtype.Text) string { if !coverPath.Valid || coverPath.String == "" { return "" } @@ -747,8 +783,8 @@ The backend now returns full URLs like `/uploads/library-{id}/path/to/cover.jpg` | File | Changes | |------|---------| | `internal/handlers/media.go` | Add `ResolveCoverURL()`, `ResolveFileURL()`, `resolveMediaURL()` helpers | -| `internal/handlers/collections.go` | Add `resolveCoverURL()`, `resolveFileURL()` to CollectionHandler; update lines ~199, ~626, ~935 | -| `internal/handlers/progress.go` | Add `resolveCoverURL()` to ProgressHandler; update lines ~288, ~359 | +| `internal/handlers/collections.go` | Add `libraryService` to struct and constructor; add `resolveCoverURL()`, `resolveFileURL()` helpers; update lines ~199, ~626, ~935 | +| `internal/handlers/progress.go` | Add `resolveCoverURL()` to Handler (in scanner.go); update lines ~288, ~359 | | `internal/handlers/media.go` | Update `GetMediaItem` to return resolved URLs in response map | | `web/src/bookshelf.ts` | Remove `/covers/` prefix from cover image URL | @@ -1041,10 +1077,11 @@ Update existing documentation to note: | 3 | `internal/handlers/media.go` | Add `getFullFilePath()` helper that calls service | | 4 | `internal/handlers/media.go` | Modify `DownloadBook` to use `getFullFilePath()` | | 5 | `internal/handlers/media.go` | Add `ServeFile()` handler for authenticated static-style routes | -| 5 | `internal/router/media.go` | Add route `GET /uploads/library-:id/*` (register LAST) | +| 5 | `internal/router/media.go` | Add route `GET /uploads/library-:id/*` on Echo (not protected group) | | 6 | `internal/handlers/opds.go` | Add `libraryService` to struct; update `GetCoverImage` to use service | -| 7 | `internal/handlers/collections.go` | Resolve cover paths to URLs in API responses | -| 7 | `internal/handlers/progress.go` | Resolve cover paths to URLs in API responses | +| 7 | `internal/handlers/collections.go` | Add `libraryService` to struct/constructor; resolve cover paths to URLs in API responses | +| 7 | `internal/router/*.go` | Update CollectionHandler instantiation to pass LibraryService | +| 7 | `internal/handlers/scanner.go` (Handler struct, used by progress.go) | Resolve cover paths to URLs in API responses | | 7 | `internal/handlers/media.go` | Resolve file paths to URLs in API responses | | 7 | `web/src/bookshelf.ts` | Remove `/covers/` prefix (use resolved URL directly) | | 8 | Runtime resolution | Handles both absolute (old) and relative (new) paths |