Commit graph sonda/internal/library
Author SHA1 Message Date
tgiachi
6d004c4225 feat(library): count unsupported audio formats and skip NAS system folders
- feat: the scan summary has an unsupported counter for audio files in formats
  Sonda cannot read yet (m4a, ogg, opus, wav, wma, ...); they are counted and
  never opened, instead of disappearing without a trace. Video containers such
  as .mpg are not counted
- feat: folders named .@__thumb, @Recycle, #recycle, @eaDir, $RECYCLE.BIN and
  System Volume Information are skipped, matched by exact name ignoring case,
  so a NAS recycle bin does not end up in the library; a library whose own
  folder carries one of these names is still scanned, and files indexed before
  from such a folder are flagged missing like any vanished file
- docs: the README lists the new counter and the skipped folders
- test: system folders at any depth, near-miss names, a library inside a
  system-named folder, entries flagged missing, unsupported counting

Closes #14
2026-11-11 14:25:33 +01:00
tgiachi
eb23ee426a fix(library): make the libraries upgrade and validation robust
- fix(migration): roots that differ only in case (/Music and /music are two
  directories on Linux) used to make migration 0005 fail on the unique name;
  the later ones now get a numeric suffix
- feat(library): at startup, log a warning for every library whose directory
  cannot be read or that overlaps another, because migrated rows skip
  validation and may still hold roots that were removed from the old config
- fix(library): creating or updating a library is now serialised, so two
  concurrent requests cannot both pass the overlap check
- fix(library): changing a library's directory or deleting it is refused with
  409 scan_running while a scan runs; the scan works from the list it started
  with and would write under a stale path
- fix(library): library names clash ignoring case and accents the same way on
  SQLite and PostgreSQL, checked in Go
- fix(library): changing only the path no longer revalidates an untouched
  name, which can be longer than the limit after a migration
- test: roots differing in case on both databases; concurrent creates with a
  slow store, verified to fail without the lock; the busy guard; Problems
2026-11-11 13:34:44 +01:00
tgiachi
46463846b3 feat(library): named media libraries managed through the API
- feat(storage): libraries table (name, path); audio_files points at a library
  by id instead of repeating the root path; migration 0005 for both drivers
  turns every existing root into a library and keeps file ids, tracks and the
  missing flag
- feat(library): Libraries service validates names and paths: absolute, an
  existing directory, never the filesystem root, never inside or around
  another library (checked on real paths, so symlinks cannot hide an overlap)
- feat(api): admin-only GET/POST /libraries, PATCH/DELETE /libraries/{id} and
  POST /libraries/{id}/scan; deleting a library drops its index entries and
  keeps tracks and listening history
- feat(library): the scanner and the scan manager work on libraries; scanning
  with no libraries answers 409 no_libraries
- feat(streaming): the library directory comes from the database instead of
  a configured list of roots
- breaking(config): library.roots is removed; an old config fails with a hint
  to use POST /api/v1/libraries
- test: CRUD and duplicates on both databases, path change keeps files,
  upgrade of a database written before libraries existed
2026-11-11 13:30:25 +01:00
tgiachi
11aa47e79f fix: refresh match keys at startup and re-check file type after stat
- fix(storage): RefreshMatchKeys recomputes name_key and title_key for rows
  created before migration 0003, whose SQL lower() key is ASCII-only on SQLite;
  idempotent, runs at every start
- fix(library): re-check that the stat result is a regular file, closing the
  window where a path is swapped for a FIFO or symlink after the directory read
- docs(library): note that OnFinish callbacks of consecutive scans can overlap
- test: old rows with approximate keys are matched after the refresh
2026-11-11 12:30:43 +01:00
tgiachi
d6e9e09ce7 fix(library): harden the scanner against special files, stat errors and lossy logging
- fix: skip FIFOs, sockets and devices named like audio files; opening a named
  pipe blocked a scan forever and left the manager stuck in "running"
- fix: a file that cannot be stat'ed for a transient reason is unknown, not
  gone, so it is never marked missing or used as a rename source
- fix: log the scan result from Manager.OnFinish instead of the lossy event
  hub, so the line can no longer be dropped
- fix(storage): match artists and albums on a Unicode-aware key computed in Go
  (migration 0003, both drivers), so SQLite and PostgreSQL agree
- test: FIFO, stat errors, OnFinish, Unicode artist and album matching
2026-11-11 12:28:44 +01:00
tgiachi
21b49d7549 fix(library): never mark a root's files missing when the root looks empty
- fix: follow a root that is itself a symlink (e.g. /srv/music -> /mnt/nas/music).
  Before, the walk saw a non-directory, found nothing and flagged every indexed
  file as missing. Symlinks inside a root are still skipped
- fix: when a root is empty but files are indexed (typical for an unmounted
  NAS mount point), return an error instead of flagging the whole library
- test: symlinked root, symlink to a file, empty root with and without indexed
  files
2026-11-11 12:19:34 +01:00
tgiachi
4c7e99bd6a feat(library): add concurrent read-only scanner with progress events
- feat(library): walk each root, plan the changes, read tags with N parallel
  workers and write from a single goroutine
- feat(library): detect renames by size and mtime only when the match is
  unambiguous; mark vanished files missing instead of deleting them
- fix-safe: an unreadable root, an unreadable subdirectory or an interrupted
  scan never marks files as missing; symlinks are skipped
- feat(library): event hub that fans scan progress out to subscribers without
  ever blocking the scan (ready for a websocket client)
- feat(library): TagLib (WASM, no CGO) reader for MP3 and FLAC tags and
  audio properties, with title and artist fallbacks
- feat(storage): library repository for SQLite and PostgreSQL
- feat(api): POST/GET /api/v1/library/scan to start a scan and read its status
- feat(config): library.scan_workers
2026-11-11 12:16:45 +01:00