mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 10:11:10 +00:00
Adds independent metadata and artwork enrichment
Splits the single combined enrichment phase of the media library scan into independent, modular jobs, so that the metadata and the artwork of a book are enriched separately and only when their respective triggers fire. - Adds the MediaContributorRoleCategory enum (Other first, then Author, Translator, Illustrator, Publisher and Narrator) and makes the role category canonical, so that roles describing the same kind of contribution are never treated as distinct. - Realizes the media contributor bounded context: a MediaContributor is a person, unique by display name, without a role. The role moves to the per-work participation (BookContributors), so that a single contributor can play multiple roles. Contributors are created and linked by the metadata enrichment job, and exposed to subsequent jobs. - Makes the Book aggregate pure: the enrichment tracking state (metadata status, providers, timestamps and covers) no longer lives on the domain aggregate, but stays in the Books table, managed directly by the jobs. - Models artwork generically as a BookArtwork child table (type, ordinal, content hash, status and provider), so that each piece of artwork is tracked independently and a change of one does not require the others to be re-fetched. - Splits the scan DAG into ResultsSave, ProviderConfigurationInvalidation, MetadataEnrichment and ArtworkEnrichment jobs. The invalidation job fingerprints the provider configuration of a library and resets the enrichment state of the affected channel when it changed. The artwork job resolves the missing artwork, hashing it to detect identical covers and skip re-copying. Content-changed books are reset by the results save job. - Deletes the book and its stored artwork when the file disappears from the library. - Adds the migration creating the new tables, backfilling the existing covers into the artwork table, and adding the configuration fingerprints. - Localizes the new scan job stages, and fixes the invalidation job wiping the library content locations by persisting the fingerprints through the change tracker instead of the repository update action.
This commit is contained in:
1 parent
4ee2976806
commit
565fe68239
98 files changed
+5845
-630
No files matched your search
+62
@@ -0,0 +1,62 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Entities.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Repository entity for the participation of a media contributor in a book, carrying the role the contributor
|
||||
/// played in that book. The role is tracked per participation, so that a single contributor can play multiple
|
||||
/// roles in the same book, or different roles in different books.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("BookId: {BookId} MediaContributorId: {MediaContributorId}")]
|
||||
public class BookContributorEntity : IStorageEntity, IAuditableEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the participation.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the book the contributor participated in.
|
||||
/// </summary>
|
||||
public required Guid BookId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the media contributor.
|
||||
/// </summary>
|
||||
public required Guid MediaContributorId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the display name of the role the contributor played in the book.
|
||||
/// </summary>
|
||||
public required string RoleName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the canonical category of the role the contributor played in the book.
|
||||
/// </summary>
|
||||
public required MediaContributorRoleCategory RoleCategory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
/// </summary>
|
||||
public DateTime? UpdatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+57
-8
@@ -1,16 +1,65 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Entities.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Repository entity for a media contributor.
|
||||
/// Repository entity for a media contributor, the person that contributed to one or more media items.
|
||||
/// The contributor is a person, unique by name, and agnostic of the kind of media it contributed to.
|
||||
/// </summary>
|
||||
/// <param name="Name">The name details of the media contributor, including display and legal names.</param>
|
||||
/// <param name="Role">The role details of the media contributor, including the role name and category.</param>
|
||||
[DebuggerDisplay("Name: {Name}, Role: {Role}")]
|
||||
public record MediaContributorEntity(
|
||||
MediaContributorNameEntity? Name,
|
||||
MediaContributorRoleEntity? Role
|
||||
);
|
||||
[DebuggerDisplay("DisplayName: {DisplayName}")]
|
||||
public class MediaContributorEntity : IStorageEntity, IAuditableEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the media contributor.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name by which the contributor is popularly known.
|
||||
/// </summary>
|
||||
public required string DisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the legal name of the contributor.
|
||||
/// </summary>
|
||||
public string? LegalName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the biography of the contributor.
|
||||
/// </summary>
|
||||
public string? Biography { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date of birth of the contributor.
|
||||
/// </summary>
|
||||
public DateOnly? DateOfBirth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date of death of the contributor.
|
||||
/// </summary>
|
||||
public DateOnly? DateOfDeath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
/// </summary>
|
||||
public DateTime? UpdatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Entities.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Repository entity for a media contributor name.
|
||||
/// </summary>
|
||||
/// <param name="DisplayName">The display name of the media contributor.</param>
|
||||
/// <param name="LegalName">The legal name of the media contributor.</param>
|
||||
[DebuggerDisplay("DisplayName: {DisplayName}")]
|
||||
public record MediaContributorNameEntity(
|
||||
string? DisplayName,
|
||||
string? LegalName
|
||||
);
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Entities.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Repository entity for a media contributor role.
|
||||
/// </summary>
|
||||
/// <param name="Name">The name of the role assigned to the media contributor.</param>
|
||||
/// <param name="Category">The category of the role.</param>
|
||||
[DebuggerDisplay("Name: {Name}, Category: {Category}")]
|
||||
public record MediaContributorRoleEntity(
|
||||
string? Name,
|
||||
string? Category
|
||||
);
|
||||
+13
-1
@@ -71,10 +71,22 @@ public class LibraryEntity : IStorageEntity, IAuditableEntity
|
||||
public bool ShouldSaveMetadataInMediaDirectories { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this media library should skip the directories whose contents have not changed since the last scan, during the scan.
|
||||
/// Gets or sets whether the unchanged directories are skipped during the scan of the media library.
|
||||
/// </summary>
|
||||
public bool ShouldSkipUnchangedDirectoriesDuringScan { 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.
|
||||
/// </summary>
|
||||
public string? MetadataProvidersConfigurationFingerprint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the fingerprint of the artwork provider configuration of the media library, used to detect
|
||||
/// whether the configuration changed since the last scan, and thus whether the books need their artwork re-resolved.
|
||||
/// </summary>
|
||||
public string? ArtworkProvidersConfigurationFingerprint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user that owns the media library.
|
||||
/// </summary>
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Repository entity for a piece of artwork of a book, like its cover.
|
||||
/// A book can have multiple pieces of artwork of different types, and multiple instances of the same type
|
||||
/// (like the booklet pages of an audio album), each tracked independently so that a change of one artwork
|
||||
/// does not require the others to be re-fetched.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("BookId: {BookId} Type: {ArtworkType} Ordinal: {Ordinal}")]
|
||||
public class BookArtworkEntity : IStorageEntity, IAuditableEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the artwork.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the book the artwork belongs to.
|
||||
/// </summary>
|
||||
public required Guid BookId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the artwork.
|
||||
/// </summary>
|
||||
public required ArtworkType ArtworkType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ordinal of the artwork within its type, so that multiple artworks of the same type can be ordered.
|
||||
/// </summary>
|
||||
public required int Ordinal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the relative file name of the stored artwork, if the artwork has been resolved.
|
||||
/// </summary>
|
||||
public string? FileName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the content hash of the stored artwork, used to detect whether a re-resolved artwork differs from the stored one.
|
||||
/// </summary>
|
||||
public ulong ContentHash { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status of the artwork enrichment.
|
||||
/// </summary>
|
||||
public required ArtworkStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the plugin that resolved the artwork, if applicable.
|
||||
/// </summary>
|
||||
public string? Provider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the artwork was last resolved, if applicable.
|
||||
/// </summary>
|
||||
public DateTime? LastUpdateUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
/// </summary>
|
||||
public DateTime? UpdatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+8
-7
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaContributors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -190,20 +191,20 @@ public class BookEntity : IStorageEntity, IAuditableEntity
|
||||
/// </summary>
|
||||
public string? AppleBooksId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the file system path of the cover image of the book, if applicable.
|
||||
/// </summary>
|
||||
public string? CoverImagePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ISBN (International Standard Book Number) of the book.
|
||||
/// </summary>
|
||||
public List<IsbnEntity> ISBNs { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of media contributors (actors, directors, etc) starring in this book.
|
||||
/// Gets or sets the participations of the media contributors in the book, each carrying the role the contributor played.
|
||||
/// </summary>
|
||||
//public List<ContributorIdModel> ContributorIds { get; set; } = [];
|
||||
public List<BookContributorEntity> BookContributors { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the pieces of artwork of the book, each tracked independently with its own enrichment state.
|
||||
/// </summary>
|
||||
public List<BookArtworkEntity> BookArtwork { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ratings for this book.
|
||||
|
||||
@@ -56,4 +56,68 @@ public interface IBookRepository : IRepository<BookEntity>,
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the number of books needing their metadata enriched, or an error.</returns>
|
||||
Task<Result<int>> GetBooksNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a page of the books of the media library identified by <paramref name="libraryId"/> that need their artwork resolved,
|
||||
/// meaning they lack at least one required piece of artwork with an enriched status, ordered by path, using keyset pagination.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose books are retrieved.</param>
|
||||
/// <param name="lastPath">The path of the last retrieved book, used for keyset pagination. Pass <see langword="null"/> to get the first page.</param>
|
||||
/// <param name="pageSize">The maximum number of books to retrieve.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a page of books needing their artwork resolved, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<BookEntity>>> GetBooksNeedingArtworkAsync(Guid libraryId, string? lastPath, int pageSize, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of books of the media library identified by <paramref name="libraryId"/> that need their artwork resolved.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose books are counted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the number of books needing their artwork resolved, or an error.</returns>
|
||||
Task<Result<int>> GetBooksNeedingArtworkCountAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Resets the enrichment state of the books stored at the provided <paramref name="paths"/> in the media library identified by
|
||||
/// <paramref name="libraryId"/>, so that they are re-enriched, because their content changed since the last scan.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose books are reset.</param>
|
||||
/// <param name="paths">The file system paths of the books whose enrichment state is reset.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Updated>> ResetEnrichmentStateForPathsAsync(Guid libraryId, IReadOnlyCollection<string> paths, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Resets the metadata enrichment status of all the books of the media library identified by <paramref name="libraryId"/>,
|
||||
/// so that they are re-enriched, because the metadata provider configuration of the library changed.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose books are reset.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Updated>> ResetMetadataStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Resets the artwork status of all the artwork of the books of the media library identified by <paramref name="libraryId"/>,
|
||||
/// so that they are re-resolved, because the artwork provider configuration of the library changed.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose artwork is reset.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Updated>> ResetArtworkStatusForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display names of the author of the books identified by the provided <paramref name="bookIds"/>,
|
||||
/// keyed by the Id of the book, or <see langword="null"/> when a book has no author.
|
||||
/// </summary>
|
||||
/// <param name="bookIds">The unique identifiers of the books whose authors are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the display names of the authors of the books, keyed by book Id, or an error.</returns>
|
||||
Task<Result<IReadOnlyDictionary<Guid, string?>>> GetAuthorsDisplayNamesByBookIdsAsync(IReadOnlyCollection<Guid> bookIds, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the book identified by <paramref name="bookId"/>.
|
||||
/// </summary>
|
||||
/// <param name="bookId">The Id of the book to delete.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Deleted>> DeleteAsync(Guid bookId, CancellationToken cancellationToken);
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaContributors;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the repository for media contributors.
|
||||
/// </summary>
|
||||
public interface IMediaContributorRepository : IRepository<MediaContributorEntity>,
|
||||
IInsertRepositoryAction<MediaContributorEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the media contributor whose display name matches the provided <paramref name="displayName"/>, or creates and inserts a new one
|
||||
/// when no contributor with that name exists yet, guaranteeing a single contributor per person.
|
||||
/// </summary>
|
||||
/// <param name="displayName">The name by which the contributor is popularly known.</param>
|
||||
/// <param name="legalName">The optional legal name of the contributor.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the existing or newly created <see cref="MediaContributorEntity"/>, or an error.</returns>
|
||||
Task<Result<MediaContributorEntity>> FindOrCreateByDisplayNameAsync(string displayName, string? legalName, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media contributors identified by the provided <paramref name="ids"/>.
|
||||
/// </summary>
|
||||
/// <param name="ids">The unique identifiers of the media contributors to retrieve.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the retrieved <see cref="MediaContributorEntity"/>s, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<MediaContributorEntity>>> GetByIdsAsync(IReadOnlyCollection<Guid> ids, CancellationToken cancellationToken);
|
||||
}
|
||||
+9
@@ -46,6 +46,15 @@ public interface ILibraryScanStagingResultsRepository : IRepository<LibraryScanS
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a page of staging results that need hashing, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<HashedFileSystemFileDto>>> GetFilesToHashPageAsync(Guid scanId, string? lastPath, int pageSize, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the paths of the media library scan staging results of the current scan that changed, meaning their content needs to be re-hashed
|
||||
/// and the books stored at those paths need to be re-enriched, excluding the staging results that are new.
|
||||
/// </summary>
|
||||
/// <param name="scanId">The unique identifier of the media library scan whose staging results are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the paths of the changed staging results, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<string>>> GetChangedPathsAsync(Guid scanId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the content hashes of the provided media library scan staging results.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaContributors;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Themes;
|
||||
@@ -41,6 +42,11 @@ public interface IUnitOfWork
|
||||
/// </summary>
|
||||
IBookRepository BookRepository { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media contributor repository.
|
||||
/// </summary>
|
||||
IMediaContributorRepository MediaContributorRepository { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the directory scan fingerprint repository.
|
||||
/// </summary>
|
||||
|
||||
@@ -21,4 +21,11 @@ public interface IFileHashService
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>A collection of the hashed files, along with their hashes.</returns>
|
||||
Task<List<HashedFileSystemFileDto>> HashFilesAsync(IReadOnlyCollection<HashedFileSystemFileDto> files, Func<Task> callback, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Computes the content hash of the file stored at <paramref name="filePath"/>, by sampling chunks from it.
|
||||
/// </summary>
|
||||
/// <param name="filePath">The path of the file to hash.</param>
|
||||
/// <returns>The content hash of the file.</returns>
|
||||
ulong ComputeFileHash(string filePath);
|
||||
}
|
||||
+5
-6
@@ -10,11 +10,13 @@ using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -131,14 +133,11 @@ public static class BookEntityMapping
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
Optional<DateTime>.FromNullable(repositoryEntity.UpdatedOnUtc),
|
||||
[.. isbnsResult.Select(isbn => isbn.Value)],
|
||||
[],
|
||||
[.. repositoryEntity.BookContributors.Select(bookContributor => MediaContributorId.Create(bookContributor.MediaContributorId))],
|
||||
[.. bookRatingsResult.Select(bookRating => bookRating.Value)]);
|
||||
if (bookResult.IsFailure)
|
||||
return bookResult.Errors;
|
||||
|
||||
if (repositoryEntity.CoverImagePath is not null)
|
||||
bookResult.Value.SetBookCoverImagePath(repositoryEntity.CoverImagePath);
|
||||
|
||||
return bookResult;
|
||||
}
|
||||
|
||||
@@ -225,7 +224,7 @@ public static class BookEntityMapping
|
||||
repositoryEntity.MetadataProvider,
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
repositoryEntity.UpdatedOnUtc,
|
||||
repositoryEntity.CoverImagePath
|
||||
repositoryEntity.BookArtwork.FirstOrDefault(artwork => artwork.ArtworkType == ArtworkType.Cover)?.FileName
|
||||
);
|
||||
}
|
||||
|
||||
@@ -267,7 +266,7 @@ public static class BookEntityMapping
|
||||
repositoryEntity.Id,
|
||||
repositoryEntity.Title,
|
||||
repositoryEntity.ReReleaseYear ?? repositoryEntity.OriginalReleaseYear,
|
||||
repositoryEntity.CoverImagePath
|
||||
repositoryEntity.BookArtwork.FirstOrDefault(artwork => artwork.ArtworkType == ArtworkType.Cover)?.FileName
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+41
-4
@@ -56,16 +56,53 @@ public static class BookMapping
|
||||
GoogleBooksId = domainEntity.GoogleBooksId.HasValue ? domainEntity.GoogleBooksId.Value : null,
|
||||
BarnesAndNobleId = domainEntity.BarnesAndNobleId.HasValue ? domainEntity.BarnesAndNobleId.Value : null,
|
||||
AppleBooksId = domainEntity.AppleBooksId.HasValue ? domainEntity.AppleBooksId.Value : null,
|
||||
CoverImagePath = domainEntity.CoverImagePath.HasValue ? domainEntity.CoverImagePath.Value : null,
|
||||
ISBNs = [.. domainEntity.ISBNs.ToRepositoryEntities()],
|
||||
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()],
|
||||
MetadataStatus = domainEntity.MetadataStatus,
|
||||
LastMetadataUpdateUtc = domainEntity.LastMetadataUpdateUtc.HasValue ? domainEntity.LastMetadataUpdateUtc.Value : null,
|
||||
MetadataProvider = domainEntity.MetadataProvider.HasValue ? domainEntity.MetadataProvider.Value : null,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc : null,
|
||||
UpdatedBy = domainEntity.UpdatedOnUtc.HasValue ? Guid.NewGuid() : null,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the metadata fields of <paramref name="domainEntity"/> onto the existing <paramref name="entity"/>,
|
||||
/// without touching the enrichment tracking columns, which are managed directly by the enrichment jobs.
|
||||
/// </summary>
|
||||
/// <param name="entity">The repository entity onto which the metadata is applied.</param>
|
||||
/// <param name="domainEntity">The domain entity whose metadata is applied.</param>
|
||||
public static void ApplyMetadataToEntity(this BookEntity entity, Book domainEntity)
|
||||
{
|
||||
entity.Title = domainEntity.Metadata.Title;
|
||||
entity.OriginalTitle = domainEntity.Metadata.OriginalTitle.HasValue ? domainEntity.Metadata.OriginalTitle.Value : null;
|
||||
entity.Description = domainEntity.Metadata.Description.HasValue ? domainEntity.Metadata.Description.Value : null;
|
||||
entity.OriginalReleaseDate = domainEntity.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue ? domainEntity.Metadata.ReleaseInfo.OriginalReleaseDate.Value : null;
|
||||
entity.OriginalReleaseYear = domainEntity.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue ? domainEntity.Metadata.ReleaseInfo.OriginalReleaseYear.Value : null;
|
||||
entity.ReReleaseDate = domainEntity.Metadata.ReleaseInfo.ReReleaseDate.HasValue ? domainEntity.Metadata.ReleaseInfo.ReReleaseDate.Value : null;
|
||||
entity.ReReleaseYear = domainEntity.Metadata.ReleaseInfo.ReReleaseYear.HasValue ? domainEntity.Metadata.ReleaseInfo.ReReleaseYear.Value : null;
|
||||
entity.ReleaseCountry = domainEntity.Metadata.ReleaseInfo.ReleaseCountry.HasValue ? domainEntity.Metadata.ReleaseInfo.ReleaseCountry.Value : null;
|
||||
entity.ReleaseVersion = domainEntity.Metadata.ReleaseInfo.ReleaseVersion.HasValue ? domainEntity.Metadata.ReleaseInfo.ReleaseVersion.Value : null;
|
||||
entity.LanguageCode = domainEntity.Metadata.Language.HasValue ? domainEntity.Metadata.Language.Value.LanguageCode : null;
|
||||
entity.LanguageName = domainEntity.Metadata.Language.HasValue ? domainEntity.Metadata.Language.Value.LanguageName : null;
|
||||
entity.LanguageNativeName = domainEntity.Metadata.Language.HasValue ? domainEntity.Metadata.Language.Value.NativeName.Value : null;
|
||||
entity.OriginalLanguageCode = domainEntity.Metadata.OriginalLanguage.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.LanguageCode : null;
|
||||
entity.OriginalLanguageName = domainEntity.Metadata.OriginalLanguage.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.LanguageName : null;
|
||||
entity.OriginalLanguageNativeName = domainEntity.Metadata.OriginalLanguage.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.NativeName.Value : null;
|
||||
entity.Publisher = domainEntity.Metadata.Publisher.HasValue ? domainEntity.Metadata.Publisher.Value : null;
|
||||
entity.PageCount = domainEntity.Metadata.PageCount.HasValue ? domainEntity.Metadata.PageCount.Value : null;
|
||||
entity.Format = domainEntity.Format.HasValue ? domainEntity.Format.Value : null;
|
||||
entity.Edition = domainEntity.Edition.HasValue ? domainEntity.Edition.Value : null;
|
||||
entity.VolumeNumber = domainEntity.VolumeNumber.HasValue ? domainEntity.VolumeNumber.Value : null;
|
||||
entity.ASIN = domainEntity.ASIN.HasValue ? domainEntity.ASIN.Value : null;
|
||||
entity.GoodreadsId = domainEntity.GoodreadsId.HasValue ? domainEntity.GoodreadsId.Value : null;
|
||||
entity.LCCN = domainEntity.LCCN.HasValue ? domainEntity.LCCN.Value : null;
|
||||
entity.OCLCNumber = domainEntity.OCLCNumber.HasValue ? domainEntity.OCLCNumber.Value : null;
|
||||
entity.OpenLibraryId = domainEntity.OpenLibraryId.HasValue ? domainEntity.OpenLibraryId.Value : null;
|
||||
entity.LibraryThingId = domainEntity.LibraryThingId.HasValue ? domainEntity.LibraryThingId.Value : null;
|
||||
entity.GoogleBooksId = domainEntity.GoogleBooksId.HasValue ? domainEntity.GoogleBooksId.Value : null;
|
||||
entity.BarnesAndNobleId = domainEntity.BarnesAndNobleId.HasValue ? domainEntity.BarnesAndNobleId.Value : null;
|
||||
entity.AppleBooksId = domainEntity.AppleBooksId.HasValue ? domainEntity.AppleBooksId.Value : null;
|
||||
entity.UpdatedOnUtc = DateTime.UtcNow;
|
||||
entity.UpdatedBy = Guid.NewGuid();
|
||||
}
|
||||
}
|
||||
+3
-10
@@ -19,14 +19,12 @@ namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.B
|
||||
public static class BookMetadataDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies the metadata of <paramref name="metadata"/> to <paramref name="book"/>, marking its metadata as enriched by the provided <paramref name="providerName"/>.
|
||||
/// Applies the metadata of <paramref name="metadata"/> to <paramref name="book"/>.
|
||||
/// </summary>
|
||||
/// <param name="book">The domain book to which the metadata is applied.</param>
|
||||
/// <param name="metadata">The metadata to be applied.</param>
|
||||
/// <param name="providerName">The name of the metadata provider that enriched the book.</param>
|
||||
/// <param name="lastUpdateUtc">The date and time when the metadata was enriched.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public static Result<Success> ApplyMetadata(this Book book, BookMetadataDto metadata, string providerName, DateTime lastUpdateUtc)
|
||||
public static Result<Success> ApplyMetadata(this Book book, BookMetadataDto metadata)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(metadata.Title))
|
||||
return Domain.Common.Errors.Errors.Metadata.TitleCannotBeEmpty;
|
||||
@@ -126,14 +124,9 @@ public static class BookMetadataDtoMapping
|
||||
Optional<string>.FromNullable(metadata.BarnesAndNobleId),
|
||||
Optional<string>.FromNullable(metadata.AppleBooksId),
|
||||
[.. domainIsbnsResult.Select(isbnResult => isbnResult.Value)],
|
||||
[.. domainRatingsResult.Select(ratingResult => ratingResult.Value)],
|
||||
providerName,
|
||||
lastUpdateUtc
|
||||
[.. domainRatingsResult.Select(ratingResult => ratingResult.Value)]
|
||||
);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(metadata.CoverImagePath))
|
||||
book.SetBookCoverImagePath(metadata.CoverImagePath);
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Artwork;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Exceptions;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the domain event raised when a media library item is no longer present in the media library scan snapshot.
|
||||
/// The book stored at the deleted path is removed, together with its stored artwork.
|
||||
/// </summary>
|
||||
public class LibraryMediaItemDeletedDomainEventHandler : IDomainEventHandler<LibraryMediaItemDeletedDomainEvent>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IBookArtworkService _bookArtworkService;
|
||||
private readonly ILogger<LibraryMediaItemDeletedDomainEventHandler> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryMediaItemDeletedDomainEventHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="bookArtworkService">Injected service for storing the artwork of the books.</param>
|
||||
/// <param name="logger">Injected logger used to report the issues encountered while deleting the media library item.</param>
|
||||
public LibraryMediaItemDeletedDomainEventHandler(IUnitOfWork unitOfWork, IBookArtworkService bookArtworkService, ILogger<LibraryMediaItemDeletedDomainEventHandler> logger)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_bookArtworkService = bookArtworkService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the event raised when a media library item is no longer present in the media library scan snapshot.
|
||||
/// </summary>
|
||||
/// <param name="domainEvent">The domain event to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public async ValueTask HandleAsync(LibraryMediaItemDeletedDomainEvent domainEvent, CancellationToken cancellationToken)
|
||||
{
|
||||
Guid libraryId = domainEvent.LibraryId.Value;
|
||||
|
||||
// load the book stored at the deleted path, which might have been already removed
|
||||
Result<BookEntity?> getBookResult = await _unitOfWork.BookRepository.GetByPathAsync(libraryId, domainEvent.Path, cancellationToken).ConfigureAwait(false);
|
||||
if (getBookResult.IsFailure)
|
||||
throw new EventualConsistencyException(getBookResult.FirstError, getBookResult.Errors);
|
||||
BookEntity? book = getBookResult.Value;
|
||||
if (book is null)
|
||||
return;
|
||||
|
||||
// delete the stored artwork of the book, best-effort, since a stale cover must not prevent the book from being removed
|
||||
Result<LibraryEntity?> getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(libraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryResult.IsFailure || getLibraryResult.Value is null)
|
||||
throw new EventualConsistencyException(getLibraryResult.FirstError, getLibraryResult.Errors);
|
||||
LibraryEntity library = getLibraryResult.Value;
|
||||
|
||||
Result<IReadOnlyDictionary<Guid, string?>> getAuthorsResult = await _unitOfWork.BookRepository.GetAuthorsDisplayNamesByBookIdsAsync([book.Id], cancellationToken).ConfigureAwait(false);
|
||||
if (getAuthorsResult.IsFailure)
|
||||
throw new EventualConsistencyException(getAuthorsResult.FirstError, getAuthorsResult.Errors);
|
||||
string authorName = getAuthorsResult.Value.TryGetValue(book.Id, out string? authorDisplayName) && authorDisplayName is not null ? authorDisplayName : string.Empty;
|
||||
|
||||
Result<Deleted> deleteArtworkResult = _bookArtworkService.DeleteBookArtwork(libraryId, book.Id, library.Title, authorName, book.Title);
|
||||
if (deleteArtworkResult.IsFailure)
|
||||
_logger.LogWarning("Failed to delete the stored artwork of the book with Id '{BookId}' at path '{BookPath}', the artwork might remain orphaned.", book.Id, book.Path);
|
||||
|
||||
// delete the book, whose stored artwork and participations are removed by the database cascade
|
||||
Result<Deleted> deleteBookResult = await _unitOfWork.BookRepository.DeleteAsync(book.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteBookResult.IsFailure)
|
||||
throw new EventualConsistencyException(deleteBookResult.FirstError, deleteBookResult.Errors);
|
||||
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -326,9 +326,7 @@ public class AddBookCommandValidator : AbstractValidator<AddBookCommand>
|
||||
.WithError(Errors.MediaContributor.RoleNameMustBeMaximum50CharactersLong);
|
||||
role.RuleFor(r => r!.Category)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.MediaContributor.RoleCategoryCannotBeEmpty)
|
||||
.MaximumLength(50)
|
||||
.WithError(Errors.MediaContributor.RoleCategoryMustBeMaximum50CharactersLong);
|
||||
.WithError(Errors.MediaContributor.RoleCategoryCannotBeEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user