DOWNLOAD_AUTOMATION.md
docs/features/DOWNLOAD_AUTOMATION.md
1# Download automation23Shared controls live under Settings → Downloads on Android, iOS, desktop and web.4All new automatic actions default off. Existing delete-after-reading preferences5are honored with the new protections.67## Behavior89- Library updates can queue newly discovered releases. Include/exclude categories,10 unread-only and filler rules apply; exclusions win. Existing queue rows, including11 stopped, failed and paused rows, are preserved. Release priority and duplicate12 selection match the reader.13- Opening a chapter/episode can download a configurable number of upcoming unread14 releases, independently for manga, anime and novels. Existing download rows count15 toward the window. Incognito sessions do not download ahead.16- Cleanup after consumption and cleanup after a manual read mark are independent.17 Completion is explicitly reported by each reader/player; a progress save on an18 already-read chapter does not invent a new completion event.19- Cleanup can retain the latest N eligible read releases and exclude categories.20 Bookmarks are protected by default. Local-library originals and open chapters21 are always protected. Continuous readers retain leases for earlier visible22 chapters until their stream closes. Queued/running/paused transfers are not23 removed by automatic cleanup.24- Preview cleanup lists read downloads before explicit deletion. Confirmation25 authorizes only the previewed IDs. Read state, retention, bookmarks, category26 exclusions, active readers and task state are checked again before deletion.2728Automatic requests use the existing persistent queue, destination, Wi-Fi policy,29source concurrency, retry/recovery and speed controls. Anime resolves video30streams with source/video headers; novels store cleaned chapter HTML. Readers31prefer downloaded images, video and novel HTML before source extraction.3233## Recovery and file safety3435New-release IDs are recorded in the same database batch as the updater's chapter36changes. Queue admissions precede receipt acknowledgement; interrupted handoffs37can replay without duplicating persisted queue rows. Receipts are acknowledged in38chunks. Fixing destination preferences triggers another attempt after admission39failure. Consumption receipts exist only for downloads subject to enabled cleanup40and are removed after cleanup; ordinary reading with cleanup off adds no ledger.4142Managed download deletion runs outside the UI thread. It rejects local originals,43malformed root/title paths, traversal and redirected chapter paths. A task is44reserved against retry through both file deletion and the database commit.45Manual removal joins a transfer before deleting its files. Combined library/download removal awaits filesystem work before deleting database parents; failures preserve titles for retry. Failure/cancellation46preserves database markers for retry. Profile retirement joins owned cleanup and47pending filesystem writes before closing storage.4849New settings are nested under `features` because `DbSettings` already reaches the50JVM constructor/copy method parameter limit. Released settings and the prerelease51flat `home` field remain readable. Credentials and automatic-work receipts are52excluded from exported backups. Feature preferences remain installation-local53through hub sync and profile restore, avoiding activation on another device.5455## Browser storage5657Web downloads use the origin-private filesystem (OPFS). The bridge streams chunks58with backpressure and keeps metadata indexes in memory; downloaded binaries are59not stored in localStorage. Legacy backup storage/listings remain compatible, and deleting a closed profile removes its OPFS files while preserving explicit backup exports. The additional-profile HTTP transport streams through a bounded channel rather than buffering a response or imposing the old 64 MiB body cap. Browser60file preparation finishes before bootstrap or opening another profile.6162A service worker serves local media with byte ranges and relative HLS resources.63Downloaded HTML receives a sandbox CSP. This requires a secure context and a64browser supporting OPFS and service workers. Source requests remain subject to65the browser's normal CORS/header restrictions and the player's codec support.66Browser archive import/CBZ creation and broader local-library management are67tracked separately in the parity ledger.6869API references: [OPFS](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system),70[writable file streams](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createWritable).7172## Verification7374- Shared policy, automation, updater, filesystem failure/path safety, offline75 content, settings migration, backup/sync isolation and profile lifecycle tests.76- Kotlin/Wasm OPFS interop tests (stream/append/promote/read/bounds and interrupted77 writes, legacy backups and profile deletion), plus streaming HTTP tests above 64 MiB with backpressure and cancellation checks. Asynchronous failure propagation was verified using a temporary negative control. Use `--tests '*BrowserStorageInteropTest*'`; JS filters include methods.78 Empty suites now fail instead of producing a misleading green result.79- `scripts/test-browser-storage.mjs` exercises real Chrome OPFS: 12 MiB streaming,80 reload recovery, partial resume, byte ranges, protected deletion, path/profile81 isolation and downloaded-HTML sandbox headers. It accepts an optional path to82 an installed `playwright-core` module.8384Final target checks and any remaining limitations are recorded in85`../parity/NON_UI_IMPLEMENTATION.md`.86