feat(limit): add opt-in daily download limit core, history store and enforcement

Records every successful audiobook download in the library database (a new
DownloadHistory table) and, when the user opts in, stops downloading once the
rolling 24 hour window is full.

The history lives in the database rather than a file under LibationFiles
because in Docker only the database is on a volume; a file there is discarded
on every container restart.

The limit is checked immediately before each book downloads, never at queueing
time, so a full queue stays full and the user can raise or disable the limit
mid-run. When nothing in the queue can proceed the queue pauses and re-checks
every 15 seconds, recomputing settings, history and clock from scratch, so a
queue left running for days drip-feeds itself as downloads age out. The CLI
never waits: it skips covered titles and reports a count.

Co-authored-by: rmcrackan <rmcrackan@gmail.com>
This commit is contained in:
Cursor Agent
2026-08-14 17:16:47 +00:00
parent 85191d2984
commit 818510d1b0
26 changed files with 2002 additions and 28 deletions

View File

@@ -63,7 +63,19 @@ public class ProcessBookViewModel : ReactiveObject
public bool IsDownloading => Status is ProcessBookStatus.Working;
public bool Queued => Status is ProcessBookStatus.Queued;
public string StatusText => (Result, LibraryBook.IsAudiblePlus) switch
/// <summary>
/// Transient status shown instead of the usual text, e.g. while the queue waits on the daily download limit.
/// Null when the book's own state should speak for itself.
/// </summary>
public string? StatusOverride { get => field; set { RaiseAndSetIfChanged(ref field, value); RaisePropertyChanged(nameof(StatusText)); } }
/// <summary>
/// True when this queue item downloads an audiobook, so the daily download limit applies to it.
/// PDF-only and mp3-conversion items are never limited.
/// </summary>
public bool IncludesBookDownload { get; private set; }
public string StatusText => StatusOverride ?? (Result, LibraryBook.IsAudiblePlus) switch
{
(ProcessBookResult.Success, _) => "Finished",
(ProcessBookResult.Cancelled, _) => "Cancelled",
@@ -267,7 +279,11 @@ public class ProcessBookViewModel : ReactiveObject
}
public ProcessBookViewModel AddDownloadPdf() => AddProcessable<DownloadPdf>();
public ProcessBookViewModel AddDownloadDecryptBook() => AddProcessable<DownloadDecryptBook>();
public ProcessBookViewModel AddDownloadDecryptBook()
{
IncludesBookDownload = true;
return AddProcessable<DownloadDecryptBook>();
}
public ProcessBookViewModel AddConvertToMp3() => AddProcessable<ConvertToMp3>();
public ProcessBookViewModel AddUploadToAudiobookshelf() => AddProcessable<UploadToAudiobookshelf>();
public ProcessBookViewModel AddSimulateBadBookFailure() => AddProcessable<SimulateBadBookFailure>();