docs: update plan with accurate line numbers

This commit is contained in:
2026-02-27 10:44:12 -05:00
parent 501c898e58
commit 123ab0c966
+68 -39
View File
@@ -50,23 +50,30 @@ This ensures one source of truth for path resolution.
#### Change 1: Store relative file path #### 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 ```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**: **New code**:
```go ```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 #### 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 ```go
if len(coverImage) > 0 && metadata.CoverPath == "" { if len(coverImage) > 0 && metadata.CoverPath == "" {
coverPath := path + ".cover.jpg" 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 #### Change 3: Add helper function
**Add new function** in `internal/services/media_scanner.go`: **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` **File**: `internal/handlers/collections.go`
**Current code** (lines 193-201): **Current code** (lines 193-201 in GetCollection function):
```go ```go
bookList := make([]BookInfo, 0, len(books)) bookList := make([]BookInfo, 0, len(books))
for _, book := range 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` **File**: `internal/handlers/collections.go`
**Current code** (lines 620-641): **Current code** (lines 620-641 in TestRules function):
```go ```go
var matches []BookMatch var matches []BookMatch
for _, item := range mediaItems { for _, item := range mediaItems {
@@ -588,42 +602,57 @@ 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` **File**: `internal/handlers/collections.go`
**Current code** (lines 925-954 - the entire function): **Location 1 - PreviewCollection function** (lines 910-919):
**Current code**:
```go ```go
return database.ListMediaItemsRow{ bookCards := make([]BookInfo, len(matchedItems))
ID: item.ID, for i, item := range matchedItems {
LibraryID: item.LibraryID, itemUUID, _ := uuid.FromBytes(item.ID.Bytes[0:16])
bookCards[i] = BookInfo{
MediaItemID: itemUUID.String(),
Title: item.Title, Title: item.Title,
Author: item.Author, Author: textToString(item.Author),
Isbn: item.Isbn, CoverImagePath: textToString(item.CoverImagePath),
Description: item.Description, }
FilePath: item.FilePath,
FileSize: item.FileSize,
MimeType: item.MimeType,
CoverImagePath: item.CoverImagePath,
// ... rest of fields
} }
``` ```
**New code**: **New code**:
```go ```go
return database.ListMediaItemsRow{ bookCards := make([]BookInfo, len(matchedItems))
ID: item.ID, for i, item := range matchedItems {
LibraryID: item.LibraryID, itemUUID, _ := uuid.FromBytes(item.ID.Bytes[0:16])
bookCards[i] = BookInfo{
MediaItemID: itemUUID.String(),
Title: item.Title, Title: item.Title,
Author: item.Author, Author: textToString(item.Author),
Isbn: item.Isbn, CoverImagePath: h.resolveCoverURL(item.LibraryID, item.CoverImagePath),
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
} }
}
```
**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: **Add helper method** for file URL resolution:
@@ -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` **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**: **Current code**:
```go ```go
@@ -691,7 +720,7 @@ if mediaItem.CoverImagePath.Valid {
coverPath := h.resolveCoverURL(mediaItem.LibraryID, mediaItem.CoverImagePath) coverPath := h.resolveCoverURL(mediaItem.LibraryID, mediaItem.CoverImagePath)
``` ```
**Location 2 - GetAllReadingProgress function** (around line 357-360): **Location 2 - GetAllProgressData function** (lines 357-360):
**Current code**: **Current code**:
```go ```go
@@ -783,8 +812,8 @@ The backend now returns full URLs like `/uploads/library-{id}/path/to/cover.jpg`
| File | Changes | | File | Changes |
|------|---------| |------|---------|
| `internal/handlers/media.go` | Add `ResolveCoverURL()`, `ResolveFileURL()`, `resolveMediaURL()` helpers | | `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/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 ~288, ~359 | | `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 | | `internal/handlers/media.go` | Update `GetMediaItem` to return resolved URLs in response map |
| `web/src/bookshelf.ts` | Remove `/covers/` prefix from cover image URL | | `web/src/bookshelf.ts` | Remove `/covers/` prefix from cover image URL |