diff --git a/docs-developers/bridge/audible.md b/docs-developers/bridge/audible.md index ee1feb18..af7268e3 100644 --- a/docs-developers/bridge/audible.md +++ b/docs-developers/bridge/audible.md @@ -267,17 +267,22 @@ progress or anything sent to the server carries an account id. - **promoting**: a request that finds the account's poll open raises its priority, never lowers it. -Enqueue keeps only the newest ended poll of each account (`pruneAudiblePolls`). +Queueing a poll keeps the account's newest ended poll (`pruneAudibleEnded`, +[Job history](pairing-and-jobs.md#job-history)). Removing an account cancels its open poll (`CancelAudibleRemoved`), and so does deleting the library it is mapped to (`CancelAudiblePaused`). Both are `IsCancelReason`'s, and the console keeps a copy (`SERVER_CANCEL_REASONS`). -**The scheduler** (`internal/audible.RunScheduler`, the module's `Start`) passes -at once, then every minute while the module is on. With an online Bridge that -offers the kind, it queues up to 20 due accounts at priority `-10` and records -`last_queued_at`, so a failed poll waits its interval. `catalog.DueAudiblePolls` -picks accounts that are not paused, are mapped to a person an account may still be -mapped to, and have a `last_queued_at` older than `poll_hours` (6 by default). +**The scheduler** (`internal/audible.RunScheduler`) runs when the module starts +and every minute while it is on. Each pass first cancels the open polls, syncs +and backups whose account is gone (`catalog.CancelOrphanAudibleJobs`), Bridge +online or not, which recovers the jobs an interrupted +[person delete](#on-the-server-0063-catalogaudiblego) left open. With an online +Bridge that offers the poll kind, it then queues up to 20 due accounts at +priority `-10` and records `last_queued_at`, so a failed poll waits its +interval. `catalog.DueAudiblePolls` picks accounts that are not paused, are +mapped to a person an account may still be mapped to, and have a +`last_queued_at` older than `poll_hours` (6 by default). The console's Check now (`POST /admin/audible/accounts/{account}/poll`) queues at a person's priority (`0`), or raises the open poll to it. A request that finds the @@ -922,11 +927,10 @@ server's scan would make a file part of an existing book when it is placed in a listed book's folder, or in a folder that already holds audio. The server refuses such a done import (`ErrImportNotOwn`, in [The done fold](#on-the-server-the-done-fold)). So `vacant` refuses that -destination before the license (step 3). The server refuses the one join left -before it queues anything: a `dest_path` whose folder is a disc folder ("CD 3") -directly inside an indexed book, or inside a folder with a `book` override, is -`400 invalid_dest_path` (`checkDestOwnFolder`), since the scan would join the disc -into that book and the fold would refuse it only after the whole download. +destination before the license (step 3). The server also checks disc folders when +saving destinations, templates, library mappings and folder overrides. The API +distinguishes an indexed parent book from a setting that joins its discs. +See [Audible disc destinations](../server/api/reference.md#audible-disc-destinations). ### Enrichment after placing @@ -1081,11 +1085,10 @@ request. Where the Bridge finds preorders is in [Preorders](#preorders). 2. `importOwnBook` checks the book. It must be indexed in a books library, else `ErrImportNotIndexed` (`not_indexed`). It must be the **title's own**, else `ErrImportNotOwn` (logged; `not_own_book`, or `rejected_match` for the book - marked Not this book). The title's own book carries the title's ASIN, or holds - **only** the files the backup placed (a single-file book is its file). A file the scan joined - into a folder book already there never makes that book (nor another title's) - this title's match. Nor does it ever match the book the admin marked Not this - book for the title. + marked Not this book). Ordinarily a matching ASIN is enough. When the scan + joins a backed-up disc into its parent book, even a matching ASIN requires + the file check. In that case, or when the ASIN differs, the book must have + indexed files and every one must appear in the backup's list of placed files. 3. If the checks pass, it sets the match (`match_how = 'import'`) and clears `rejected`, `import_pending` and any previous refusal. If it refuses the result, it records the reason and time on the title and keeps the existing @@ -1612,9 +1615,13 @@ the preorder clock skip an ignored title. Migration `0066` adds `sync_queued_at` the book's places (`moveAudibleTitles`). So the re-match trigger offers the moved book's place to Audible, never a stale row an earlier book left at the new path, and a carry that fails leaves the titles where they were. -- Unpairing keeps the rows; deleting a user removes their accounts (the FK). The - delete, of a person or of an owner's household member, then cancels the gone - accounts' open poll, backups and sync (`catalog.CancelOrphanAudibleJobs`). +- Unpairing keeps the rows. Deleting a person removes their accounts and those of + the household members deleted with them; deleting one household member removes + theirs. The delete transaction records those account ids, and after commit + `catalog.CancelRemovedAudibleJobs` cancels the open polls, syncs and backups of + the ids still absent, a backup queued in an earlier library included. A delete + interrupted before that is caught by the + [scheduler's sweep](#the-poll-audiblepoll). - The Bridge's writes are user-state writes (`store/userstate.go`): titles and the poll times don't move the content generation; a mapping change does. - Free text is cleaned and bounded, never refused (one odd title never fails a diff --git a/docs-developers/bridge/pairing-and-jobs.md b/docs-developers/bridge/pairing-and-jobs.md index e628eae9..a6c20d36 100644 --- a/docs-developers/bridge/pairing-and-jobs.md +++ b/docs-developers/bridge/pairing-and-jobs.md @@ -370,6 +370,19 @@ The Bridge may report a job it holds (`claimed`, `running` or `needs_attention`) `running`, `done`, `failed`, `needs_attention` or `cancelled`; it can never put a job back in the queue. +### Job history + +When the server enqueues a new job, it applies the kind's history rule +(`kindSpec.prune`) in the same transaction. Each rule applies only to ended +jobs of the same kind. + +| Job kind | History kept on enqueue | +|---|---| +| `audible.poll`, `audible.sync` | The newest ended poll and the newest ended sync for each Audible account. | +| `podcast.poll` | The newest ended poll for the show in that library. | +| `podcast.fetch`, `podcast.retain` | The newest ended fetch for the episode or retain for the show in that library, plus any older results the server has yet to apply (`podcast_folded`). | +| Other kinds, including `audible.import` | All of it. | + ### Claims and leases The Bridge long-polls `GET /bridge/jobs/next?wait=25&kind=…`. The server picks the diff --git a/docs-developers/server/api/index.md b/docs-developers/server/api/index.md index 10411431..271c62ec 100644 --- a/docs-developers/server/api/index.md +++ b/docs-developers/server/api/index.md @@ -404,7 +404,8 @@ Failures a person can fix also carry a machine-readable **`code`** next to | `account_paused` | `409` | `POST /admin/audible/accounts/{account}/poll` (Check now), a backup or Back up everything for an account whose library was deleted, until the Bridge maps it again | | `unknown_title` | `404` | an Audible title route (a backup, `PATCH /admin/audible/titles/{account}/{asin}`) naming no title of the account | | `already_matched` / `import_open` / `not_available` | `409` | [`POST /admin/audible/titles/{account}/{asin}/backup`](reference.md#post-apiv1adminaudibletitlesaccountasinbackup): the title is on this server; its backup is waiting, running or pending; it is `unavailable` or `gone` | -| `invalid_dest_path` / `invalid_template` | `400` | a title's `dest_path` or an account's `template` the server refuses (the reason in `error`) | +| `invalid_dest_path` | `400` | an Audible title's `dest_path` the server refuses (what is wrong in `error`); a disc folder the scan would join into another book also carries a `reason`, on a title's or account's edit, the Bridge's library change or a `book` folder override: [Audible disc destinations](reference.md#audible-disc-destinations); a [backup](reference.md#post-apiv1adminaudibletitlesaccountasinbackup) of a title whose saved destination no longer validates carries `reason: "title"` | +| `invalid_template` | `400` | an account's `template` the server refuses (what is wrong in `error`); a backup or Back up everything with a saved template that no longer validates carries `reason: "account"` | | `unknown_user` | `404` | the Bridge's `PUT /bridge/audible/accounts/{account}` naming no user, or one an account may not be mapped to (a kid household member, a demo or a disabled account) | | `unknown_library` | `404` | the Bridge's `PUT /bridge/audible/accounts/{account}` or `GET /bridge/libraries/{id}/books` naming no library | | `not_books` | `400` | the same two routes naming a podcast library | diff --git a/docs-developers/server/api/reference.md b/docs-developers/server/api/reference.md index 80f65524..37eb9cd3 100644 --- a/docs-developers/server/api/reference.md +++ b/docs-developers/server/api/reference.md @@ -6150,9 +6150,9 @@ and left ticked. An id that isn't one of this person's members, or one `keep_members` also names, is `400 invalid_delete_members` and nothing is deleted. -Deleting a person, or an owner's member with them, also cancels the open -Audible jobs (polls, backups and syncs) of the accounts mapped to them (from -2.7.0). +The server cancels open Audible polls, syncs and backups only for accounts removed +with the person or their deleted household members. Members kept as independent +accounts keep their jobs. The checks answer in this order: an id that isn't a number, then a malformed `keep_members` (`400 invalid_keep_members`) or `delete_members` (`400 @@ -6589,6 +6589,11 @@ state onto it (see [Joined books](../scanner.md#joined-books-disc-sets)); on any other folder without audio it changes nothing. Clearing it splits the discs out again. +`"book"` is refused, and nothing saved, while an Audible title's destination, an +account's template or an open backup in this library places audio in a disc +folder directly under `path`: `400 invalid_dest_path` with `reason: +"book_override"` ([Audible disc destinations](#audible-disc-destinations)). + Response `200`: `{ "status": "override set", "path": "…", "mode": "collection" }`. `400` for any other mode or a path over 4096 bytes (`path is too long`, before the library is looked up); `404` library not found. @@ -12258,6 +12263,40 @@ Two sets of routes, as for [the Bridge](#the-bridge): An account id is the Bridge's own, `^[a-z0-9]{8,32}$`. On every route that names one, an id that doesn't match is `404 unknown_account`. +### Audible disc destinations + +When a destination names a disc folder such as `Shelf/CD 2`, or a file inside it, +the server checks its parent (`Shelf`) in the target library, since the scan +would join the disc into that book and the done fold would refuse it only after +the whole download. It checks on a title's `dest_path` +([PATCH](#patch-apiv1adminaudibletitlesaccountasin)), an account's `template` +([PATCH](#patch-apiv1adminaudibleaccountsaccount)), the Bridge's library change +([PUT](#put-apiv1bridgeaudibleaccountsaccount)) and a `book` +[folder override](#put-apiv1adminlibrariesidfolder-override). A conflict is +`400` with `code: "invalid_dest_path"`, a message in `error` and a `reason`. + +| `reason` | Condition | +|---|---| +| `book_override` | The parent has a `book` override, or setting one would join a disc used by an Audible destination. This reason takes precedence when the parent is also an indexed book. | +| `indexed_book` | The parent is already indexed as a book and has no `book` override. | + +The `reason` field is additive. Clients that read only `code` still receive +`invalid_dest_path`. An invalid path such as `../Book` gets that code without +a `reason` on a title edit. + +For templates, the server checks a disc folder it can identify before the Bridge +substitutes title data. For example, `Shelf/CD 2/` and `Shelf/CD 2/{Title}.m4b` +both use a disc directly under `Shelf`. When the parent depends on title data, +the server checks the actual book and files in the +[finished backup](../../bridge/audible.md#on-the-server-the-done-fold). + +An open backup keeps the library and placement it was queued with, whatever +later edits to the title or account say. So the folder override also counts the +open backups' placements: a backup that is queued, running or parked +(`needs_attention`) holds it until the job ends (`done`, `failed` or `cancelled`). +Cancelling a running backup only asks the Bridge to stop, so the hold lasts until +the Bridge reports. + ### The account object ```json @@ -12336,10 +12375,15 @@ the server can't tell a fresh sign-in from an edit of the label, and the sync's places are the account's either way. Every PUT clears [`refused_at`](#the-account-object). +When `library_id` changes, the server checks the saved template and title +destinations in the proposed library before saving the mapping. It checks saved +destinations only for unmatched titles and titles marked **Not this book**. +This also applies when a paused account gets a new library. + | Status | Meaning | |---|---| | `200` | `{ "account": Account }` (without `titles`) | -| `400` | `invalid_request` (the JSON); `invalid_policy`; `invalid_marketplace`; `not_books` - the library is a podcast library | +| `400` | `invalid_request` (the JSON); `invalid_policy`; `invalid_marketplace`; `not_books` - the library is a podcast library; `invalid_dest_path` with a [disc `reason`](#audible-disc-destinations) | | `404` | `unknown_account` - an id the Bridge couldn't have made; `unknown_user` - no such user, or one an account may not be mapped to (above); `unknown_library` | ### `DELETE /api/v1/bridge/audible/accounts/{account}` @@ -12604,7 +12648,7 @@ answer. The backup job itself can still be `done`. |---|---| | `invalid_result` | The server could not read the backup result, or it named the wrong library or lacked a usable book path. | | `not_indexed` | The server found no indexed book at that path in the backup's books library. | -| `not_own_book` | The indexed book's ASIN did not match the title's, and the server could not verify that the book contained only files placed by this backup. | +| `not_own_book` | The server could not verify that this backup placed every indexed file in the book. It requires that check when the ASIN differs or when the scan joined the backed-up disc into its parent book, even if the ASIN matches. | | `rejected_match` | The book at that path was marked **Not this book** for this title. | The server clears both fields when it queues the title's next backup or @@ -12645,7 +12689,10 @@ now on a poll still queued gives it the account's current template. It is quiet (no notifications) and held while the module is off. The module's scheduler queues each due account's poll every `poll_hours` at priority `-10` while an online Bridge offers the kind. Only the newest ended poll of each -account is kept. +account is kept ([Job history](../../bridge/pairing-and-jobs.md#job-history)). +At start and every minute while the module is on, Bridge online or not, the +scheduler also cancels the open polls, syncs and backups of accounts that are +gone. ### `POST /api/v1/admin/audible/titles/{account}/{asin}/backup` @@ -12660,6 +12707,7 @@ by the first poll that reports the title available. |---|---| | `202` | `{ "pending": false, "job_id": N }`: queued (or the title's open backup, when a request at the same moment queued it first) | | `200` | `{ "pending": true, "job_id": null }`: a preorder, backed up on release | +| `400` | `invalid_dest_path` with reason `title` - the title's saved destination no longer validates; `invalid_template` with reason `account` - the account's saved template no longer does | | `404` | `unknown_account`; `unknown_title` (also an `{asin}` that isn't an ASIN); `module_off` | | `409` | `already_matched` - the title is on this server (matched, not marked "Not this book"); `import_open` - its backup is waiting, running or parked, or a preorder request is pending; `not_available` - the title is `unavailable` or `gone`; `account_paused`; `kind_unavailable` - no Bridge has reported, or the paired one doesn't run `audible.import`; `library_not_writable` - the Bridge can't write to the account's library | @@ -12707,10 +12755,10 @@ out is left as it is: account's placement: a file path, or a folder (a last segment without an audio extension) the title's file goes in. At most 1024 bytes, clean (no `..`, no leading or trailing `/`, no `.` segment), no hidden, dot-led segment, no - backslash or control character. From 2.7.0 it is refused (`invalid_dest_path`) - when it is a disc folder (`CD 3`) directly inside an indexed book or a folder - with a `book` override, which the scan would join into that book. It is copied - into a backup when it is queued; the Bridge checks it again against its + backslash or control character, and not a + [disc folder another book would join](#audible-disc-destinations) in the + account's library (clearing it checks the account's template instead). It is + copied into a backup when it is queued; the Bridge checks it again against its mapping. - `no_sync` `true` keeps the title's book out of the account's [position sync](#audible-position-sync), both ways; `false` lets it sync again. @@ -12723,7 +12771,7 @@ logged and the next scheduled sync carries the change. | Status | Meaning | |---|---| | `200` | the [title](#get-apiv1adminaudibletitles) (not wrapped) | -| `400` | `invalid_request` - the JSON (an unknown field too); `invalid_dest_path` - with what is wrong in `error` | +| `400` | `invalid_request` - the JSON (an unknown field too); `invalid_dest_path` - with what is wrong in `error`, and a [disc `reason`](#audible-disc-destinations) for a disc folder | | `404` | `unknown_account`; `unknown_title`; `module_off` | Audited as **`bridge.audible.title`** (with `account`, `asin`, and `rejected`, @@ -12745,7 +12793,9 @@ it is: - `template`: the placement template, `""` for the Bridge's placement beside the series' other books. At most 500 bytes, in the Bridge's [template grammar](../../bridge/audible.md#the-template-grammar) (its variables, - mods and the segment rules the server checks). + mods and the segment rules the server checks), and not a + [disc folder another book would join](#audible-disc-destinations) in the + account's library. - `sync`: `true` turns the account's [position sync](#audible-position-sync) on and queues its first `audible.sync` at once (when an online Bridge offers the kind); `false` turns it off and cancels its open sync ("sync with Audible was @@ -12757,7 +12807,7 @@ The account's person and library stay the Bridge's. | Status | Meaning | |---|---| | `200` | `{ "account": Account }` (without `titles` and `backup_estimate`) | -| `400` | `invalid_request` - the JSON (an unknown field too); `invalid_policy`; `invalid_template` - with what is wrong in `error` | +| `400` | `invalid_request` - the JSON (an unknown field too); `invalid_policy`; `invalid_template` - with what is wrong in `error`; `invalid_dest_path` with a [disc `reason`](#audible-disc-destinations) | | `404` | `unknown_account`; `module_off` | Audited as `bridge.audible.account` (with `account`, and `policy`, `template` and diff --git a/docs-users/admin/audible.md b/docs-users/admin/audible.md index 5a16c4a8..891fe769 100644 --- a/docs-users/admin/audible.md +++ b/docs-users/admin/audible.md @@ -56,9 +56,15 @@ paired, the card still lists the accounts this server keeps, with **Remove...**. ![The Account settings dialog](/img/screenshots/admin/audible-backup-settings.png) -You change who an account is for, and its library, on the Bridge's Accounts -tab. You set what it backs up, where, and whether it syncs here, in **Account -settings...**. +Use **Account settings...** to choose what the account backs up, where, and +whether it syncs here. To change the person or library, use **Change** on the +Bridge's **Accounts** tab. + +When you choose a different library, AudioSilo checks the account's template and +the saved destinations of its titles that aren't on this server, or that you +marked **Not this book**. If one puts a backup in a +[disc folder that would join another book](#choosing-a-destination), choose a +separate folder for it, then change the library again. An account marked **Paused** lost its library. Choose another library for it on the Bridge's Accounts tab. @@ -197,10 +203,28 @@ Type a path inside the library: - **a file**, such as `Author/Series/Title.m4b` (`.m4b`, `.m4a` or `.mp4`), or - **a folder**, such as `Author/Series/Book 3`. -Leave it empty for the usual place. The path can't start with a dot or contain -`..`. It can't be a disc folder, such as `CD 3`, inside a book already on the -server, because the backup would join that book. A title whose saved destination -is no longer valid appears in **Needs a look**. +Leave it empty to use the account's usual place. The path can't start with a +dot or contain `..`. A title whose saved destination is no longer valid appears +in **Needs a look**. + +A disc folder such as `Author/Book/CD 3`, or a file inside it, is refused when +the scan would join it into `Author/Book`: + +- `Author/Book` is already a book in the library, or +- `Author/Book` is set to **Always one book** in + [folder detection](libraries.md#folder-detection). + +Choose a separate folder for the backup instead, such as `Author/New Title`. + +Clearing a destination is refused in the same way while the account's template +names such a disc folder. + +A backup that is waiting, running or needs attention keeps the destination it +was queued with, even if you edit it here. So **Always one book** on +`Author/Book` is refused until no destination or template points at a disc there +and that backup has ended. **Cancel** in +[**Server > Settings > Bridge > Jobs**](bridge.md#jobs) ends a waiting backup at +once. A running one ends when the Bridge stops it. ![The Destination dialog for one title](/img/screenshots/admin/audible-destination.png) @@ -263,6 +287,9 @@ variable inside it is empty. A last part ending in `.m4b` names the file; otherw it is a folder. A title's own [destination](#choosing-a-destination) wins over the template. +A template that names a disc folder, such as `Author/Book/CD 3/{Title}.m4b`, +gets the same [disc folder check](#choosing-a-destination). + The Bridge keeps folder and file names safe for a network share (SMB) or a Windows disk. It drops `?`, `*`, `<` and `>`, turns `"` into `'` and `|` into `-`. So *Who Moved My Cheese?* is backed up as `Who Moved My Cheese`. A name Windows diff --git a/docs-users/admin/libraries.md b/docs-users/admin/libraries.md index 2cdcdda6..d6f58443 100644 --- a/docs-users/admin/libraries.md +++ b/docs-users/admin/libraries.md @@ -197,6 +197,10 @@ To fix that, click **⋯ > Folder detection...**, open the folder and choose: Your choice is saved at once and the library rescans. It survives rescans and even a full index rebuild. +**Always one book** is refused while an Audible backup is set to go into a disc +folder directly inside this folder (see +[Choosing a destination](audible.md#choosing-a-destination)). + ### The Folders page **Library > Folders** makes the same choice with more room. Pick a library and diff --git a/docs-users/admin/users-and-invites.md b/docs-users/admin/users-and-invites.md index 67fc73f6..f3ba8669 100644 --- a/docs-users/admin/users-and-invites.md +++ b/docs-users/admin/users-and-invites.md @@ -250,9 +250,9 @@ working, [disable the account](#disabling-vs-deleting). - **Disable account** - their devices stop working, but nothing is lost. **Enable** brings everything back. - **Delete account** - permanent. It removes their devices, invites, progress, - bookmarks, notes and history. Their [Audible accounts](audible.md) go too, and - any backup or check waiting for them is cancelled. Your audio files are not - touched. + bookmarks, notes and history. Their [Audible accounts](audible.md), and those + of household members deleted with them, go too, and any check, sync or backup + waiting for those accounts is cancelled. Your audio files are not touched. When in doubt, disable. diff --git a/docs-users/getting-started/bridge-accounts.md b/docs-users/getting-started/bridge-accounts.md index e74d4ca3..704c0bcd 100644 --- a/docs-users/getting-started/bridge-accounts.md +++ b/docs-users/getting-started/bridge-accounts.md @@ -130,8 +130,11 @@ holds the current **Back up** setting. The Bridge's card shows the value it last saw, as **Last known to the Bridge**. It catches up the next time you press **Change** and **Save** on the Bridge's card, or sign in to the account again. -Use **Change** to edit the person, library or name. Listening place sync starts -off. You can turn it on in the console. Changing the person turns it off again. +Use **Change** to edit the person, library or name. A new library is refused +while the account's template or a title's saved destination would put a backup +in a [disc folder that joins another book](../admin/audible.md#choosing-a-destination) +there. Listening place sync starts off. You can turn it on in the console. +Changing the person turns it off again. ### The account's states