feat: defer runtime bootstrap and harden watchlist refresh

This commit is contained in:
Dymas
2026-05-14 07:00:48 +02:00
parent 5feee92bcd
commit a6ef93cc95
6 changed files with 2998 additions and 1663 deletions
+45 -8
View File
@@ -2,14 +2,16 @@
A local web UI for a system-wide `ani-cli` install.
Current version: `0.8.13`
Current version: `0.12.0`
## Project Layout
```text
ani-cli-web/
app.py Web server, queue, watchlist, thumbnail cache, and post-download file naming.
app.py Web server, runtime wiring, request handlers, and CLI entrypoint.
web_templates.py Shared Search, Config, and Watchlist page markup plus page-shell helpers.
ani-cli-web Launcher script.
test_app.py Regression tests with isolated temp-state setup.
VERSION Project version.
CHANGELOG.md Change history.
README.md Project documentation.
@@ -41,16 +43,21 @@ By default the server binds to `127.0.0.1:8421`.
## Overview
`ani-cli-web` keeps search and download management on `/` and exposes the watchlist on `/watchlist`.
`ani-cli-web` keeps search and download management on `/`, saved defaults on `/config`, and the watchlist on `/watchlist`, all with the same sidebar navigation layout and a Tsuki-inspired visual style.
The app currently includes:
- Search against AllAnime with `sub` or `dub` mode selection.
- Episode loading for the selected result.
- Queueing downloads with editable library name, season, episode range, quality, and target folder.
- A dedicated Config page for saved default folder, mode, and quality settings.
- A paged SQLite-backed download queue with retry, cancel, remove, retry-failed, and clear-finished actions.
- A paged SQLite-backed watchlist with summary cards, per-show refresh, bulk refresh, source links, and thumbnail tools.
- Background `Refresh All` execution with status polling instead of a long blocking HTTP request.
- Persistent watchlist refresh history that survives restarts and marks interrupted bulk refresh jobs clearly.
- Local thumbnail caching plus manual thumbnail upload when automatic cover lookup fails.
- A refreshed glassy dark UI inspired by the Tsuki frontend design language.
- Shared page templates moved out of `app.py` plus broader regression tests for higher-risk queue, watchlist, and handler flows.
- Project-local runtime state under `.ani-cli-web/`.
## Search Page
@@ -66,10 +73,34 @@ Workflow:
The page also includes:
- A Defaults panel for the saved download folder, mode, and quality.
- A dependency status panel so you can see which required tools are available.
- A live queue view that refreshes automatically.
## Config Page
The Config page at `/config` is where saved defaults now live.
Use it to:
1. Set the default download folder.
2. Choose the default `sub` or `dub` search mode.
3. Choose the default search quality used to prefill the Search page.
Those saved defaults are written into the project-local `config.json` and loaded automatically when the Search page opens.
The Config page also shows the current app version plus dependency status in a compact centered layout.
## Access Guard
By default, `ani-cli-web` only serves loopback clients such as `127.0.0.1` and `::1`.
If you intentionally want LAN or remote access, set:
```sh
ANI_CLI_WEB_ALLOW_REMOTE=1
```
This keeps the queue, config, and watchlist mutation APIs safer by default when the app is rebound away from localhost.
## Download Queue
The queue is stored in SQLite and shown 10 jobs at a time.
@@ -100,7 +131,7 @@ You can add entries in two ways:
Watchlist features:
1. `Refresh` updates one tracked show.
2. `Refresh All` updates the entire watchlist.
2. `Refresh All` runs in the background, rejects duplicate queueing while a refresh is already pending or running, and preserves interrupted job status across restarts.
3. `Open` jumps back to the Search page with the title pre-filled.
4. Clicking the anime title opens the AllManga source page at `bangumi/<show_id>` in a new tab.
5. `Remove` deletes the watchlist entry and clears its cached poster file.
@@ -116,6 +147,7 @@ Current thumbnail behavior:
- Cached thumbnails render from the local project cache when available.
- The page adds a fresh nonce to thumbnail URLs to avoid stale browser-cached misses.
- Missing visible covers are warmed up in small batches instead of one request per card all at once.
- Thumbnail image tags only hit the local route for already-cached files, so opening the watchlist no longer triggers a per-card remote lookup burst.
- AnimeSchedule is tried first for cover lookup.
- If a season-labeled title fails as-is, lookup retries with simplified base-title queries.
- AniDB is used as a fallback when AnimeSchedule does not resolve a cover.
@@ -140,7 +172,7 @@ ani-cli-web/.ani-cli-web/
That folder currently holds:
- `config.json`
- `queue.sqlite3`
- `state.sqlite3`
- legacy `queue.json` migration input when present
- legacy `watchlist.json` migration input when present
- `thumbnails/`
@@ -148,6 +180,7 @@ That folder currently holds:
- staging files for active downloads
Legacy files from `~/.config/ani-cli-web/` and `~/.local/state/ani-cli-web/` are migrated into the project-local folder automatically on startup.
The earlier project-local `queue.sqlite3` filename is also migrated automatically into `state.sqlite3`.
## Configuration
@@ -159,11 +192,15 @@ Environment variables:
- `ANI_CLI_QUALITY`: initial quality such as `best`, `1080`, or `720`.
- `ANI_CLI_WEB_HOST`: server host, default `127.0.0.1`.
- `ANI_CLI_WEB_PORT`: server port, default `8421`.
- `ANI_CLI_WEB_ALLOW_REMOTE`: allow non-loopback clients when set to `1`, `true`, `yes`, or `on`.
- `ANI_CLI_WEB_DEBUG`: enable debug logging when set to `1`, `true`, `yes`, or `on`.
- `ANI_CLI_WEB_STATE_ROOT`: override the project-local state directory path; useful for isolated test runs or custom storage locations.
Saved defaults from the UI are written into the project-local `config.json`.
## Notes
- Watchlist and queue data are stored in the same project-local SQLite database.
- Importing `app.py` no longer boots the runtime worker threads automatically; runtime setup is deferred until startup or first use.
- Watchlist and queue data are stored in the same project-local SQLite database file, `state.sqlite3`.
- Runtime folders such as `.ani-cli-web/`, `downloads/`, and Python bytecode cache directories at any depth are ignored by git.
- Focused regression tests live in `test_app.py`, run against an isolated temporary state root, and can be started with `python3 -m unittest test_app.py`.