diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-19 14:18:43 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-19 14:18:43 +0300 |
| commit | 53a599e763eb8f105dd12c8e0a2a50e2a850e4d6 (patch) | |
| tree | 02bb08debc8844b77b65a32c8448044bc21a419b /player-server/internal/repository | |
| parent | 212e849475701d91d5f173c3638af540fab796dd (diff) | |
Fix four defects flagged by S19/S20/S24; tighten scenarios
1. tagService.AssignTag and RemoveTag now use verifyModifyAccess
(owner role required) instead of verifyAccess. Tags are global
state visible to every user with access to a media item, so a
viewer must not be able to add or remove them. Favorites and
notes stay on verifyAccess because they're per-user data
(favorites.user_id, media_notes.user_id) and don't affect anyone
else. Verified via curl: viewer POST /media/{id}/tags now 403,
admin still 200.
2. serveFileResult now emits a strong ETag header
("<size>-<mtime-nanos>") before calling http.ServeContent. Go's
ServeContent honours If-None-Match when ETag is set, so iOS
audio clients and podcast apps can revalidate cached downloads
with conditional GETs. Verified via curl: ETag present on
/stream; If-None-Match matching the ETag returns 304.
3. MediaFilter gains IncludeDeleted flag; ListMedia skips the
implicit `deleted_at IS NULL` predicate when it is set.
FSScanner.loadExistingMedia now passes IncludeDeleted=true so
the dedup map includes soft-deleted rows. Previously a re-scan
of a soft-deleted file tried to CreateMedia and hit the
UNIQUE(set_id, rel_path) constraint, failing the whole scan and
setting progress.last_error. Now the rescan skips the row
cleanly; soft-delete sticks.
4. FSScanner.reconcileOrphans soft-deletes media rows whose
underlying file disappeared between scans. The scanner used to
only walk files that exist and never compare against the DB,
leaving phantom rows in GET /api/v1/media that 404'd on stream.
Verified via curl: rm /testdata/.../orphan.mp3, rescan, row
now has deleted_at != NULL.
Scenarios updated to lock in the fixed behaviour:
S19 step 15 — viewer tag-add now asserts 403, not 200.
S20 step 14 — asserts ETag is present and If-None-Match → 304.
S24 step 13 — asserts clean rescan (no last_error from UNIQUE).
S24 step 20 — asserts orphan rows are soft-deleted by rescan.
Verified: full Go unit suite passes; 25/25 LLM e2e scenarios;
22/22 Playwright e2e-web.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Diffstat (limited to 'player-server/internal/repository')
| -rw-r--r-- | player-server/internal/repository/media.go | 4 | ||||
| -rw-r--r-- | player-server/internal/repository/repository.go | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/player-server/internal/repository/media.go b/player-server/internal/repository/media.go index 60a611d..c06d257 100644 --- a/player-server/internal/repository/media.go +++ b/player-server/internal/repository/media.go @@ -231,7 +231,9 @@ func (s *SQLite) ListMedia(ctx context.Context, filter MediaFilter) ([]model.Med conds = append(conds, `media.duration <= ?`) args = append(args, *filter.MaxDuration) } - conds = append(conds, `media.deleted_at IS NULL`) + if !filter.IncludeDeleted { + conds = append(conds, `media.deleted_at IS NULL`) + } query += joins if len(conds) > 0 { diff --git a/player-server/internal/repository/repository.go b/player-server/internal/repository/repository.go index 487921f..e4b28c7 100644 --- a/player-server/internal/repository/repository.go +++ b/player-server/internal/repository/repository.go @@ -214,6 +214,12 @@ type MediaFilter struct { Sort string // Sort chooses the order: name, date, duration, play_count, or random. Limit int // Limit caps the number of returned rows. Offset int // Offset skips rows before returning results. + + // IncludeDeleted disables the implicit `deleted_at IS NULL` filter. + // Required for scanner dedup loads so soft-deleted rows are visible to + // the dedup map; without it a re-scan of a soft-deleted file would + // reinsert and hit the UNIQUE(set_id, rel_path) constraint. + IncludeDeleted bool } // MediaRepo manages media items. |
