M8b: Library admin (libraries, scans, problem items) #23

Merged
mett merged 3 commits from feat/m8b-library-admin into main 2026-10-29 13:04:33 +01:00
Owner

Second of three M8 parts, as agreed in the session: library management. Item editing (metadata, cover, matching, chapters) follows as M8c, which will close #8.

Part of #8

What's in it

  • Admin page (sidebar, server admins only): each library with folders, scan status and a link to its problem items. Scan and Force rescan (with a confirm).
  • Live scans: ABS reports scans as library-scan tasks over the socket (task_started/task_finished) and gives no percentage. While a scan runs the page shows how many items it has added or changed so far (from the item events), then the server's summary ("2 added (85 ms)"). The sidebar's Admin entry pulses while any scan runs. Scans already running when the app starts come from /api/tasks.
  • Library editor (new and edit): name, type (fixed after creation), icon, folders, metadata provider (from /api/search/providers), square covers, hide single-book series, folder watching, scheduled scan (presets or cron), mark as finished by seconds left or percent. The server merges settings, so the ones Cushion doesn't show keep their values.
  • Server folder browser: walks /api/filesystem from the top level, with breadcrumbs; a path can also be typed.
  • Delete library: asks for the library's name; files stay on the server.
  • Problem items: missing and invalid items with their server path; remove one or all (DELETE /api/items/:id and /api/libraries/:id/issues, no hard delete).
  • The library switcher follows library_added/updated/removed from the socket.

Separate fix (own commit)

Right after start or login the server often closes the first socket right after the handshake; the retry a second later works. That close marked the server unreachable for a second, so the first page loads came from the cache. On a new login the cache is empty, so the app showed "This account has no audiobook libraries" and moved to Downloads. A close before the server's init no longer counts as unreachable, and a successful login or resume marks the server reachable at once.

Tests

  • pnpm check 0 errors; Prettier clean on tracked and new files (pnpm lint as a whole still trips over another session's untracked .claude/worktrees/).
  • cargo fmt --check, cargo clippy --all-targets -D warnings: clean.
  • cargo test against the test server (ABS 2.37.2 via Podman): all pass. New live_admin.rs: providers and server folders; create, edit (settings round-trip), scan, force-rescan and delete a library; missing items made by copying a book into the test server's data folder, scanning, deleting it and scanning again, then removing one and the rest. Unit tests for the request body, decoding, scan-task tracking and item-event library ids.
  • live_lists.rs: a batch added to a collection may come back in any order, which made collection_lifecycle flaky on a fresh server; it now compares the set.
  • By hand in tauri dev (isolated XDG dirs, test server): Admin page, scan with 2 added, then 2 missing with the problems link, the problems page (remove one, remove all), a new podcast library through the folder browser with a daily scan and 90 %, editing it (values kept), the switcher picking it up, and deleting it with the typed name. The login fix was checked with the new log lines.
  • Not seen by hand: the "Scanning…" state and the sidebar dot (four test books scan in a few ms; the state logic has unit tests), and the Admin entry staying hidden for a non-admin user. Windows build not tested.

🤖 Generated with Claude Code

Second of three M8 parts, as agreed in the session: library management. Item editing (metadata, cover, matching, chapters) follows as M8c, which will close #8. Part of #8 ## What's in it - **Admin page** (sidebar, server admins only): each library with folders, scan status and a link to its problem items. Scan and Force rescan (with a confirm). - **Live scans:** ABS reports scans as `library-scan` tasks over the socket (`task_started`/`task_finished`) and gives no percentage. While a scan runs the page shows how many items it has added or changed so far (from the item events), then the server's summary ("2 added (85 ms)"). The sidebar's Admin entry pulses while any scan runs. Scans already running when the app starts come from `/api/tasks`. - **Library editor** (new and edit): name, type (fixed after creation), icon, folders, metadata provider (from `/api/search/providers`), square covers, hide single-book series, folder watching, scheduled scan (presets or cron), mark as finished by seconds left or percent. The server merges settings, so the ones Cushion doesn't show keep their values. - **Server folder browser:** walks `/api/filesystem` from the top level, with breadcrumbs; a path can also be typed. - **Delete library:** asks for the library's name; files stay on the server. - **Problem items:** missing and invalid items with their server path; remove one or all (`DELETE /api/items/:id` and `/api/libraries/:id/issues`, no hard delete). - The library switcher follows `library_added/updated/removed` from the socket. ## Separate fix (own commit) Right after start or login the server often closes the first socket right after the handshake; the retry a second later works. That close marked the server unreachable for a second, so the first page loads came from the cache. On a new login the cache is empty, so the app showed "This account has no audiobook libraries" and moved to Downloads. A close before the server's `init` no longer counts as unreachable, and a successful login or resume marks the server reachable at once. ## Tests - `pnpm check` 0 errors; Prettier clean on tracked and new files (`pnpm lint` as a whole still trips over another session's untracked `.claude/worktrees/`). - `cargo fmt --check`, `cargo clippy --all-targets -D warnings`: clean. - `cargo test` against the test server (ABS 2.37.2 via Podman): all pass. New `live_admin.rs`: providers and server folders; create, edit (settings round-trip), scan, force-rescan and delete a library; missing items made by copying a book into the test server's data folder, scanning, deleting it and scanning again, then removing one and the rest. Unit tests for the request body, decoding, scan-task tracking and item-event library ids. - `live_lists.rs`: a batch added to a collection may come back in any order, which made `collection_lifecycle` flaky on a fresh server; it now compares the set. - By hand in `tauri dev` (isolated XDG dirs, test server): Admin page, scan with 2 added, then 2 missing with the problems link, the problems page (remove one, remove all), a new podcast library through the folder browser with a daily scan and 90 %, editing it (values kept), the switcher picking it up, and deleting it with the typed name. The login fix was checked with the new log lines. - Not seen by hand: the "Scanning…" state and the sidebar dot (four test books scan in a few ms; the state logic has unit tests), and the Admin entry staying hidden for a non-admin user. Windows build not tested. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
- api/admin.rs: list libraries with settings and issue counts; create,
  edit and delete libraries (name, icon, media type, folders, provider and
  the settings Cushion shows; the server keeps the others); browse the
  server's folders; metadata providers; start a scan or forced rescan;
  list missing/invalid items and remove one or all (files stay).
- state/admin.rs: scans come over the socket as library-scan tasks. They
  are tracked per library (running, items changed so far, the server's
  summary) and sent to the UI as admin://scan; library changes on the
  server as library://libraries-changed.
- live_admin.rs: providers and folders, the library lifecycle with scans,
  and missing items (made by copying a book into the test server's data
  folder, scanning, deleting it and scanning again).
- live_lists.rs: a batch added to a collection may come back in any order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The server often closes a fresh socket right after the handshake; the
retry a second later works. That close counted as "server unreachable",
so for a second the app was offline: the first page loads (libraries,
home) came from the cache, which is empty on a new login, and the layout
sent the user to Downloads.

- A socket closed before the server's `init` no longer reports
  Disconnected; a failed connection or a lost live socket still does.
- A successful login or resume marks the server reachable at once.
- Log (info) when the server becomes reachable or unreachable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
M8 UI: Admin page, library editor, server folder browser, problem items
Some checks failed
CI / linux (pull_request) Has been cancelled
CI / fedora (pull_request) Has been cancelled
CI / windows (pull_request) Has been cancelled
435af0cc6d
- Sidebar "Admin" for server admins, with a pulsing dot while a scan runs.
- Admin page: every library with its folders, scan status (running with
  items changed so far, then the server's summary, or the last scan),
  Scan / Force rescan, and a link to items with problems. Reloads when a
  scan finishes.
- Library editor (new and edit): name, type (fixed after creation), icon,
  folders picked by browsing the server or typing a path, metadata
  provider, square covers, single-book series, folder watching, scheduled
  scans (presets or cron), and mark-as-finished by seconds left or
  percent. Delete asks for the library's name.
- Problem items page: missing/invalid items with their server path,
  remove one or all; files stay.
- The library switcher follows libraries added, changed or removed on
  the server.
- PLAN.md/README: M8 now in three parts; M8c (item editing) is next.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mett merged commit ea256a2ae0 into main 2026-10-29 13:04:33 +01:00
Sign in to join this conversation.
No description provided.