Adds per-library consumption settings to the domain, storage, and API

This commit is contained in:
BinaryAlley committed 2026-10-24 10:20:00 +03:00
1 parent eaca69bf2a
commit b2d274f609
47 files changed
+4371 -11

No files matched your search

@@ -80,6 +80,16 @@ public class LibraryEntity : IStorageEntity, IAuditableEntity
/// </summary>
public bool ShouldSkipUnchangedDirectoriesDuringScan { get; init; }
/// <summary>
/// Gets a value indicating whether the consumption progress of the media library items is tracked.
/// </summary>
public bool ShouldTrackConsumptionProgress { get; init; }
/// <summary>
/// Gets the percentage of a media library item that must be consumed for its session to be considered completed, when progress tracking is enabled.
/// </summary>
public int? CompletionThresholdPercentage { get; init; }
/// <summary>
/// Gets or sets the fingerprint of the metadata provider configuration of the media library, used to detect
/// whether the configuration changed since the last scan, and thus whether the books need re-enrichment.
@@ -29,6 +29,8 @@ public static class AddMediaLibraryRequestMapping
request.CanDownloadMetadataFromWeb,
request.ShouldSaveMetadataInMediaDirectories,
request.ShouldSkipUnchangedDirectoriesDuringScan,
request.ShouldTrackConsumptionProgress,
request.CompletionThresholdPercentage,
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part.Kind, part.Representation, part.IsOptional)).ToArray()
);
}
@@ -36,6 +36,8 @@ public static class LibraryEntityMapping
repositoryEntity.CanDownloadMetadataFromWeb,
repositoryEntity.ShouldSaveMetadataInMediaDirectories,
repositoryEntity.ShouldSkipUnchangedDirectoriesDuringScan,
repositoryEntity.ShouldTrackConsumptionProgress,
repositoryEntity.CompletionThresholdPercentage,
[.. repositoryEntity.PathTemplateParts
.OrderBy(part => part.Position)
.Select(part => new LibraryPathTemplatePartResponse(part.Kind.ToString(), part.Representation, part.IsOptional))],
@@ -57,6 +59,10 @@ public static class LibraryEntityMapping
if (pathTemplateResult.IsFailure)
return pathTemplateResult.Errors;
LibraryConsumptionSettings consumptionSettings = LibraryConsumptionSettings.Create(
repositoryEntity.ShouldTrackConsumptionProgress,
Optional<int>.FromNullable(repositoryEntity.CompletionThresholdPercentage));
return Library.Create(
LibraryId.Create(repositoryEntity.Id),
UserId.Create(repositoryEntity.UserId),
@@ -69,6 +75,7 @@ public static class LibraryEntityMapping
repositoryEntity.CanDownloadMetadataFromWeb,
repositoryEntity.ShouldSaveMetadataInMediaDirectories,
repositoryEntity.ShouldSkipUnchangedDirectoriesDuringScan,
consumptionSettings,
pathTemplateResult.Value,
[.. repositoryEntity.LibraryScans.Select(libraryScan => ScanId.Create(libraryScan.Id))]
);
@@ -39,6 +39,10 @@ public static class LibraryMapping
CanDownloadMetadataFromWeb = domainEntity.CanDownloadMetadataFromWeb,
ShouldSaveMetadataInMediaDirectories = domainEntity.ShouldSaveMetadataInMediaDirectories,
ShouldSkipUnchangedDirectoriesDuringScan = domainEntity.ShouldSkipUnchangedDirectoriesDuringScan,
ShouldTrackConsumptionProgress = domainEntity.ConsumptionSettings.ShouldTrackConsumptionProgress,
CompletionThresholdPercentage = domainEntity.ConsumptionSettings.CompletionThresholdPercentage.HasValue
? domainEntity.ConsumptionSettings.CompletionThresholdPercentage.Value
: null,
LibraryScans = [.. domainEntity.ScanIds.Select(scanId => new LibraryScanEntity()
{
Id = scanId.Value,
@@ -31,6 +31,8 @@ public static class UpdateLibraryRequestMapping
request.CanDownloadMetadataFromWeb,
request.ShouldSaveMetadataInMediaDirectories,
request.ShouldSkipUnchangedDirectoriesDuringScan,
request.ShouldTrackConsumptionProgress,
request.CompletionThresholdPercentage,
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part.Kind, part.Representation, part.IsOptional)).ToArray()
);
}