Commit graph sonda/internal/api/http
Author SHA1 Message Date
tgiachi
def20731be fix(streaming): open files through os.Root and tighten token parsing
- fix: open the audio file through os.Root with O_NONBLOCK. A FIFO under a
  stored path used to block the request forever in open(2) before the
  regular-file check could run; now it is refused immediately
- fix: os.Root also removes the gap between checking the path and opening it,
  so a symlink swapped in at the last moment cannot leave the library
  (absolute symlinks are refused even when they point back inside)
- fix(api): only "Authorization: Bearer <token>" is accepted again. The query
  token change had made a bare token in the header pass on every route
- fix(config): library.roots must be absolute paths; a relative root made
  every stream fail and depended on the directory sondad started in
- test: FIFO and symlink-to-FIFO without hanging, bare and non-Bearer headers
  on a normal route and on the stream route, relative roots
2026-11-11 13:00:17 +01:00
tgiachi
49f1051b3f feat(streaming): stream tracks with HTTP Range support
- feat(streaming): open a track's file only after checking it against the
  configured library roots: relative paths only, no "..", symlinks resolved on
  both sides so none can leave the root, regular files only
- feat(api): GET and HEAD /api/v1/tracks/{id}/stream via http.ServeContent
  (206, 416, Content-Length, conditional requests), MIME type from the
  extension, nosniff, no-referrer and private caching headers
- feat(api): the stream route also accepts the access token as access_token in
  the query string, because an audio element cannot send headers; no other
  route does, and the query string is never logged
- feat(storage): PlayableFile picks the oldest file of a track that is not
  flagged missing
- fix(api): internal errors set by handlers are now written to the request log
- test: range variants, HEAD, conditional requests, auth variants, traversal,
  symlink escape, symlinked root, missing file, directory instead of file
2026-11-11 12:56:20 +01:00
tgiachi
7e59bd26af fix(auth): close session races found in review
- fix(storage): lock the user row when rotating a refresh token or changing a
  password, so on PostgreSQL a token minted during a password change can no
  longer survive the revoke-everything that runs at the same time
- fix(auth): a replay of a just-rotated refresh token (two tabs, a retrying
  client) now fails without revoking the winner's new token; only a replay
  after RefreshReuseGrace is treated as theft and revokes every session
- fix(auth): changing or resetting a password and revoking the user's refresh
  tokens now happen in one transaction
- docs(auth): note that the last-admin rule relies on a single instance
- test: password change racing with a refresh (25 rounds, both databases),
  grace window, winner's token still valid after concurrent rotation
2026-11-11 12:45:06 +01:00
tgiachi
dbe9338af3 feat(auth): add refresh tokens, admin role and user management
- feat(auth): short-lived access tokens plus rotating refresh tokens stored as
  SHA-256 hashes; replaying a spent token revokes every session of that user
- feat(auth): is_admin flag; the first registered user is the admin and the
  last admin can be neither demoted nor deleted
- feat(api): POST /auth/refresh, /auth/logout, /auth/password and GET /auth/me
- feat(api): admin-only GET/POST /users, PATCH /users/{id}, PUT
  /users/{id}/password and DELETE /users/{id}; the admin check reads the role
  from the database on every call
- feat(api): starting a library scan is now admin-only
- feat(storage): users and refresh token repositories for SQLite and
  PostgreSQL (migration 0004; the oldest existing account becomes admin)
- feat(config): auth.access_ttl_minutes and auth.refresh_ttl_hours replace
  auth.token_ttl_hours
- test: rotation, reuse detection, concurrent rotation with a single winner,
  admin rules, role changes taking effect immediately
2026-11-11 12:38:42 +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
tgiachi
3a739dc3ae feat: add sondad server with config, storage, auth and listening API
- feat(config): TOML config with env overrides, strict parsing and validation
- feat(storage): SQLite (modernc) and PostgreSQL (pgx) backends through bun,
  embedded per-driver SQL migrations with a transactional runner
- feat(schema): catalog tables (artists, albums, tracks, audio_files with
  per-root paths), users and listening events with idempotency keys
- feat(auth): Argon2id password hashing, HS256 JWT tokens, first-user-only
  registration and login
- feat(api): gin REST API under /api/v1 (health, register, login, listens)
  with a consistent error envelope, body limit and request logging
- feat(sondad): zap logger, graceful shutdown, composition root in main
- chore: example config, .gitignore for secrets, DB files, IDE and agent files
2026-11-11 12:06:15 +01:00