Commit graph sonda/internal/api/http/covers_test.go
Author SHA1 Message Date
tgiachi
a880b87a9e chore: move the module path to git.kmalloc.org/squid/sonda
Migrating hosting from Codeberg to git.kmalloc.org. Renames the
module path in go.mod, every internal import, and the OCI image
source label in the Dockerfile. Build and full test suite verified
green after the rename.
2026-11-15 17:30:29 +01:00
tgiachi
345ad8eecb fix(images): a refresh never wipes covers, the job sees outages and starts cleanly
- A refresh (or any rebuild) while the Cover Art Archive is switched off, but its data
  not taken back, no longer turns the covers it gave into "no cover" and deletes their
  files: the stored cover is kept and its date renewed, so the files are not searched
  again at every request.
- When none of an album's files and folders can be looked at (an unmounted disk, a
  permission), that is ErrFilesUnreadable (503 files_unreadable), not "no picture": nothing
  is remembered, nothing built is touched, the archive is not asked, and the job counts it
  as a failure and gives up after five. A link that leaves the library is still just refused.
- The job calls the build for every album that is not good yet and does not serve an older
  cover on an outage, so a dead provider shows as failures and trips the limit instead of
  being reported as covers from the archive.
- Start marks the job as running before counting the albums and does not hold the lock
  meanwhile; a stop that comes back as a plain driver error is not a failure; a job that
  finished by itself is never marked stopped.
- Spec and README say so; the tests cover each case, including a list that fails midway.
2026-11-12 09:43:51 +01:00
tgiachi
548ee03d83 feat(images): a background job that builds all the covers
- POST /library/covers (admin) starts, in the background and one at a time like a scan,
  a job that builds the cover of every album that has something to play and no cover that
  is still good; GET /library/covers shows the progress and how the last job ended;
  DELETE /library/covers stops it. ?refresh=true searches every album again.
- For each album it does what opening its cover does: the user's own files first, then the
  Cover Art Archive if the provider is on. It gives up, and says why, when the provider
  fails for five albums in a row; an album that vanished is skipped, not a failure.
- This is the one request that goes through the whole library, and the README and the
  provider text say so: with the archive on it sends the release group id of each album with
  no picture in its files, one after the other, spaced out.
- NewRouter now refuses to build when a service was not wired, naming it, instead of
  panicking at the first request (the wiring of this job in main had been missed, which no
  test could see).
- The outbound spacing test measures where the request leaves the client, so a busy
  machine cannot make it fail.
- Spec, contract and HTTP tests, README updated.

Closes #45
2026-11-12 09:34:27 +01:00
tgiachi
d5ed0f2e9c feat(images): album covers from the Cover Art Archive
- The scan reads the MusicBrainz release group id of an album from the tags of its
  files (MUSICBRAINZ_RELEASEGROUPID, a vorbis comment or an ID3 frame) and stores it in
  albums.mbid: it is taken only when the file has an album and exactly one valid id, an
  album keeps the one it has, and an id that another album owns is not given twice. A full
  rescan reads it for music that was already indexed.
- New provider "coverartarchive" (off by default, no key, contact in the User-Agent). When
  an album has no picture in the user's own files, which always come first, its cover is
  asked from the archive by that id and never by a title: only the id leaves the server.
  The same GET /albums/{id}/cover; the record keeps the source. An outage is a 502
  provider_unavailable and is not remembered, and an older cover is served in its place.
- The archive answers with three redirects (coverartarchive.org, archive.org, a data node
  whose name changes). The outbound client can now follow redirects, but only the ones the
  caller allows, up to a limit; here that is https on archive.org and its subdomains.
- A purge counter now guards the covers too: a read that started before the provider's data
  was taken back is not kept. Removing the provider's data forgets the covers that came from
  it and deletes their files, and leaves the ones from the user's files.
- Spec, contract and HTTP tests, README updated; the facts of the real archive are written down.

Closes #43
2026-11-12 09:09:31 +01:00
tgiachi
0e121ead8e feat(images): album covers from my own files
- GET and HEAD /albums/{id}/cover serve a JPEG made from the picture embedded in
  the album's files, or else a cover, folder, front, album or albumart image
  (jpg, jpeg, png) in the album's folder. ?size=small (300 px) or large (1000 px).
  The token can be in the query, so an <img> element can use it.
- Built the first time it is asked for, scaled, and kept in storage.data_dir
  (SONDA_DATA_DIR, default "data"); an album with no cover is remembered for a day.
  A new or changed file of the album, or a full rescan, clears the record.
- Nothing is sent anywhere. Pictures are untrusted: files are opened inside the
  library only (links are not followed), over 20 MB or 16 million pixels are
  ignored, and what is served is always a JPEG made here. Stored files are 0600.
- images table (migration 0013, SQLite and PostgreSQL).
- Spec, contract test, README and example config updated.

Closes #37
2026-11-11 20:52:36 +01:00