From 123ab0c9669e76a0562a4a0a2866539257a5b36e Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Fri, 27 Feb 2026 10:44:12 -0500 Subject: [PATCH] docs: update plan with accurate line numbers --- cover_image_serving_plan.md | 111 +++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 41 deletions(-) diff --git a/cover_image_serving_plan.md b/cover_image_serving_plan.md index 8706805..cb79d62 100644 --- a/cover_image_serving_plan.md +++ b/cover_image_serving_plan.md @@ -50,23 +50,30 @@ This ensures one source of truth for path resolution. #### Change 1: Store relative file path -**Location**: Where metadata.FilePath is set (multiple locations) +**Location**: In `internal/services/media_scanner.go` - wherever `FilePath` is set in the database insert -**Current code**: +**Current code** (line 579): ```go -metadata.FilePath = path // path is absolute like /app/uploads/Author/Book/file.epub +FilePath: path, // path is absolute like /app/uploads/Author/Book/file.epub ``` **New code**: ```go -metadata.FilePath = s.getRelativePath(path) +FilePath: s.getRelativePath(path), ``` +**Also update** line 617 for format file paths: +```go +FilePath: pgtype.Text{String: s.getRelativePath(format.FilePath), Valid: true}, +``` + +--- + #### Change 2: Store relative cover path -**Location**: Around lines 514-517, 641-651, 832-837, 1056-1067, 1472 +**Location**: In `internal/services/media_scanner.go` - wherever `metadata.CoverPath` is set -**Current code** (example at line 514-517): +**Current code** (example at line 517): ```go if len(coverImage) > 0 && metadata.CoverPath == "" { coverPath := path + ".cover.jpg" @@ -87,6 +94,13 @@ if len(coverImage) > 0 && metadata.CoverPath == "" { } ``` +**All locations where metadata.CoverPath is set**: +- Line 517 (main cover) +- Line 645 (sidecar cover) +- Line 651 (sidecar cover alternative) +- Line 1060 (main cover) +- Line 1067 (sidecar cover) + #### Change 3: Add helper function **Add new function** in `internal/services/media_scanner.go`: @@ -475,11 +489,11 @@ cfg.CollectionHandler, err = handlers.NewCollectionHandler(cfg.Queries, cfg.Libr --- -### Step 2: Update collections.go - GetCollectionBooks (line ~199) +### Step 2: Update collections.go - GetCollection handler (line ~193-201) **File**: `internal/handlers/collections.go` -**Current code** (lines 193-201): +**Current code** (lines 193-201 in GetCollection function): ```go bookList := make([]BookInfo, 0, len(books)) for _, book := range books { @@ -534,11 +548,11 @@ func (h *CollectionHandler) resolveCoverURL(libraryID pgtype.UUID, coverPath pgt --- -### Step 3: Update collections.go - CheckMatchRules (line ~626) +### Step 3: Update collections.go - TestRules/BookMatch (lines 620-641) **File**: `internal/handlers/collections.go` -**Current code** (lines 620-641): +**Current code** (lines 620-641 in TestRules function): ```go var matches []BookMatch for _, item := range mediaItems { @@ -588,44 +602,59 @@ for _, item := range mediaItems { --- -### Step 4: Update collections.go - ListCollectionBooks (line ~935) +### Step 4: Update collections.go - PreviewCollection (lines 910-919) and mediaItemsToListMediaItemsRow helper (line 935) **File**: `internal/handlers/collections.go` -**Current code** (lines 925-954 - the entire function): +**Location 1 - PreviewCollection function** (lines 910-919): + +**Current code**: ```go -return database.ListMediaItemsRow{ - ID: item.ID, - LibraryID: item.LibraryID, - Title: item.Title, - Author: item.Author, - Isbn: item.Isbn, - Description: item.Description, - FilePath: item.FilePath, - FileSize: item.FileSize, - MimeType: item.MimeType, - CoverImagePath: item.CoverImagePath, - // ... rest of fields +bookCards := make([]BookInfo, len(matchedItems)) +for i, item := range matchedItems { + itemUUID, _ := uuid.FromBytes(item.ID.Bytes[0:16]) + bookCards[i] = BookInfo{ + MediaItemID: itemUUID.String(), + Title: item.Title, + Author: textToString(item.Author), + CoverImagePath: textToString(item.CoverImagePath), + } } ``` **New code**: ```go -return database.ListMediaItemsRow{ - ID: item.ID, - LibraryID: item.LibraryID, - Title: item.Title, - Author: item.Author, - Isbn: item.Isbn, - Description: item.Description, - FilePath: pgtype.Text{String: h.resolveFileURL(item.LibraryID, item.FilePath), Valid: item.FilePath.Valid}, - FileSize: item.FileSize, - MimeType: item.MimeType, - CoverImagePath: pgtype.Text{String: h.resolveCoverURL(item.LibraryID, item.CoverImagePath), Valid: item.CoverImagePath.Valid}, - // ... rest of fields +bookCards := make([]BookInfo, len(matchedItems)) +for i, item := range matchedItems { + itemUUID, _ := uuid.FromBytes(item.ID.Bytes[0:16]) + bookCards[i] = BookInfo{ + MediaItemID: itemUUID.String(), + Title: item.Title, + Author: textToString(item.Author), + CoverImagePath: h.resolveCoverURL(item.LibraryID, item.CoverImagePath), + } } ``` +**Location 2 - mediaItemsToListMediaItemsRow helper** (line 935): + +**Current code**: +```go +func mediaItemsToListMediaItemsRow(item database.MediaItems) database.ListMediaItemsRow { + return database.ListMediaItemsRow{ + // ... + CoverImagePath: item.CoverImagePath, + // ... + } +} +``` + +**New code**: +```go +// NOTE: This helper function doesn't have access to libraryID +// Consider refactoring to pass libraryID or handle URL resolution at call site +``` + **Add helper method** for file URL resolution: ```go @@ -650,7 +679,7 @@ func (h *CollectionHandler) resolveFileURL(libraryID pgtype.UUID, filePath pgtyp --- -### Step 5: Update progress.go - two locations (lines ~288 and ~359) +### Step 5: Update progress.go - two locations (lines 286-289 and 357-360) **File**: `internal/handlers/progress.go` @@ -676,7 +705,7 @@ func (h *Handler) resolveCoverURL(libraryID pgtype.UUID, coverPath pgtype.Text) } ``` -**Location 1 - GetReadingProgress function** (around line 286-289): +**Location 1 - GetAllProgress function** (lines 286-289): **Current code**: ```go @@ -691,7 +720,7 @@ if mediaItem.CoverImagePath.Valid { coverPath := h.resolveCoverURL(mediaItem.LibraryID, mediaItem.CoverImagePath) ``` -**Location 2 - GetAllReadingProgress function** (around line 357-360): +**Location 2 - GetAllProgressData function** (lines 357-360): **Current code**: ```go @@ -783,8 +812,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 `libraryService` to struct and constructor; add `resolveCoverURL()`, `resolveFileURL()` helpers; update lines ~199, ~626, ~935 | -| `internal/handlers/progress.go` | Add `resolveCoverURL()` to Handler (in commonhandlers.go); update lines ~288, ~359 | +| `internal/handlers/collections.go` | Add `libraryService` to struct and constructor; add `resolveCoverURL()`, `resolveFileURL()` helpers; update lines 193-201, 620-641, 910-919 | +| `internal/handlers/progress.go` | Add `resolveCoverURL()` to Handler (in commonhandlers.go); update lines 286-289, 357-360 | | `internal/handlers/media.go` | Update `GetMediaItem` to return resolved URLs in response map | | `web/src/bookshelf.ts` | Remove `/covers/` prefix from cover image URL |