EXTERNAL_DOWNLOADER_PROGRESS.md
docs/features/EXTERNAL_DOWNLOADER_PROGRESS.md
1# External downloader integration23The shared `Aria2RpcClient` implements the documented HTTP JSON-RPC protocol:4token authorization, caller-selected GIDs, URI admission, bounded batched progress5queries, pause/resume/cancel and removal of completed results. It validates response6identity, bounds streamed responses to 1 MiB, preserves cancellation, rejects header7injection and unsafe output filenames, and never issues global queue commands.8Remote error messages are not exposed, since they can contain source URLs/secrets.9Six shared protocol tests passed on desktop and Kotlin/Wasm, covering request10options, identity matching, batched errors, bounded responses and cancellation.11The adapter compiled for Android and iOS alongside those targets.1213## User behavior1415Settings → Downloads provides the preferred downloader, aria2 JSON-RPC URL, secret16token, remote directory and a connection test. Manual manga and direct-video17downloads use aria2 when selected. Explicit local-folder requests, novels and HLS18playlists keep using the built-in downloader. Download-ahead and automatic release19downloads also remain in managed local storage. Image processing settings apply to20the built-in downloader.2122Remote jobs appear in both Downloads settings and the download manager, with file23progress, their selectable server directory, pause/resume/cancel, refresh, retry and24receipt removal. Removing a receipt requires confirmation and neither cancels a25remote transfer nor deletes server files. Remote completion never writes a local26archive path or download row, so downloaded-only views and local cleanup stay correct.2728## Recovery and ownership2930Each file has a profile-owned GID, persisted and flushed before RPC submission.31The intermediate `Submitting` state survives a lost reply or process restart.32Recovery queries that same GID; missing/unverified work requires attention and is33never blindly admitted again. A user retry verifies the old task is stopped before34creating a new GID. Identical resource URLs/headers can resume their existing output;35changed resources receive fresh filenames to avoid mixing an old partial file with36new content. Old partial files can remain on the server.3738Jobs retain the title/source/chapter identity so restoring a library with reused39database IDs cannot redirect an old retry to unrelated content. The endpoint and a40SHA-256 credential binding prevent old controls from targeting a different account.41Restoring the original account settings permits reconciliation. Rotated credentials42are treated as a new account binding; old receipts can be removed locally while the43server's own management interface remains available.4445All work uses captured profile HTTP/scope and raw RPC requests. Retirement joins46source/network work; it leaves already accepted server transfers running. Source47URLs and headers are cleared after acceptance. RPC secrets, jobs and operational48credentials are removed from portable backups, including sensitive exports. The49preferences and receipts are excluded from sync; restoring a backup preserves the50current installation's feature settings.5152## Performance and limits5354The queue observes configuration changes without comparing the potentially large55job payload. Accepted remote work is polled only while the queue is observed;56pending admissions and control requests continue independently. The UI observes57with lifecycle awareness. Idle queues issue no requests, and progress persistence58does not wake another poll. Connection failures back off to at most one retry per59minute. RPC timeouts become ordinary failures, preserving the queue owner's job.6061Each pass visits up to four jobs, queries at most 64 file statuses per job in one62batch, and admits at most four new files per job. Progress-only checkpoints are63limited to once per 15 seconds; admission/state transitions are durable. Queue64limits are 100 unresolved jobs, 2,000 files per chapter and a 2 MiB serialized receipt65budget, retaining up to 155 finished receipts alongside active work. Settings66read/transform/write is batched so simultaneous UI edits cannot overwrite receipts.6768Integration checks passed for durable admission, serialized restart,69ambiguous acknowledgements, missing tasks, source changes, pause/resume/cancel,70safe retries, profile retirement/isolation, private backup/sync settings, manual71routing and reactive polling. The final broader run passed 270 desktop tests and7260 Kotlin/Wasm browser tests, with compilation on Android, iOS, desktop and web.7374The HTTP API is the equivalent integration for Android, iOS, desktop and web. Users75provide their own aria2 server and token. Web deployments require a browser-reachable76HTTPS endpoint and appropriate CORS configuration. No external account or live aria277server has been supplied or used for live verification. Protocol behavior is78verified against deterministic RPC fixtures; no external account verification is79implied.8081Protocol reference: [official aria2 RPC manual](https://aria2.github.io/manual/en/html/aria2c.html#rpc-interface).82