From ca4f308b0af2bd9539cdb45149c614b724c9abe1 Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Mon, 5 Oct 2026 18:42:00 +0300 Subject: [PATCH] Adds dynamic path templates for media libraries, so that the scanner can derive the meaning of each path part --- .../api/library/management/Api.Libraries.md | 68 +- .../library/management/AddLibrary.http | 8 +- .../GetLibraryPathTemplateParts.http | 2 + .../library/management/UpdateLibrary.http | 8 +- .../Management/LibraryPathTemplatePartDto.cs | 13 + .../MediaLibrary/Management/LibraryEntity.cs | 11 + .../LibraryPathTemplatePartEntity.cs | 33 + .../AddMediaLibraryRequestMapping.cs | 5 +- ...tLibraryPathTemplatePartsRequestMapping.cs | 24 + .../Management/LibraryEntityMapping.cs | 28 + .../MediaLibrary/Management/LibraryMapping.cs | 7 + .../LibraryPathTemplatePartDtoMapping.cs | 44 + .../Management/UpdateLibraryRequestMapping.cs | 5 +- .../Commands/AddLibrary/AddLibraryCommand.cs | 5 +- .../AddLibrary/AddLibraryCommandHandler.cs | 24 +- .../AddLibrary/AddLibraryCommandValidator.cs | 12 + .../UpdateLibrary/UpdateLibraryCommand.cs | 5 +- .../UpdateLibraryCommandHandler.cs | 18 + .../UpdateLibraryCommandValidator.cs | 12 + .../GetLibraryPathTemplatePartsQuery.cs | 15 + ...GetLibraryPathTemplatePartsQueryHandler.cs | 72 + .../Management/AddLibraryRequest.cs | 4 +- .../GetLibraryPathTemplatePartsRequest.cs | 14 + .../LibraryPathTemplatePartRequest.cs | 18 + .../Management/UpdateLibraryRequest.cs | 4 +- .../LibraryPathPartDefinitionResponse.cs | 20 + .../LibraryPathTemplateCatalogResponse.cs | 17 + .../LibraryPathTemplatePartResponse.cs | 18 + .../Management/LibraryResponse.cs | 2 + .../Configuration/LibraryConfiguration.cs | 40 +- ...064333_AddsLibraryPathTemplate.Designer.cs | 3425 +++++++++++++++++ .../20261008064333_AddsLibraryPathTemplate.cs | 146 + .../LuminaDbContextModelSnapshot.cs | 966 ++++- .../Libraries/LibraryRepository.cs | 17 + .../Enums/MediaLibrary/LibraryPathPartKind.cs | 82 + .../MediaLibrary/LibraryPathValueType.cs | 32 + .../DomainLayerServices.cs | 6 + .../Common/Errors/Errors.Library.cs | 5 + .../MusicLibraryPathPartCatalog.cs | 69 + .../ValueObjects/MusicLibraryPathMetadata.cs | 121 + .../LibraryAggregate/Library.cs | 14 + .../ValueObjects/LibraryPathPart.cs | 91 + .../ValueObjects/LibraryPathTemplate.cs | 62 + .../PathTemplate/ILibraryPathPartCatalog.cs | 31 + .../ILibraryPathTemplateService.cs | 42 + .../LibraryPathTemplateService.cs | 197 + .../ValueObjects/LibraryPathPartDefinition.cs | 60 + .../ValueObjects/ParsedLibraryPath.cs | 89 + .../BookLibraryPathPartCatalog.cs | 66 + .../Library/Management/ApiRoutes.Libraries.cs | 1 + .../AddLibrary/AddLibraryEndpointSummary.cs | 6 +- .../GetEnabledLibrariesEndpointSummary.cs | 17 + .../GetLibrariesEndpointSummary.cs | 17 + .../GetLibrary/GetLibraryEndpointSummary.cs | 2 + .../GetLibraryPathTemplatePartsEndpoint.cs | 55 + .../UpdateLibraryEndpointSummary.cs | 6 +- .../Common/DTO/Libraries/LibraryDto.cs | 5 + .../Libraries/LibraryPathPartDefinitionDto.cs | 32 + .../LibraryPathTemplateCatalogDto.cs | 23 + .../Libraries/LibraryPathTemplatePartDto.cs | 27 + .../GetLibraryPathTemplatePartsRequest.cs | 14 + .../Common/Routes/ApiRoutes.Libraries.cs | 1 + .../Routes/WebRoutes.LibraryManagement.cs | 1 + .../GetLibraryPathTemplatePartsEndpoint.cs | 54 + .../Views/Library/Management/Item.ar-SA.resx | 65 +- .../Views/Library/Management/Item.de-DE.resx | 65 +- .../Views/Library/Management/Item.en-US.resx | 65 +- .../Views/Library/Management/Item.es-ES.resx | 67 +- .../Views/Library/Management/Item.fr-FR.resx | 65 +- .../Views/Library/Management/Item.it-IT.resx | 65 +- .../Views/Library/Management/Item.ja-JP.resx | 65 +- .../Views/Library/Management/Item.resx | 65 +- .../Views/Library/Management/Item.ro-RO.resx | 65 +- .../Views/Library/Management/Item.uk-UA.resx | 65 +- .../Views/Library/Management/Item.zh-CN.resx | 65 +- .../Core/Views/Library/Management/Item.cshtml | 439 ++- src/Lumina.sln | 1 + .../AddLibrary/AddLibraryCommandFixture.cs | 9 +- .../UpdateLibraryCommandFixture.cs | 9 +- .../Management/AddLibraryRequestFixture.cs | 7 +- .../Management/UpdateLibraryRequestFixture.cs | 7 +- .../Management/LibraryResponseFixture.cs | 3 + .../LibraryAggregate/LibraryFixture.cs | 5 + .../AddLibraryCommandHandlerTests.cs | 8 +- .../UpdateLibraryCommandHandlerTests.cs | 8 +- .../LibraryAggregate/LibraryTests.cs | 6 + 86 files changed, 7406 insertions(+), 151 deletions(-) create mode 100644 docs/technical/requests/library/management/GetLibraryPathTemplateParts.http create mode 100644 src/Lumina.Application/Common/DTO/MediaLibrary/Management/LibraryPathTemplatePartDto.cs create mode 100644 src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/Management/LibraryPathTemplatePartEntity.cs create mode 100644 src/Lumina.Application/Common/Mapping/MediaLibrary/Management/GetLibraryPathTemplatePartsRequestMapping.cs create mode 100644 src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryPathTemplatePartDtoMapping.cs create mode 100644 src/Lumina.Application/Core/MediaLibrary/Management/Queries/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsQuery.cs create mode 100644 src/Lumina.Application/Core/MediaLibrary/Management/Queries/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsQueryHandler.cs create mode 100644 src/Lumina.Contracts/Requests/MediaLibrary/Management/GetLibraryPathTemplatePartsRequest.cs create mode 100644 src/Lumina.Contracts/Requests/MediaLibrary/Management/LibraryPathTemplatePartRequest.cs create mode 100644 src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryPathPartDefinitionResponse.cs create mode 100644 src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryPathTemplateCatalogResponse.cs create mode 100644 src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryPathTemplatePartResponse.cs create mode 100644 src/Lumina.DataAccess/Common/Migrations/20261008064333_AddsLibraryPathTemplate.Designer.cs create mode 100644 src/Lumina.DataAccess/Common/Migrations/20261008064333_AddsLibraryPathTemplate.cs create mode 100644 src/Lumina.Domain.SharedKernel/Common/Enums/MediaLibrary/LibraryPathPartKind.cs create mode 100644 src/Lumina.Domain.SharedKernel/Common/Enums/MediaLibrary/LibraryPathValueType.cs create mode 100644 src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/Services/PathTemplate/MusicLibraryPathPartCatalog.cs create mode 100644 src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicLibraryPathMetadata.cs create mode 100644 src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/ValueObjects/LibraryPathPart.cs create mode 100644 src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/ValueObjects/LibraryPathTemplate.cs create mode 100644 src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/PathTemplate/ILibraryPathPartCatalog.cs create mode 100644 src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/PathTemplate/ILibraryPathTemplateService.cs create mode 100644 src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/PathTemplate/LibraryPathTemplateService.cs create mode 100644 src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/ValueObjects/LibraryPathPartDefinition.cs create mode 100644 src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/ValueObjects/ParsedLibraryPath.cs create mode 100644 src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/Services/PathTemplate/BookLibraryPathPartCatalog.cs create mode 100644 src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsEndpoint.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryPathPartDefinitionDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryPathTemplateCatalogDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryPathTemplatePartDto.cs create mode 100644 src/Lumina.Presentation.Web/Common/Requests/Library/Management/GetLibraryPathTemplatePartsRequest.cs create mode 100644 src/Lumina.Presentation.Web/Core/Endpoints/Library/Management/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsEndpoint.cs diff --git a/docs/technical/api/library/management/Api.Libraries.md b/docs/technical/api/library/management/Api.Libraries.md index 30a6eba7..4963627e 100644 --- a/docs/technical/api/library/management/Api.Libraries.md +++ b/docs/technical/api/library/management/Api.Libraries.md @@ -38,6 +38,9 @@ - [Cancel Library Scan](#cancel-library-scan) - [Cancel Library Scan Request](#cancel-library-scan-request) - [Cancel Library Scan Response](#cancel-library-scan-response) + - [Get Library Path Template Parts](#get-library-path-template-parts) + - [Get Library Path Template Parts Request](#get-library-path-template-parts-request) + - [Get Library Path Template Parts Response](#get-library-path-template-parts-response) ## Library @@ -59,9 +62,10 @@ POST api/v1/libraries "coverImage": null, "isEnabled": true, "isLocked": false, - "downloadMetadataFromWeb": true, + "canDownloadMetadataFromWeb": true, "shouldSaveMetadataInMediaDirectories": true, - "shouldSkipUnchangedDirectoriesDuringScan": true + "shouldSkipUnchangedDirectoriesDuringScan": true, + "pathTemplateParts": [] } ``` @@ -83,9 +87,10 @@ POST api/v1/libraries "coverImage": null, "isEnabled": true, "isLocked": false, - "downloadMetadataFromWeb": true, + "canDownloadMetadataFromWeb": true, "shouldSaveMetadataInMediaDirectories": true, "shouldSkipUnchangedDirectoriesDuringScan": true, + "pathTemplateParts": [], "createdOnUtc": "2025-01-01T12:00:00.0000000Z", "updatedOnUtc": null } @@ -118,9 +123,10 @@ GET api/v1/libraries "coverImage": null, "isEnabled": true, "isLocked": false, - "downloadMetadataFromWeb": true, + "canDownloadMetadataFromWeb": true, "shouldSaveMetadataInMediaDirectories": true, "shouldSkipUnchangedDirectoriesDuringScan": true, + "pathTemplateParts": [], "createdOnUtc": "2025-01-01T12:00:00.0000000Z", "updatedOnUtc": null } @@ -154,9 +160,10 @@ GET api/v1/libraries/enabled "coverImage": null, "isEnabled": true, "isLocked": false, - "downloadMetadataFromWeb": true, + "canDownloadMetadataFromWeb": true, "shouldSaveMetadataInMediaDirectories": true, "shouldSkipUnchangedDirectoriesDuringScan": true, + "pathTemplateParts": [], "createdOnUtc": "2025-01-01T12:00:00.0000000Z", "updatedOnUtc": null } @@ -189,9 +196,10 @@ GET api/v1/libraries/{id} "coverImage": null, "isEnabled": true, "isLocked": false, - "downloadMetadataFromWeb": true, + "canDownloadMetadataFromWeb": true, "shouldSaveMetadataInMediaDirectories": true, "shouldSkipUnchangedDirectoriesDuringScan": true, + "pathTemplateParts": [], "createdOnUtc": "2025-01-01T12:00:00.0000000Z", "updatedOnUtc": null } @@ -217,9 +225,10 @@ PUT api/v1/libraries/{id} "coverImage": null, "isEnabled": true, "isLocked": false, - "downloadMetadataFromWeb": true, + "canDownloadMetadataFromWeb": true, "shouldSaveMetadataInMediaDirectories": true, - "shouldSkipUnchangedDirectoriesDuringScan": true + "shouldSkipUnchangedDirectoriesDuringScan": true, + "pathTemplateParts": [] } ``` @@ -241,9 +250,10 @@ PUT api/v1/libraries/{id} "coverImage": null, "isEnabled": true, "isLocked": false, - "downloadMetadataFromWeb": true, + "canDownloadMetadataFromWeb": true, "shouldSaveMetadataInMediaDirectories": true, "shouldSkipUnchangedDirectoriesDuringScan": true, + "pathTemplateParts": [], "createdOnUtc": "2025-01-01T12:00:00.0000000Z", "updatedOnUtc": null } @@ -400,3 +410,43 @@ POST api/v1/libraries/{libraryId}/scans/{scanId}/cancel ```js 204 No Content ``` + +### Get Library Path Template Parts + +#### Get Library Path Template Parts Request + +```js +GET api/v1/libraries/path-template-parts/{libraryType} +``` + +#### Get Library Path Template Parts Response + +```js +200 Ok +``` + +```json +{ + "parts": [ + { + "kind": "Artist", + "valueType": "Text", + "defaultRepresentation": "{0}", + "isOptionalByDefault": false + }, + { + "kind": "DiscNumber", + "valueType": "Integer", + "defaultRepresentation": "{0:00}", + "isOptionalByDefault": true + } + ], + "defaultTemplateParts": [ + { + "kind": "Artist", + "representation": "{0}", + "isOptional": false + } + ] +} +``` diff --git a/docs/technical/requests/library/management/AddLibrary.http b/docs/technical/requests/library/management/AddLibrary.http index f6136db5..0a20c31f 100644 --- a/docs/technical/requests/library/management/AddLibrary.http +++ b/docs/technical/requests/library/management/AddLibrary.http @@ -11,7 +11,11 @@ Content-Type: application/json "coverImage": null, "isEnabled": true, "isLocked": false, - "downloadMetadataFromWeb": true, + "canDownloadMetadataFromWeb": true, "shouldSaveMetadataInMediaDirectories": true, - "shouldSkipUnchangedDirectoriesDuringScan": true + "shouldSkipUnchangedDirectoriesDuringScan": true, + "pathTemplateParts": [ + { "kind": "Artist", "representation": "{0}", "isOptional": false }, + { "kind": "Separator", "representation": "", "isOptional": false } + ] } diff --git a/docs/technical/requests/library/management/GetLibraryPathTemplateParts.http b/docs/technical/requests/library/management/GetLibraryPathTemplateParts.http new file mode 100644 index 00000000..1562fed7 --- /dev/null +++ b/docs/technical/requests/library/management/GetLibraryPathTemplateParts.http @@ -0,0 +1,2 @@ +GET {{host}}/api/v1/libraries/path-template-parts/Music +Authorization: Bearer {{ACCESS_TOKEN}} diff --git a/docs/technical/requests/library/management/UpdateLibrary.http b/docs/technical/requests/library/management/UpdateLibrary.http index 5cc9136c..aa82d623 100644 --- a/docs/technical/requests/library/management/UpdateLibrary.http +++ b/docs/technical/requests/library/management/UpdateLibrary.http @@ -13,7 +13,11 @@ Content-Type: application/json "coverImage": null, "isEnabled": true, "isLocked": false, - "downloadMetadataFromWeb": true, + "canDownloadMetadataFromWeb": true, "shouldSaveMetadataInMediaDirectories": true, - "shouldSkipUnchangedDirectoriesDuringScan": true + "shouldSkipUnchangedDirectoriesDuringScan": true, + "pathTemplateParts": [ + { "kind": "Artist", "representation": "{0}", "isOptional": false }, + { "kind": "Separator", "representation": "", "isOptional": false } + ] } diff --git a/src/Lumina.Application/Common/DTO/MediaLibrary/Management/LibraryPathTemplatePartDto.cs b/src/Lumina.Application/Common/DTO/MediaLibrary/Management/LibraryPathTemplatePartDto.cs new file mode 100644 index 00000000..05a0898f --- /dev/null +++ b/src/Lumina.Application/Common/DTO/MediaLibrary/Management/LibraryPathTemplatePartDto.cs @@ -0,0 +1,13 @@ +namespace Lumina.Application.Common.DTO.MediaLibrary.Management; + +/// +/// Data transfer object for one part of the path template of a media library, carried by the commands that create or update a media library. +/// +/// The kind of the path part. +/// The literal text or the value mask of the path part. +/// Whether the path part can be absent from the path. +public record LibraryPathTemplatePartDto( + string? Kind, + string? Representation, + bool IsOptional +); diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/Management/LibraryEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/Management/LibraryEntity.cs index 3dfdaa16..993b48a4 100644 --- a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/Management/LibraryEntity.cs +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/Management/LibraryEntity.cs @@ -45,6 +45,11 @@ public class LibraryEntity : IStorageEntity, IAuditableEntity /// public required ICollection ContentLocations { get; init; } = []; + /// + /// Gets the ordered parts of the template describing the structure of the media library on disk. + /// + public ICollection PathTemplateParts { get; init; } = []; + /// /// Gets the list of scans of the media library. /// @@ -87,6 +92,12 @@ public class LibraryEntity : IStorageEntity, IAuditableEntity /// public string? ArtworkProvidersConfigurationFingerprint { get; set; } + /// + /// Gets or sets the fingerprint of the path template of the media library, used to detect whether the template + /// changed since the last scan, and thus whether the metadata needs to be derived from the paths again. + /// + public string? PathTemplateFingerprint { get; set; } + /// /// Gets the user that owns the media library. /// diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/Management/LibraryPathTemplatePartEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/Management/LibraryPathTemplatePartEntity.cs new file mode 100644 index 00000000..dfa26b26 --- /dev/null +++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/Management/LibraryPathTemplatePartEntity.cs @@ -0,0 +1,33 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management; + +/// +/// Repository entity for one part of the path template of a media library. +/// +[DebuggerDisplay("Kind: {Kind}; Position: {Position}")] +public class LibraryPathTemplatePartEntity +{ + /// + /// Gets or sets the zero based position of the part in the path template. + /// + public required int Position { get; set; } + + /// + /// Gets or sets the kind of the path part. + /// + public required LibraryPathPartKind Kind { get; set; } + + /// + /// Gets or sets the literal text or the value mask of the path part. + /// + public required string Representation { get; set; } + + /// + /// Gets or sets whether the path part can be absent from the path. + /// + public required bool IsOptional { get; set; } +} diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/AddMediaLibraryRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/AddMediaLibraryRequestMapping.cs index f524961e..e02402e7 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/AddMediaLibraryRequestMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/AddMediaLibraryRequestMapping.cs @@ -1,6 +1,8 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DTO.MediaLibrary.Management; using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary; using Lumina.Contracts.Requests.MediaLibrary.Management; +using System.Linq; #endregion namespace Lumina.Application.Common.Mapping.MediaLibrary.Management; @@ -26,7 +28,8 @@ public static class AddMediaLibraryRequestMapping request.IsLocked, request.CanDownloadMetadataFromWeb, request.ShouldSaveMetadataInMediaDirectories, - request.ShouldSkipUnchangedDirectoriesDuringScan + request.ShouldSkipUnchangedDirectoriesDuringScan, + request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part.Kind, part.Representation, part.IsOptional)).ToArray() ); } } diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/GetLibraryPathTemplatePartsRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/GetLibraryPathTemplatePartsRequestMapping.cs new file mode 100644 index 00000000..b407fb7a --- /dev/null +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/GetLibraryPathTemplatePartsRequestMapping.cs @@ -0,0 +1,24 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraryPathTemplateParts; +using Lumina.Contracts.Requests.MediaLibrary.Management; +#endregion + +namespace Lumina.Application.Common.Mapping.MediaLibrary.Management; + +/// +/// Extension methods for converting . +/// +public static class GetLibraryPathTemplatePartsRequestMapping +{ + /// + /// Converts to . + /// + /// The request to be converted. + /// The converted query. + public static GetLibraryPathTemplatePartsQuery ToQuery(this GetLibraryPathTemplatePartsRequest request) + { + return new GetLibraryPathTemplatePartsQuery( + request.LibraryType + ); + } +} diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryEntityMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryEntityMapping.cs index 2e7e8142..70060f17 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryEntityMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryEntityMapping.cs @@ -36,6 +36,9 @@ public static class LibraryEntityMapping repositoryEntity.CanDownloadMetadataFromWeb, repositoryEntity.ShouldSaveMetadataInMediaDirectories, repositoryEntity.ShouldSkipUnchangedDirectoriesDuringScan, + [.. repositoryEntity.PathTemplateParts + .OrderBy(part => part.Position) + .Select(part => new LibraryPathTemplatePartResponse(part.Kind.ToString(), part.Representation, part.IsOptional))], repositoryEntity.CreatedOnUtc, repositoryEntity.UpdatedOnUtc ); @@ -50,6 +53,10 @@ public static class LibraryEntityMapping /// public static Result ToDomainEntity(this LibraryEntity repositoryEntity) { + Result pathTemplateResult = BuildPathTemplate(repositoryEntity.PathTemplateParts); + if (pathTemplateResult.IsFailure) + return pathTemplateResult.Errors; + return Library.Create( LibraryId.Create(repositoryEntity.Id), UserId.Create(repositoryEntity.UserId), @@ -62,10 +69,31 @@ public static class LibraryEntityMapping repositoryEntity.CanDownloadMetadataFromWeb, repositoryEntity.ShouldSaveMetadataInMediaDirectories, repositoryEntity.ShouldSkipUnchangedDirectoriesDuringScan, + pathTemplateResult.Value, [.. repositoryEntity.LibraryScans.Select(libraryScan => ScanId.Create(libraryScan.Id))] ); } + /// + /// Builds the path template of a media library from its ordered stored parts. + /// + /// The stored parts of the path template. + /// + /// An containing either the built , or an error message. + /// + private static Result BuildPathTemplate(IEnumerable parts) + { + List orderedParts = []; + foreach (LibraryPathTemplatePartEntity part in parts.OrderBy(part => part.Position)) + { + Result partResult = LibraryPathPart.Create(part.Kind, part.Representation, part.IsOptional); + if (partResult.IsFailure) + return partResult.Errors; + orderedParts.Add(partResult.Value); + } + return LibraryPathTemplate.Create(orderedParts); + } + /// /// Converts to a collection of . /// diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryMapping.cs index be721acb..3d90a2a8 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryMapping.cs @@ -26,6 +26,13 @@ public static class LibraryMapping LibraryType = domainEntity.LibraryType, UserId = domainEntity.UserId.Value, ContentLocations = [.. domainEntity.ContentLocations.Select(path => new LibraryContentLocationEntity() { Path = path.Path })], + PathTemplateParts = [.. domainEntity.PathTemplate.Parts.Select((part, index) => new LibraryPathTemplatePartEntity + { + Kind = part.Kind, + Representation = part.Representation, + IsOptional = part.IsOptional, + Position = index + })], CoverImage = domainEntity.CoverImage.HasValue ? domainEntity.CoverImage.Value : null, IsEnabled = domainEntity.IsEnabled, IsLocked = domainEntity.IsLocked, diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryPathTemplatePartDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryPathTemplatePartDtoMapping.cs new file mode 100644 index 00000000..df2c4165 --- /dev/null +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/LibraryPathTemplatePartDtoMapping.cs @@ -0,0 +1,44 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DTO.MediaLibrary.Management; +using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System; +using System.Collections.Generic; +using DomainErrors = Lumina.Domain.Common.Errors.Errors; +#endregion + +namespace Lumina.Application.Common.Mapping.MediaLibrary.Management; + +/// +/// Extension methods for converting . +/// +public static class LibraryPathTemplatePartDtoMapping +{ + /// + /// Converts the provided path template parts to their domain path parts. + /// + /// The path template parts to be converted. + /// + /// An containing either the converted domain path parts, or an error message. + /// + public static Result> ToDomainParts(this IEnumerable? parts) + { + List domainParts = []; + if (parts is null) + return domainParts; + + foreach (LibraryPathTemplatePartDto part in parts) + { + if (!Enum.TryParse(part.Kind, ignoreCase: true, out LibraryPathPartKind kind)) + return DomainErrors.Library.PathTemplatePartKindNotSupportedForLibraryType; + + Result partResult = LibraryPathPart.Create(kind, part.Representation, part.IsOptional); + if (partResult.IsFailure) + return partResult.Errors; + + domainParts.Add(partResult.Value); + } + return domainParts; + } +} diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/UpdateLibraryRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/UpdateLibraryRequestMapping.cs index 374f9e15..529bbc32 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/UpdateLibraryRequestMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/Management/UpdateLibraryRequestMapping.cs @@ -1,6 +1,8 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DTO.MediaLibrary.Management; using Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary; using Lumina.Contracts.Requests.MediaLibrary.Management; +using System.Linq; #endregion namespace Lumina.Application.Common.Mapping.MediaLibrary.Management; @@ -28,7 +30,8 @@ public static class UpdateLibraryRequestMapping request.IsLocked, request.CanDownloadMetadataFromWeb, request.ShouldSaveMetadataInMediaDirectories, - request.ShouldSkipUnchangedDirectoriesDuringScan + request.ShouldSkipUnchangedDirectoriesDuringScan, + request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part.Kind, part.Representation, part.IsOptional)).ToArray() ); } } diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommand.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommand.cs index 995a3ee6..e1ff00bf 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommand.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommand.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.CQRS; +using Lumina.Application.Common.DTO.MediaLibrary.Management; using System.Diagnostics; #endregion @@ -17,6 +18,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary; /// Whether this media library should update the metadata of its elements from the web, or not. /// Whether this media library should copy the downloaded metadata into the media library content locations, or not. /// Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. +/// The ordered parts of the template describing the structure of the media library on disk. [DebuggerDisplay("Title: {Title}")] public record AddLibraryCommand( string? Title, @@ -27,5 +29,6 @@ public record AddLibraryCommand( bool IsLocked, bool CanDownloadMetadataFromWeb, bool ShouldSaveMetadataInMediaDirectories, - bool ShouldSkipUnchangedDirectoriesDuringScan + bool ShouldSkipUnchangedDirectoriesDuringScan, + LibraryPathTemplatePartDto[]? PathTemplateParts ) : ICommand; diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandler.cs index 44e6272e..d41a53cb 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandler.cs @@ -11,6 +11,8 @@ using Lumina.Application.Common.Mapping.MediaLibrary.Management; using Lumina.Contracts.Responses.MediaLibrary.Management; using Lumina.Domain.Common.Events; using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate; @@ -39,6 +41,7 @@ public class AddLibraryCommandHandler : ICommandHandler _validator; /// @@ -49,6 +52,7 @@ public class AddLibraryCommandHandler : ICommandHandlerInjected service for the queue of domain events. /// Injected facade service for environment contextual services. /// Injected store of the provider configurations of the media libraries. + /// Injected service for validating and resolving the path templates of the media libraries. /// Injected unit of work for interacting with the data access layer repositories. /// Injected validator for application validation rules. public AddLibraryCommandHandler( @@ -57,6 +61,7 @@ public class AddLibraryCommandHandler : ICommandHandler validator) { @@ -66,6 +71,7 @@ public class AddLibraryCommandHandler : ICommandHandler(command.LibraryType!); + + // A library always carries a path template: the one provided by the user, or the ideal structure of the library type as its default. + Result> pathTemplatePartsResult = command.PathTemplateParts.ToDomainParts(); + if (pathTemplatePartsResult.IsFailure) + return pathTemplatePartsResult.Errors; + LibraryPathTemplate pathTemplate = command.PathTemplateParts is null + ? _pathTemplateService.GetDefaultTemplate(libraryType) + : LibraryPathTemplate.Create(pathTemplatePartsResult.Value); + Result validatePathTemplateResult = _pathTemplateService.Validate(libraryType, pathTemplate); + if (validatePathTemplateResult.IsFailure) + return validatePathTemplateResult.Errors; + // Create a domain library object. Result createLibraryResult = Library.Create( UserId.Create(userId), command.Title!, - Enum.Parse(command.LibraryType!), + libraryType, command.ContentLocations!, Optional.FromNullable(command.CoverImage), command.IsEnabled, @@ -120,6 +139,7 @@ public class AddLibraryCommandHandler : ICommandHandler ensureProviderConfigurationsResult = await _providerConfigurationStore.EnsureProviderConfigurationsAsync( - createLibraryResult.Value.Id.Value, Enum.Parse(command.LibraryType!), cancellationToken).ConfigureAwait(false); + createLibraryResult.Value.Id.Value, libraryType, cancellationToken).ConfigureAwait(false); if (ensureProviderConfigurationsResult.IsFailure) return ensureProviderConfigurationsResult.Errors; diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandValidator.cs index b439d346..a1ad34cb 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandValidator.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandValidator.cs @@ -41,5 +41,17 @@ public class AddLibraryCommandValidator : AbstractValidator .WithError(Errors.Library.TitleCannotBeEmpty) .MaximumLength(255) .WithError(Errors.Library.TitleMustBeMaximum255CharactersLong); + + RuleForEach(command => command.PathTemplateParts) + .ChildRules(part => + { + part.RuleFor(pathPart => pathPart.Kind) + .NotEmpty() + .WithError(Errors.Library.PathTemplatePartKindNotSupportedForLibraryType); + part.RuleFor(pathPart => pathPart.Representation) + .NotEmpty() + .When(pathPart => !string.Equals(pathPart.Kind, nameof(LibraryPathPartKind.Separator), StringComparison.OrdinalIgnoreCase)) + .WithError(Errors.Library.PathTemplateLiteralCannotBeEmpty); + }); } } diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommand.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommand.cs index 63fd4be0..27965444 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommand.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommand.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.CQRS; +using Lumina.Application.Common.DTO.MediaLibrary.Management; using System; using System.Diagnostics; #endregion @@ -20,6 +21,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary /// Whether this media library should update the metadata of its elements from the web, or not. /// Whether this media library should copy the downloaded metadata into the media library content locations, or not. /// Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. +/// The ordered parts of the template describing the structure of the media library on disk. [DebuggerDisplay("Title: {Title}")] public record UpdateLibraryCommand( Guid Id, @@ -32,5 +34,6 @@ public record UpdateLibraryCommand( bool IsLocked, bool CanDownloadMetadataFromWeb, bool ShouldSaveMetadataInMediaDirectories, - bool ShouldSkipUnchangedDirectoriesDuringScan + bool ShouldSkipUnchangedDirectoriesDuringScan, + LibraryPathTemplatePartDto[]? PathTemplateParts ) : ICommand; diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandHandler.cs index 42fe46cb..6f0a8dc2 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandHandler.cs @@ -12,6 +12,7 @@ using Lumina.Application.Common.Mapping.MediaLibrary.Management; using Lumina.Contracts.Responses.MediaLibrary.Management; using Lumina.Domain.Common.Events; using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate; @@ -43,6 +44,7 @@ public class UpdateLibraryCommandHandler : ICommandHandler _validator; /// @@ -53,6 +55,7 @@ public class UpdateLibraryCommandHandler : ICommandHandlerInjected service for the queue of domain events. /// Injected facade service for environment contextual services. /// Injected store of the provider configurations of the media libraries. + /// Injected service for validating and resolving the path templates of the media libraries. /// Injected unit of work for interacting with the data access layer repositories. /// Injected validator for application validation rules. public UpdateLibraryCommandHandler( @@ -61,6 +64,7 @@ public class UpdateLibraryCommandHandler : ICommandHandler validator) { @@ -70,6 +74,7 @@ public class UpdateLibraryCommandHandler : ICommandHandler(command.LibraryType!); + + // A library always carries a path template: the one provided by the user, or the ideal structure of the library type as its default. + Result> pathTemplatePartsResult = command.PathTemplateParts.ToDomainParts(); + if (pathTemplatePartsResult.IsFailure) + return pathTemplatePartsResult.Errors; + LibraryPathTemplate pathTemplate = command.PathTemplateParts is null + ? _pathTemplateService.GetDefaultTemplate(newLibraryType) + : LibraryPathTemplate.Create(pathTemplatePartsResult.Value); + Result validatePathTemplateResult = _pathTemplateService.Validate(newLibraryType, pathTemplate); + if (validatePathTemplateResult.IsFailure) + return validatePathTemplateResult.Errors; + Result createLibraryResult = Library.Create( LibraryId.Create(command.Id), UserId.Create(command.OwnerId), @@ -136,6 +153,7 @@ public class UpdateLibraryCommandHandler : ICommandHandler ScanId.Create(libraryScan.Id))] ); if (createLibraryResult.IsFailure) diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandValidator.cs index 53ed0211..febdd879 100644 --- a/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandValidator.cs +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandValidator.cs @@ -53,5 +53,17 @@ public class UpdateLibraryCommandValidator : AbstractValidator command.PathTemplateParts) + .ChildRules(part => + { + part.RuleFor(pathPart => pathPart.Kind) + .NotEmpty() + .WithError(Errors.Library.PathTemplatePartKindNotSupportedForLibraryType); + part.RuleFor(pathPart => pathPart.Representation) + .NotEmpty() + .When(pathPart => !string.Equals(pathPart.Kind, nameof(LibraryPathPartKind.Separator), StringComparison.OrdinalIgnoreCase)) + .WithError(Errors.Library.PathTemplateLiteralCannotBeEmpty); + }); } } diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Queries/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsQuery.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Queries/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsQuery.cs new file mode 100644 index 00000000..acf7fb9f --- /dev/null +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Queries/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsQuery.cs @@ -0,0 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.CQRS; +using System.Diagnostics; +#endregion + +namespace Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraryPathTemplateParts; + +/// +/// Query for getting the path parts available for a media library type. +/// +/// The media library type whose available path parts are retrieved. +[DebuggerDisplay("LibraryType: {LibraryType}")] +public record GetLibraryPathTemplatePartsQuery( + string? LibraryType +) : IQuery; diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Queries/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Queries/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsQueryHandler.cs new file mode 100644 index 00000000..ac64fcec --- /dev/null +++ b/src/Lumina.Application/Core/MediaLibrary/Management/Queries/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsQueryHandler.cs @@ -0,0 +1,72 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.CQRS; +using Lumina.Contracts.Responses.MediaLibrary.Management; +using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using DomainErrors = Lumina.Domain.Common.Errors.Errors; +#endregion + +namespace Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraryPathTemplateParts; + +/// +/// Handler for the query to get the path template catalog available for a media library type. +/// +public class GetLibraryPathTemplatePartsQueryHandler : IQueryHandler> +{ + private readonly IReadOnlyList _catalogs; + + /// + /// Initializes a new instance of the class. + /// + /// Injected path part catalogs of the supported media library types. + public GetLibraryPathTemplatePartsQueryHandler(IEnumerable catalogs) + { + _catalogs = [.. catalogs]; + } + + /// + /// Handles the query to get the path template catalog available for a media library type. + /// + /// The query to be handled. + /// Cancellation token that can be used to stop the execution. + /// + /// An containing either the path template catalog, or an error message. + /// + public Task> HandleAsync(GetLibraryPathTemplatePartsQuery query, CancellationToken cancellationToken) + { + // the library type travels as a string taken from the route, and is matched against the enum the same way the create and update + // library commands do, so that a malformed type is reported as an unknown library type instead of silently returning an empty catalog. + if (!Enum.TryParse(query.LibraryType, ignoreCase: true, out LibraryType libraryType)) + return Task.FromResult>(DomainErrors.Library.UnknownLibraryType); + + // only the catalog registered for the requested library type applies, so the parts and the default structure offered to the user are + // type aware (music libraries get artist and release parts, book libraries get author and title parts, and so on). + ILibraryPathPartCatalog? catalog = _catalogs.FirstOrDefault(candidate => candidate.SupportedLibraryType == libraryType); + if (catalog is null) + // a library type without a catalog has no structure to describe, so an empty catalog is returned, which the client uses to hide the editor. + return Task.FromResult(Result.Success(new LibraryPathTemplateCatalogResponse([], []))); + + // the selectable parts describe what the user can drop into the template, together with the value type and the default on-disk representation of each part. + List parts = + [ + .. catalog.GetPartDefinitions().Select(definition => new LibraryPathPartDefinitionResponse( + definition.Kind.ToString(), + definition.ValueType.ToString(), + definition.DefaultRepresentation, + definition.IsOptionalByDefault)) + ]; + // the default template parts describe the ideal structure the application expects, pre-filled in the editor so the user only edits what deviates. + List defaultTemplateParts = + [ + .. catalog.GetDefaultTemplate().Parts.Select(part => new LibraryPathTemplatePartResponse(part.Kind.ToString(), part.Representation, part.IsOptional)) + ]; + return Task.FromResult(Result.Success(new LibraryPathTemplateCatalogResponse(parts, defaultTemplateParts))); + } +} diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/Management/AddLibraryRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/Management/AddLibraryRequest.cs index df43eb8d..8f8e7196 100644 --- a/src/Lumina.Contracts/Requests/MediaLibrary/Management/AddLibraryRequest.cs +++ b/src/Lumina.Contracts/Requests/MediaLibrary/Management/AddLibraryRequest.cs @@ -16,6 +16,7 @@ namespace Lumina.Contracts.Requests.MediaLibrary.Management; /// Whether this media library should update the metadata of its elements from the web, or not. Optional. /// Whether this media library should copy the downloaded metadata into the media library content locations, or not. Optional. /// Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. Optional. +/// The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent. [DebuggerDisplay("Title: {Title}")] public record AddLibraryRequest( string? Title, @@ -26,5 +27,6 @@ public record AddLibraryRequest( bool IsLocked, bool CanDownloadMetadataFromWeb, bool ShouldSaveMetadataInMediaDirectories, - bool ShouldSkipUnchangedDirectoriesDuringScan + bool ShouldSkipUnchangedDirectoriesDuringScan, + LibraryPathTemplatePartRequest[]? PathTemplateParts ); diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/Management/GetLibraryPathTemplatePartsRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/Management/GetLibraryPathTemplatePartsRequest.cs new file mode 100644 index 00000000..41c8557c --- /dev/null +++ b/src/Lumina.Contracts/Requests/MediaLibrary/Management/GetLibraryPathTemplatePartsRequest.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Requests.MediaLibrary.Management; + +/// +/// Represents a request to get the path parts available for a media library type. +/// +/// The media library type whose available path parts are retrieved. Required. +[DebuggerDisplay("LibraryType: {LibraryType}")] +public record GetLibraryPathTemplatePartsRequest( + string? LibraryType +); diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/Management/LibraryPathTemplatePartRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/Management/LibraryPathTemplatePartRequest.cs new file mode 100644 index 00000000..bb4fab5e --- /dev/null +++ b/src/Lumina.Contracts/Requests/MediaLibrary/Management/LibraryPathTemplatePartRequest.cs @@ -0,0 +1,18 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Requests.MediaLibrary.Management; + +/// +/// Represents one part of the path template of a media library. +/// +/// The kind of the path part. Required. +/// The literal text or the value mask of the path part. Optional for separators, required otherwise. +/// Whether the path part can be absent from the path. Optional. +[DebuggerDisplay("Kind: {Kind}; Representation: {Representation}")] +public record LibraryPathTemplatePartRequest( + string? Kind, + string? Representation, + bool IsOptional +); diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/Management/UpdateLibraryRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/Management/UpdateLibraryRequest.cs index 9590f10a..ba3b9226 100644 --- a/src/Lumina.Contracts/Requests/MediaLibrary/Management/UpdateLibraryRequest.cs +++ b/src/Lumina.Contracts/Requests/MediaLibrary/Management/UpdateLibraryRequest.cs @@ -19,6 +19,7 @@ namespace Lumina.Contracts.Requests.MediaLibrary.Management; /// Whether this media library should update the metadata of its elements from the web, or not. Optional. /// Whether this media library should copy the downloaded metadata into the media library content locations, or not. /// Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. Optional. +/// The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent. [DebuggerDisplay("Title: {Title}")] public record class UpdateLibraryRequest( Guid Id, @@ -31,5 +32,6 @@ public record class UpdateLibraryRequest( bool IsLocked, bool CanDownloadMetadataFromWeb, bool ShouldSaveMetadataInMediaDirectories, - bool ShouldSkipUnchangedDirectoriesDuringScan + bool ShouldSkipUnchangedDirectoriesDuringScan, + LibraryPathTemplatePartRequest[]? PathTemplateParts ); diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryPathPartDefinitionResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryPathPartDefinitionResponse.cs new file mode 100644 index 00000000..43e7966c --- /dev/null +++ b/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryPathPartDefinitionResponse.cs @@ -0,0 +1,20 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Responses.MediaLibrary.Management; + +/// +/// Represents a path part definition response. +/// +/// The kind of the path part. +/// The value type captured by the path part. +/// The default representation of the path part, pre-filled when it is added to a template. +/// Whether the path part is optional by default. +[DebuggerDisplay("Kind: {Kind}; ValueType: {ValueType}")] +public record LibraryPathPartDefinitionResponse( + string Kind, + string ValueType, + string DefaultRepresentation, + bool IsOptionalByDefault +); diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryPathTemplateCatalogResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryPathTemplateCatalogResponse.cs new file mode 100644 index 00000000..91434a61 --- /dev/null +++ b/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryPathTemplateCatalogResponse.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Responses.MediaLibrary.Management; + +/// +/// Represents a path template catalog response. +/// +/// The path parts that can be used in the path template of the library type. +/// The ordered parts of the default path template of the library type, describing the ideal structure the application expects. +[DebuggerDisplay("Parts: {Parts.Count}; DefaultTemplateParts: {DefaultTemplateParts.Count}")] +public record LibraryPathTemplateCatalogResponse( + List Parts, + List DefaultTemplateParts +); diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryPathTemplatePartResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryPathTemplatePartResponse.cs new file mode 100644 index 00000000..b48e2e2a --- /dev/null +++ b/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryPathTemplatePartResponse.cs @@ -0,0 +1,18 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Responses.MediaLibrary.Management; + +/// +/// Represents a path template part response. +/// +/// The kind of the path part. +/// The literal text or the value mask of the path part. +/// Whether the path part can be absent from the path. +[DebuggerDisplay("Kind: {Kind}; Representation: {Representation}")] +public record LibraryPathTemplatePartResponse( + string Kind, + string Representation, + bool IsOptional +); diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryResponse.cs index 9dff6ddc..63e17fb0 100644 --- a/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryResponse.cs +++ b/src/Lumina.Contracts/Responses/MediaLibrary/Management/LibraryResponse.cs @@ -21,6 +21,7 @@ namespace Lumina.Contracts.Responses.MediaLibrary.Management; /// Whether the media library should update the metadata of its elements from the web, or not. /// Whether the media library should copy the downloaded metadata into the media library content locations, or not. /// Whether the media library should skip the directories whose contents have not changed since the last scan, during the scan. +/// The ordered parts of the template describing the structure of the media library on disk. /// The date and time when the library was created. /// The optional date and time when the library was updated. [DebuggerDisplay("Title: {Title}")] @@ -36,6 +37,7 @@ public record LibraryResponse( bool CanDownloadMetadataFromWeb, bool ShouldSaveMetadataInMediaDirectories, bool ShouldSkipUnchangedDirectoriesDuringScan, + List PathTemplateParts, DateTime CreatedOnUtc, DateTime? UpdatedOnUtc ); diff --git a/src/Lumina.DataAccess/Common/Configuration/LibraryConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/LibraryConfiguration.cs index 5f20f98a..ae9fcc88 100644 --- a/src/Lumina.DataAccess/Common/Configuration/LibraryConfiguration.cs +++ b/src/Lumina.DataAccess/Common/Configuration/LibraryConfiguration.cs @@ -66,6 +66,11 @@ public class LibraryConfiguration : IEntityTypeConfiguration .HasDefaultValue(null) .HasColumnOrder(10); + builder.Property(library => library.PathTemplateFingerprint) + .HasMaxLength(64) + .HasDefaultValue(null) + .HasColumnOrder(11); + // one user with many libraries builder.HasOne(library => library.User) .WithMany(user => user.Libraries) @@ -95,21 +100,48 @@ public class LibraryConfiguration : IEntityTypeConfiguration .IsRequired(); }); + // the path template parts are ordered, so their position is stored explicitly and part of a unique index together with the library + builder.OwnsMany(library => library.PathTemplateParts, partBuilder => + { + partBuilder.ToTable("LibraryPathTemplateParts"); + partBuilder.WithOwner() + .HasForeignKey("LibraryId"); + + partBuilder.Property("Id") + .ValueGeneratedOnAdd(); + partBuilder.HasKey("Id"); + partBuilder.HasIndex("LibraryId", nameof(LibraryPathTemplatePartEntity.Position)) + .IsUnique(); + + partBuilder.Property(part => part.Position) + .HasColumnName("Position") + .IsRequired(); + partBuilder.Property(part => part.Kind) + .HasConversion() + .HasMaxLength(32) + .IsRequired(); + partBuilder.Property(part => part.Representation) + .HasMaxLength(512) + .IsRequired(); + partBuilder.Property(part => part.IsOptional) + .IsRequired(); + }); + // audit builder.Property(library => library.CreatedOnUtc) .IsRequired() - .HasColumnOrder(11); + .HasColumnOrder(12); builder.Property(library => library.CreatedBy) .IsRequired() - .HasColumnOrder(12); + .HasColumnOrder(13); builder.Property(library => library.UpdatedOnUtc) .HasDefaultValue(null) - .HasColumnOrder(13); + .HasColumnOrder(14); builder.Property(library => library.UpdatedBy) .HasDefaultValue(null) - .HasColumnOrder(14); + .HasColumnOrder(15); } } diff --git a/src/Lumina.DataAccess/Common/Migrations/20261008064333_AddsLibraryPathTemplate.Designer.cs b/src/Lumina.DataAccess/Common/Migrations/20261008064333_AddsLibraryPathTemplate.Designer.cs new file mode 100644 index 00000000..412d7c15 --- /dev/null +++ b/src/Lumina.DataAccess/Common/Migrations/20261008064333_AddsLibraryPathTemplate.Designer.cs @@ -0,0 +1,3425 @@ +// +using System; +using Lumina.DataAccess.Core.UoW; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Lumina.DataAccess.Common.Migrations +{ + [DbContext(typeof(LuminaDbContext))] + [Migration("20261008064333_AddsLibraryPathTemplate")] + partial class AddsLibraryPathTemplate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.11"); + + modelBuilder.Entity("AlbumGenres", b => + { + b.Property("AlbumId") + .HasColumnType("TEXT"); + + b.Property("GenreId") + .HasColumnType("TEXT"); + + b.HasKey("AlbumId", "GenreId"); + + b.HasIndex("GenreId"); + + b.ToTable("AlbumGenres", (string)null); + }); + + modelBuilder.Entity("AlbumTags", b => + { + b.Property("AlbumId") + .HasColumnType("TEXT"); + + b.Property("TagId") + .HasColumnType("TEXT"); + + b.HasKey("AlbumId", "TagId"); + + b.HasIndex("TagId"); + + b.ToTable("AlbumTags", (string)null); + }); + + modelBuilder.Entity("ArtistGenres", b => + { + b.Property("ArtistId") + .HasColumnType("TEXT"); + + b.Property("GenreId") + .HasColumnType("TEXT"); + + b.HasKey("ArtistId", "GenreId"); + + b.HasIndex("GenreId"); + + b.ToTable("ArtistGenres", (string)null); + }); + + modelBuilder.Entity("ArtistTags", b => + { + b.Property("ArtistId") + .HasColumnType("TEXT"); + + b.Property("TagId") + .HasColumnType("TEXT"); + + b.HasKey("ArtistId", "TagId"); + + b.HasIndex("TagId"); + + b.ToTable("ArtistTags", (string)null); + }); + + modelBuilder.Entity("BookGenres", b => + { + b.Property("BookId") + .HasColumnType("TEXT"); + + b.Property("GenreId") + .HasColumnType("TEXT"); + + b.HasKey("BookId", "GenreId"); + + b.HasIndex("GenreId"); + + b.ToTable("BookGenres", (string)null); + }); + + modelBuilder.Entity("BookTags", b => + { + b.Property("BookId") + .HasColumnType("TEXT"); + + b.Property("TagId") + .HasColumnType("TEXT"); + + b.HasKey("BookId", "TagId"); + + b.HasIndex("TagId"); + + b.ToTable("BookTags", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.HasKey("Id"); + + b.ToTable("Permissions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.HasKey("Id"); + + b.ToTable("Roles", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b => + { + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("PermissionId") + .HasColumnType("TEXT"); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("RoleId", "PermissionId"); + + b.HasIndex("PermissionId"); + + b.HasIndex("RoleId", "PermissionId") + .IsUnique(); + + b.ToTable("RolePermissions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("PermissionId") + .HasColumnType("TEXT"); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("UserId", "PermissionId"); + + b.HasIndex("PermissionId"); + + b.HasIndex("UserId", "PermissionId") + .IsUnique(); + + b.ToTable("UserPermissions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("UserId"); + + b.HasIndex("RoleId"); + + b.HasIndex("UserId", "RoleId") + .IsUnique(); + + b.ToTable("UserRoles", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", b => + { + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Genres", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", b => + { + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Tags", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaContributors.MediaContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Biography") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("DateOfBirth") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("DateOfDeath") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1) + .UseCollation("NOCASE"); + + b.Property("LegalName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.HasKey("Id"); + + b.HasIndex("DisplayName") + .IsUnique(); + + b.ToTable("MediaContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("AlbumId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("MediaContributorId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Role") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("MediaContributorId"); + + b.HasIndex("AlbumId", "MediaContributorId", "Role") + .IsUnique(); + + b.ToTable("AlbumContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ASIN") + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(28); + + b.Property("ArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Barcode") + .HasMaxLength(13) + .HasColumnType("TEXT") + .HasColumnOrder(25); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(33); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(32); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Disambiguation") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("Label") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(27); + + b.Property("LanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("LanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("LanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(37); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("MediaFormat") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(23); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(38); + + b.Property("MetadataStatus") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasDefaultValue("Pending") + .HasColumnOrder(36); + + b.Property("MusicBrainzReleaseArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(31); + + b.Property("MusicBrainzReleaseGroupId") + .HasColumnType("TEXT") + .HasColumnOrder(30); + + b.Property("MusicBrainzReleaseId") + .HasColumnType("TEXT") + .HasColumnOrder(29); + + b.Property("OriginalLanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(16); + + b.Property("OriginalLanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(17); + + b.Property("OriginalLanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("OriginalReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("OriginalReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(8); + + b.Property("OriginalTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("Packaging") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.Property("ReReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("ReReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("ReleaseCountry") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("ReleaseStatus") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(20); + + b.Property("ReleaseTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(26); + + b.Property("ReleaseVersion") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("Script") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("TotalDiscs") + .HasColumnType("INTEGER") + .HasColumnOrder(21); + + b.Property("TotalTracks") + .HasColumnType("INTEGER") + .HasColumnOrder(22); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(35); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(34); + + b.HasKey("Id"); + + b.HasIndex("ArtistId", "Title"); + + b.HasIndex("LibraryId", "Title"); + + b.ToTable("Albums", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("MediaContributorId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Role") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("MediaContributorId"); + + b.HasIndex("ArtistId", "MediaContributorId", "Role") + .IsUnique(); + + b.ToTable("ArtistContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Country") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("Disambiguation") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("Gender") + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("IsEnded") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("LifeSpanBegin") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("LifeSpanEnd") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("MetadataStatus") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasDefaultValue("Pending") + .HasColumnOrder(17); + + b.Property("MusicBrainzArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("SortName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("Type") + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(16); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("Website") + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "Name") + .IsUnique(); + + b.ToTable("Artists", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicArtworkEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtworkType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("FileName") + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("LastUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("Ordinal") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("OwnerId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("OwnerType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Provider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.HasIndex("OwnerType", "OwnerId", "ArtworkType", "Ordinal") + .IsUnique(); + + b.ToTable("MusicArtwork", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicLibraryScanItemMetadataEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("AcoustId") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(25); + + b.Property("ArtistName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("AudioCodec") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("BitDepth") + .HasColumnType("INTEGER") + .HasColumnOrder(14); + + b.Property("Bitrate") + .HasColumnType("INTEGER") + .HasColumnOrder(16); + + b.Property("Channels") + .HasColumnType("INTEGER") + .HasColumnOrder(13); + + b.Property("DiscNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("DurationInSeconds") + .HasColumnType("INTEGER") + .HasColumnOrder(11); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("LibraryScanId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.PrimitiveCollection("Moods") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(30); + + b.Property("MusicBrainzArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(17); + + b.Property("MusicBrainzRecordingId") + .HasColumnType("TEXT") + .HasColumnOrder(21); + + b.Property("MusicBrainzReleaseArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("MusicBrainzReleaseGroupId") + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("MusicBrainzReleaseId") + .HasColumnType("TEXT") + .HasColumnOrder(20); + + b.Property("MusicBrainzTrackId") + .HasColumnType("TEXT") + .HasColumnOrder(22); + + b.Property("MusicBrainzWorkId") + .HasColumnType("TEXT") + .HasColumnOrder(23); + + b.Property("Path") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("ReleaseName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("ReleaseType") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("ReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("ReplayGainAlbumGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(28); + + b.Property("ReplayGainAlbumPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(29); + + b.Property("ReplayGainTrackGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(26); + + b.Property("ReplayGainTrackPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(27); + + b.Property("SampleRate") + .HasColumnType("INTEGER") + .HasColumnOrder(12); + + b.Property("TrackNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(9); + + b.Property("TrackTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("WorkTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.HasKey("Id"); + + b.HasIndex("LibraryScanId", "Path") + .IsUnique(); + + b.ToTable("MusicLibraryScanItemMetadata", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("MediaContributorId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Role") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("TrackId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("MediaContributorId"); + + b.HasIndex("TrackId", "MediaContributorId", "Role") + .IsUnique(); + + b.ToTable("TrackContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("AcoustId") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(44); + + b.Property("AlbumId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("AudioCodec") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.Property("BitDepth") + .HasColumnType("INTEGER") + .HasColumnOrder(23); + + b.Property("Bitrate") + .HasColumnType("INTEGER") + .HasColumnOrder(25); + + b.Property("Bpm") + .HasColumnType("INTEGER") + .HasColumnOrder(30); + + b.Property("Channels") + .HasColumnType("INTEGER") + .HasColumnOrder(22); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(38); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(37); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("Disambiguation") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("DiscNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(27); + + b.Property("DurationInSeconds") + .HasColumnType("INTEGER") + .HasColumnOrder(20); + + b.Property("IsVideo") + .HasColumnType("INTEGER") + .HasColumnOrder(31); + + b.Property("Key") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(29); + + b.Property("LanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("LanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("LanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(16); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(42); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(43); + + b.Property("MetadataStatus") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasDefaultValue("Pending") + .HasColumnOrder(41); + + b.Property("MusicBrainzRecordingId") + .HasColumnType("TEXT") + .HasColumnOrder(34); + + b.Property("MusicBrainzTrackId") + .HasColumnType("TEXT") + .HasColumnOrder(35); + + b.Property("MusicBrainzWorkId") + .HasColumnType("TEXT") + .HasColumnOrder(36); + + b.Property("OriginalLanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(17); + + b.Property("OriginalLanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("OriginalLanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("OriginalReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("OriginalReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(9); + + b.Property("OriginalTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Path") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("ReReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("ReReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(11); + + b.Property("ReleaseCountry") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("ReleaseVersion") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("ReplayGainAlbumGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(47); + + b.Property("ReplayGainAlbumPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(48); + + b.Property("ReplayGainTrackGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(45); + + b.Property("ReplayGainTrackPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(46); + + b.Property("SampleRate") + .HasColumnType("INTEGER") + .HasColumnOrder(21); + + b.Property("Script") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(28); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("TrackNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(26); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(40); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(39); + + b.Property("WorkTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(32); + + b.Property("WorkType") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(33); + + b.HasKey("Id"); + + b.HasIndex("AlbumId", "TrackNumber"); + + b.HasIndex("LibraryId", "Path") + .IsUnique(); + + b.ToTable("Tracks", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.DirectoryScanFingerprintEntity", b => + { + b.Property("LibraryId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("LastWriteTimeUtc") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.HasKey("LibraryId", "Path"); + + b.HasIndex("LibraryId"); + + b.ToTable("DirectoryScanFingerprints", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtworkProvidersConfigurationFingerprint") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("CanDownloadMetadataFromWeb") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(true) + .HasColumnOrder(6); + + b.Property("CoverImage") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("IsEnabled") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(true) + .HasColumnOrder(4); + + b.Property("IsLocked") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("LibraryType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("MetadataProvidersConfigurationFingerprint") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("PathTemplateFingerprint") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("ShouldSaveMetadataInMediaDirectories") + .HasColumnType("INTEGER") + .HasColumnOrder(7); + + b.Property("ShouldSkipUnchangedDirectoriesDuringScan") + .HasColumnType("INTEGER") + .HasColumnOrder(8); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Libraries", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("LibraryId") + .HasColumnType("TEXT"); + + b.Property("Status") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.HasIndex("LibraryId", "Status", "CreatedOnUtc") + .IsDescending(true, false, true); + + b.ToTable("LibraryScans", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanResultEntity", b => + { + b.Property("LibraryScanId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasMaxLength(24) + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("FileSize") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Status") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Ticks") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.HasKey("LibraryScanId", "Path"); + + b.HasIndex("Path"); + + b.HasIndex("ContentHash", "FileSize", "Path"); + + b.ToTable("LibraryScanResults", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanSnapshotEntity", b => + { + b.Property("LibraryId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("FileSize") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Ticks") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("LibraryId", "Path"); + + b.HasIndex("LibraryId"); + + b.ToTable("LibraryScanSnapshots", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanStagingResultsEntity", b => + { + b.Property("LibraryScanId") + .HasColumnType("TEXT"); + + b.Property("Path") + .HasMaxLength(1024) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("IsNew") + .HasColumnType("INTEGER") + .HasColumnOrder(7); + + b.Property("NeedsRehash") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("PreviousContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("Size") + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("Ticks") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.HasKey("LibraryScanId", "Path"); + + b.HasIndex("LibraryScanId", "NeedsRehash"); + + b.ToTable("LibraryScanStagingResults", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookArtworkEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtworkType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("BookId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("FileName") + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("LastUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Ordinal") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("Provider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.HasIndex("BookId", "ArtworkType", "Ordinal") + .IsUnique(); + + b.ToTable("BookArtwork", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookContributorEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("BookId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("MediaContributorId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Role") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("MediaContributorId"); + + b.HasIndex("BookId", "MediaContributorId", "Role") + .IsUnique(); + + b.ToTable("BookContributors", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ASIN") + .HasMaxLength(10) + .HasColumnType("TEXT") + .HasColumnOrder(21); + + b.Property("AppleBooksId") + .HasColumnType("TEXT") + .HasColumnOrder(29); + + b.Property("BarnesAndNobleId") + .HasMaxLength(10) + .HasColumnType("TEXT") + .HasColumnOrder(28); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(33); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(32); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("Edition") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("Format") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("GoodreadsId") + .HasColumnType("TEXT") + .HasColumnOrder(22); + + b.Property("GoogleBooksId") + .HasMaxLength(12) + .HasColumnType("TEXT") + .HasColumnOrder(27); + + b.Property("LCCN") + .HasColumnType("TEXT") + .HasColumnOrder(23); + + b.Property("LanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("LanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("LanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(39); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(36); + + b.Property("LibraryThingId") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(26); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(40); + + b.Property("MetadataStatus") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(38); + + b.Property("OCLCNumber") + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.Property("OpenLibraryId") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(25); + + b.Property("OriginalLanguageCode") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("OriginalLanguageName") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("OriginalLanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("OriginalReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("OriginalReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("OriginalTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("PageCount") + .HasColumnType("INTEGER") + .HasColumnOrder(17); + + b.Property("Path") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(37); + + b.Property("Publisher") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(16); + + b.Property("ReReleaseDate") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("ReReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(7); + + b.Property("ReleaseCountry") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("ReleaseVersion") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(35); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(34); + + b.Property("VolumeNumber") + .HasColumnType("REAL") + .HasColumnOrder(20); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "MetadataStatus"); + + b.HasIndex("LibraryId", "Path") + .IsUnique(); + + b.ToTable("Books", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryArtworkProviderConfigurationEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("IsEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("PluginId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Rank") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "PluginId"); + + b.ToTable("LibraryArtworkProviderConfigurations", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryBookReaderConfigurationEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("IsEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("PluginId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "PluginId") + .IsUnique(); + + b.ToTable("LibraryBookReaderConfigurations", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.LibraryMetadataProviderConfigurationEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("IsEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("PluginId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("Rank") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.HasKey("Id"); + + b.HasIndex("LibraryId", "PluginId"); + + b.ToTable("LibraryMetadataProviderConfigurations", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Plugins.PluginEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Author") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Description") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("LoadError") + .HasMaxLength(2000) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("LoadStatus") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("SettingsJson") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("Version") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.HasKey("Id"); + + b.ToTable("Plugins", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.ScheduledJobEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("Hour") + .HasColumnType("INTEGER") + .HasColumnOrder(5); + + b.Property("IntervalMinutes") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("LastCompletedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("LastStartedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("Minute") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("OwnerUserId") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("ScheduleType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("Status") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("TaskType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.ToTable("ScheduledJobs", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.ScheduledJobExecutionEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CompletedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("IsCycleRun") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("ScheduledJobId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("StartedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("TaskType") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("WasCycleActive") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.HasKey("Id"); + + b.HasIndex("ScheduledJobId"); + + b.HasIndex("StartedOnUtc", "ScheduledJobId"); + + b.ToTable("ScheduledJobExecutions", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Scheduling.SchedulerDisplayPreferencesEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("DisplayTimeSpan") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("DisplayTimeUnit") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("JobTypeFilter") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UserId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("SchedulerDisplayPreferences", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Themes.ThemeEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("Author") + .IsRequired() + .HasMaxLength(80) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("Description") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("InstallSource") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("InstalledAtUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("IsCurrent") + .HasColumnType("INTEGER") + .HasColumnOrder(8); + + b.Property("IsDeleted") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasDefaultValue(false) + .HasColumnOrder(9); + + b.Property("Name") + .IsRequired() + .HasMaxLength(80) + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("PreviewPath") + .HasMaxLength(240) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("ThemeId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(14); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("Version") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.HasKey("Id"); + + b.HasIndex("IsCurrent") + .IsUnique() + .HasFilter("IsCurrent = 1"); + + b.HasIndex("ThemeId") + .IsUnique(); + + b.ToTable("Themes", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("TempPassword") + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("TempPasswordCreated") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("TotpSecret") + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Username") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.HasKey("Id"); + + b.HasIndex("Username") + .IsUnique(); + + b.ToTable("Users", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserSettingsEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("IsPaginationEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(2); + + b.Property("IsThemeCachingEnabled") + .HasColumnType("INTEGER") + .HasColumnOrder(9); + + b.Property("ItemsPerPage") + .HasColumnType("INTEGER") + .HasColumnOrder(3); + + b.Property("ShouldAggregateArtworkWhenMissing") + .HasColumnType("INTEGER") + .HasColumnOrder(13); + + b.Property("ShouldAggregateMetadataWhenMissing") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("ShouldIgnoreThePrefixForAlphaPicker") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("ShouldPreserveBookStyles") + .HasColumnType("INTEGER") + .HasColumnOrder(12); + + b.Property("ShouldRenderPdfAsImages") + .HasColumnType("INTEGER") + .HasColumnOrder(11); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UserId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("UserSettings", (string)null); + }); + + modelBuilder.Entity("TrackGenres", b => + { + b.Property("TrackId") + .HasColumnType("TEXT"); + + b.Property("GenreId") + .HasColumnType("TEXT"); + + b.HasKey("TrackId", "GenreId"); + + b.HasIndex("GenreId"); + + b.ToTable("TrackGenres", (string)null); + }); + + modelBuilder.Entity("TrackTags", b => + { + b.Property("TrackId") + .HasColumnType("TEXT"); + + b.Property("TagId") + .HasColumnType("TEXT"); + + b.HasKey("TrackId", "TagId"); + + b.HasIndex("TagId"); + + b.ToTable("TrackTags", (string)null); + }); + + modelBuilder.Entity("AlbumGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", null) + .WithMany() + .HasForeignKey("AlbumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("AlbumTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", null) + .WithMany() + .HasForeignKey("AlbumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ArtistGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", null) + .WithMany() + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ArtistTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", null) + .WithMany() + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BookGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany() + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("BookTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany() + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", "Permission") + .WithMany("RolePermissions") + .HasForeignKey("PermissionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", "Role") + .WithMany("RolePermissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Permission"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", "Permission") + .WithMany("UserPermissions") + .HasForeignKey("PermissionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithMany("UserPermissions") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Permission"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", "Role") + .WithMany("UserRoles") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithOne("UserRole") + .HasForeignKey("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", null) + .WithMany("Contributors") + .HasForeignKey("AlbumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", "Artist") + .WithMany("Albums") + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumCatalogNumberEntity", "CatalogNumbers", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("AlbumId") + .HasColumnType("TEXT"); + + b1.Property("CatalogNumber") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("AlbumId"); + + b1.ToTable("AlbumCatalogNumbers", (string)null); + + b1.WithOwner() + .HasForeignKey("AlbumId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AudioRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("AlbumId") + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("AlbumId"); + + b1.ToTable("AlbumRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("AlbumId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumReleaseTypeEntity", "ReleaseTypes", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("AlbumId") + .HasColumnType("TEXT"); + + b1.Property("ReleaseType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("AlbumId"); + + b1.ToTable("AlbumReleaseTypes", (string)null); + + b1.WithOwner() + .HasForeignKey("AlbumId"); + }); + + b.Navigation("Artist"); + + b.Navigation("CatalogNumbers"); + + b.Navigation("Ratings"); + + b.Navigation("ReleaseTypes"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", null) + .WithMany("Contributors") + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", b => + { + b.OwnsOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicAreaEntity", "Area", b1 => + { + b1.Property("ArtistEntityId"); + + b1.Property("Disambiguation"); + + b1.Property("Iso3166Code"); + + b1.Property("MusicBrainzAreaId"); + + b1.Property("Name") + .IsRequired(); + + b1.Property("SortName"); + + b1.Property("Type"); + + b1.HasKey("ArtistEntityId"); + + b1.ToTable("Artists"); + + b1 + .ToJson("Area") + .HasColumnType("TEXT"); + + b1.WithOwner() + .HasForeignKey("ArtistEntityId"); + }); + + b.OwnsOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicAreaEntity", "BeginArea", b1 => + { + b1.Property("ArtistEntityId"); + + b1.Property("Disambiguation"); + + b1.Property("Iso3166Code"); + + b1.Property("MusicBrainzAreaId"); + + b1.Property("Name") + .IsRequired(); + + b1.Property("SortName"); + + b1.Property("Type"); + + b1.HasKey("ArtistEntityId"); + + b1.ToTable("Artists"); + + b1 + .ToJson("BeginArea") + .HasColumnType("TEXT"); + + b1.WithOwner() + .HasForeignKey("ArtistEntityId"); + }); + + b.OwnsOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicAreaEntity", "EndArea", b1 => + { + b1.Property("ArtistEntityId"); + + b1.Property("Disambiguation"); + + b1.Property("Iso3166Code"); + + b1.Property("MusicBrainzAreaId"); + + b1.Property("Name") + .IsRequired(); + + b1.Property("SortName"); + + b1.Property("Type"); + + b1.HasKey("ArtistEntityId"); + + b1.ToTable("Artists"); + + b1 + .ToJson("EndArea") + .HasColumnType("TEXT"); + + b1.WithOwner() + .HasForeignKey("ArtistEntityId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistAliasEntity", "Aliases", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("BeginDate") + .HasColumnType("TEXT"); + + b1.Property("EndDate") + .HasColumnType("TEXT"); + + b1.Property("IsEnded") + .HasColumnType("INTEGER"); + + b1.Property("IsPrimary") + .HasColumnType("INTEGER"); + + b1.Property("Locale") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b1.Property("SortName") + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b1.Property("Type") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistAliases", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AudioRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistIpiEntity", "Ipis", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistIpis", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistIsniEntity", "Isnis", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistIsnis", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.Navigation("Aliases"); + + b.Navigation("Area"); + + b.Navigation("BeginArea"); + + b.Navigation("EndArea"); + + b.Navigation("Ipis"); + + b.Navigation("Isnis"); + + b.Navigation("Ratings"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", null) + .WithMany("Contributors") + .HasForeignKey("TrackId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", "Album") + .WithMany("Tracks") + .HasForeignKey("AlbumId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AudioRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackIsrcEntity", "Isrcs", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(12) + .HasColumnType("TEXT") + .HasColumnName("ISRC"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackIsrcs", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackMoodEntity", "Moods", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackMoods", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackWorkIswcEntity", "WorkIswcs", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackWorkIswcs", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackWorkLanguageEntity", "WorkLanguages", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("LanguageCode") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("TEXT"); + + b1.Property("LanguageName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b1.Property("NativeName") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackWorkLanguages", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.Navigation("Album"); + + b.Navigation("Isrcs"); + + b.Navigation("Moods"); + + b.Navigation("Ratings"); + + b.Navigation("WorkIswcs"); + + b.Navigation("WorkLanguages"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.DirectoryScanFingerprintEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", null) + .WithMany() + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithMany("Libraries") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryContentLocationEntity", "ContentLocations", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("LibraryId") + .HasColumnType("TEXT"); + + b1.Property("Path") + .IsRequired() + .HasMaxLength(260) + .HasColumnType("TEXT") + .HasColumnName("Path"); + + b1.HasKey("Id"); + + b1.HasIndex("LibraryId"); + + b1.ToTable("LibraryContentLocations", (string)null); + + b1.WithOwner() + .HasForeignKey("LibraryId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryPathTemplatePartEntity", "PathTemplateParts", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("IsOptional") + .HasColumnType("INTEGER"); + + b1.Property("Kind") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("TEXT"); + + b1.Property("LibraryId") + .HasColumnType("TEXT"); + + b1.Property("Position") + .HasColumnType("INTEGER") + .HasColumnName("Position"); + + b1.Property("Representation") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("LibraryId", "Position") + .IsUnique(); + + b1.ToTable("LibraryPathTemplateParts", (string)null); + + b1.WithOwner() + .HasForeignKey("LibraryId"); + }); + + b.Navigation("ContentLocations"); + + b.Navigation("PathTemplateParts"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", "Library") + .WithMany("LibraryScans") + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User") + .WithMany("LibraryScans") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Library"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanResultEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", "LibraryScan") + .WithMany("LibraryScanResults") + .HasForeignKey("LibraryScanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("LibraryScan"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanSnapshotEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", "Library") + .WithMany() + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Library"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanStagingResultsEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", null) + .WithMany() + .HasForeignKey("LibraryScanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookArtworkEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany("Artwork") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookContributorEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) + .WithMany("Contributors") + .HasForeignKey("BookId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b => + { + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("BookId") + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("BookId"); + + b1.ToTable("BookRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("BookId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.IsbnEntity", "ISBNs", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("BookId") + .HasColumnType("TEXT"); + + b1.Property("Format") + .IsRequired() + .HasMaxLength(6) + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(13) + .HasColumnType("TEXT") + .HasColumnName("ISBN"); + + b1.HasKey("Id"); + + b1.HasIndex("BookId"); + + b1.ToTable("BookISBNs", (string)null); + + b1.WithOwner() + .HasForeignKey("BookId"); + }); + + b.Navigation("ISBNs"); + + b.Navigation("Ratings"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserSettingsEntity", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", null) + .WithOne() + .HasForeignKey("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserSettingsEntity", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("TrackGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", null) + .WithMany() + .HasForeignKey("TrackId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("TrackTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", null) + .WithMany() + .HasForeignKey("TrackId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b => + { + b.Navigation("RolePermissions"); + + b.Navigation("UserPermissions"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b => + { + b.Navigation("RolePermissions"); + + b.Navigation("UserRoles"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumEntity", b => + { + b.Navigation("Contributors"); + + b.Navigation("Tracks"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", b => + { + b.Navigation("Albums"); + + b.Navigation("Contributors"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", b => + { + b.Navigation("Contributors"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b => + { + b.Navigation("LibraryScans"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b => + { + b.Navigation("LibraryScanResults"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b => + { + b.Navigation("Artwork"); + + b.Navigation("Contributors"); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b => + { + b.Navigation("Libraries"); + + b.Navigation("LibraryScans"); + + b.Navigation("UserPermissions"); + + b.Navigation("UserRole"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Lumina.DataAccess/Common/Migrations/20261008064333_AddsLibraryPathTemplate.cs b/src/Lumina.DataAccess/Common/Migrations/20261008064333_AddsLibraryPathTemplate.cs new file mode 100644 index 00000000..6378425a --- /dev/null +++ b/src/Lumina.DataAccess/Common/Migrations/20261008064333_AddsLibraryPathTemplate.cs @@ -0,0 +1,146 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Lumina.DataAccess.Common.Migrations +{ + /// + public partial class AddsLibraryPathTemplate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "UpdatedOnUtc", + table: "Libraries", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 14) + .OldAnnotation("Relational:ColumnOrder", 13); + + migrationBuilder.AlterColumn( + name: "UpdatedBy", + table: "Libraries", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 15) + .OldAnnotation("Relational:ColumnOrder", 14); + + migrationBuilder.AlterColumn( + name: "CreatedOnUtc", + table: "Libraries", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 12) + .OldAnnotation("Relational:ColumnOrder", 11); + + migrationBuilder.AlterColumn( + name: "CreatedBy", + table: "Libraries", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 13) + .OldAnnotation("Relational:ColumnOrder", 12); + + migrationBuilder.AddColumn( + name: "PathTemplateFingerprint", + table: "Libraries", + type: "TEXT", + maxLength: 64, + nullable: true) + .Annotation("Relational:ColumnOrder", 11); + + migrationBuilder.CreateTable( + name: "LibraryPathTemplateParts", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Position = table.Column(type: "INTEGER", nullable: false), + Kind = table.Column(type: "TEXT", maxLength: 32, nullable: false), + Representation = table.Column(type: "TEXT", maxLength: 512, nullable: false), + IsOptional = table.Column(type: "INTEGER", nullable: false), + LibraryId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LibraryPathTemplateParts", x => x.Id); + table.ForeignKey( + name: "FK_LibraryPathTemplateParts_Libraries_LibraryId", + column: x => x.LibraryId, + principalTable: "Libraries", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_LibraryPathTemplateParts_LibraryId_Position", + table: "LibraryPathTemplateParts", + columns: new[] { "LibraryId", "Position" }, + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "LibraryPathTemplateParts"); + + migrationBuilder.DropColumn( + name: "PathTemplateFingerprint", + table: "Libraries"); + + migrationBuilder.AlterColumn( + name: "UpdatedOnUtc", + table: "Libraries", + type: "TEXT", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 13) + .OldAnnotation("Relational:ColumnOrder", 14); + + migrationBuilder.AlterColumn( + name: "UpdatedBy", + table: "Libraries", + type: "TEXT", + nullable: true, + oldClrType: typeof(Guid), + oldType: "TEXT", + oldNullable: true) + .Annotation("Relational:ColumnOrder", 14) + .OldAnnotation("Relational:ColumnOrder", 15); + + migrationBuilder.AlterColumn( + name: "CreatedOnUtc", + table: "Libraries", + type: "TEXT", + nullable: false, + oldClrType: typeof(DateTime), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 11) + .OldAnnotation("Relational:ColumnOrder", 12); + + migrationBuilder.AlterColumn( + name: "CreatedBy", + table: "Libraries", + type: "TEXT", + nullable: false, + oldClrType: typeof(Guid), + oldType: "TEXT") + .Annotation("Relational:ColumnOrder", 12) + .OldAnnotation("Relational:ColumnOrder", 13); + } + } +} diff --git a/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs b/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs index 0d628bfb..d2db1993 100644 --- a/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs +++ b/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs @@ -47,6 +47,36 @@ namespace Lumina.DataAccess.Common.Migrations b.ToTable("AlbumTags", (string)null); }); + modelBuilder.Entity("ArtistGenres", b => + { + b.Property("ArtistId") + .HasColumnType("TEXT"); + + b.Property("GenreId") + .HasColumnType("TEXT"); + + b.HasKey("ArtistId", "GenreId"); + + b.HasIndex("GenreId"); + + b.ToTable("ArtistGenres", (string)null); + }); + + modelBuilder.Entity("ArtistTags", b => + { + b.Property("ArtistId") + .HasColumnType("TEXT"); + + b.Property("TagId") + .HasColumnType("TEXT"); + + b.HasKey("ArtistId", "TagId"); + + b.HasIndex("TagId"); + + b.ToTable("ArtistTags", (string)null); + }); + modelBuilder.Entity("BookGenres", b => { b.Property("BookId") @@ -376,6 +406,11 @@ namespace Lumina.DataAccess.Common.Migrations .HasColumnType("TEXT") .HasColumnOrder(0); + b.Property("ASIN") + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(28); + b.Property("ArtistId") .HasColumnType("TEXT") .HasColumnOrder(1); @@ -383,38 +418,47 @@ namespace Lumina.DataAccess.Common.Migrations b.Property("Barcode") .HasMaxLength(13) .HasColumnType("TEXT") - .HasColumnOrder(23); - - b.Property("CatalogNumber") - .HasMaxLength(50) - .HasColumnType("TEXT") - .HasColumnOrder(24); + .HasColumnOrder(25); b.Property("CreatedBy") .HasColumnType("TEXT") - .HasColumnOrder(29); + .HasColumnOrder(33); b.Property("CreatedOnUtc") .HasColumnType("TEXT") - .HasColumnOrder(28); + .HasColumnOrder(32); b.Property("Description") .HasMaxLength(2000) .HasColumnType("TEXT") .HasColumnOrder(5); - b.Property("LanguageCode") + b.Property("Disambiguation") + .HasMaxLength(255) .HasColumnType("TEXT") - .HasColumnOrder(12); + .HasColumnOrder(6); - b.Property("LanguageName") + b.Property("Label") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(27); + + b.Property("LanguageCode") .HasColumnType("TEXT") .HasColumnOrder(13); - b.Property("LanguageNativeName") + b.Property("LanguageName") .HasColumnType("TEXT") .HasColumnOrder(14); + b.Property("LanguageNativeName") + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(37); + b.Property("LibraryId") .HasColumnType("TEXT") .HasColumnOrder(2); @@ -422,71 +466,94 @@ namespace Lumina.DataAccess.Common.Migrations b.Property("MediaFormat") .HasMaxLength(50) .HasColumnType("TEXT") - .HasColumnOrder(22); + .HasColumnOrder(23); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(38); + + b.Property("MetadataStatus") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasDefaultValue("Pending") + .HasColumnOrder(36); b.Property("MusicBrainzReleaseArtistId") .HasColumnType("TEXT") - .HasColumnOrder(27); + .HasColumnOrder(31); b.Property("MusicBrainzReleaseGroupId") .HasColumnType("TEXT") - .HasColumnOrder(26); + .HasColumnOrder(30); b.Property("MusicBrainzReleaseId") .HasColumnType("TEXT") - .HasColumnOrder(25); + .HasColumnOrder(29); b.Property("OriginalLanguageCode") .HasColumnType("TEXT") - .HasColumnOrder(15); + .HasColumnOrder(16); b.Property("OriginalLanguageName") .HasColumnType("TEXT") - .HasColumnOrder(16); + .HasColumnOrder(17); b.Property("OriginalLanguageNativeName") .HasColumnType("TEXT") - .HasColumnOrder(17); + .HasColumnOrder(18); b.Property("OriginalReleaseDate") .HasColumnType("TEXT") - .HasColumnOrder(6); + .HasColumnOrder(7); b.Property("OriginalReleaseYear") .HasColumnType("INTEGER") - .HasColumnOrder(7); + .HasColumnOrder(8); b.Property("OriginalTitle") .HasMaxLength(255) .HasColumnType("TEXT") .HasColumnOrder(4); + b.Property("Packaging") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(24); + b.Property("ReReleaseDate") .HasColumnType("TEXT") - .HasColumnOrder(8); + .HasColumnOrder(9); b.Property("ReReleaseYear") .HasColumnType("INTEGER") - .HasColumnOrder(9); + .HasColumnOrder(10); b.Property("ReleaseCountry") .HasMaxLength(2) .HasColumnType("TEXT") - .HasColumnOrder(10); + .HasColumnOrder(11); b.Property("ReleaseStatus") .HasMaxLength(50) .HasColumnType("TEXT") - .HasColumnOrder(19); + .HasColumnOrder(20); - b.Property("ReleaseType") - .HasMaxLength(50) + b.Property("ReleaseTitle") + .HasMaxLength(255) .HasColumnType("TEXT") - .HasColumnOrder(18); + .HasColumnOrder(26); b.Property("ReleaseVersion") .HasColumnType("TEXT") - .HasColumnOrder(11); + .HasColumnOrder(12); + + b.Property("Script") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(19); b.Property("Title") .IsRequired() @@ -496,19 +563,19 @@ namespace Lumina.DataAccess.Common.Migrations b.Property("TotalDiscs") .HasColumnType("INTEGER") - .HasColumnOrder(20); + .HasColumnOrder(21); b.Property("TotalTracks") .HasColumnType("INTEGER") - .HasColumnOrder(21); + .HasColumnOrder(22); b.Property("UpdatedBy") .HasColumnType("TEXT") - .HasColumnOrder(31); + .HasColumnOrder(35); b.Property("UpdatedOnUtc") .HasColumnType("TEXT") - .HasColumnOrder(30); + .HasColumnOrder(34); b.HasKey("Id"); @@ -571,21 +638,65 @@ namespace Lumina.DataAccess.Common.Migrations .HasColumnType("TEXT") .HasColumnOrder(0); + b.Property("Country") + .HasMaxLength(2) + .HasColumnType("TEXT") + .HasColumnOrder(7); + b.Property("CreatedBy") .HasColumnType("TEXT") - .HasColumnOrder(6); + .HasColumnOrder(14); b.Property("CreatedOnUtc") .HasColumnType("TEXT") - .HasColumnOrder(5); + .HasColumnOrder(13); + + b.Property("Disambiguation") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("Gender") + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(6); + + b.Property("IsEnded") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(18); b.Property("LibraryId") .HasColumnType("TEXT") .HasColumnOrder(1); + b.Property("LifeSpanBegin") + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("LifeSpanEnd") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("MetadataStatus") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasDefaultValue("Pending") + .HasColumnOrder(17); + b.Property("MusicBrainzArtistId") .HasColumnType("TEXT") - .HasColumnOrder(4); + .HasColumnOrder(12); b.Property("Name") .IsRequired() @@ -593,18 +704,28 @@ namespace Lumina.DataAccess.Common.Migrations .HasColumnType("TEXT") .HasColumnOrder(2); + b.Property("SortName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("Type") + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(5); + b.Property("UpdatedBy") .HasColumnType("TEXT") - .HasColumnOrder(8); + .HasColumnOrder(16); b.Property("UpdatedOnUtc") .HasColumnType("TEXT") - .HasColumnOrder(7); + .HasColumnOrder(15); b.Property("Website") .HasMaxLength(2048) .HasColumnType("TEXT") - .HasColumnOrder(3); + .HasColumnOrder(11); b.HasKey("Id"); @@ -614,6 +735,226 @@ namespace Lumina.DataAccess.Common.Migrations b.ToTable("Artists", (string)null); }); + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicArtworkEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("ArtworkType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("ContentHash") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("CreatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(11); + + b.Property("CreatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(10); + + b.Property("FileName") + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("LastUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(9); + + b.Property("Ordinal") + .HasColumnType("INTEGER") + .HasColumnOrder(4); + + b.Property("OwnerId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("OwnerType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.Property("Provider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("Status") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("UpdatedBy") + .HasColumnType("TEXT") + .HasColumnOrder(13); + + b.Property("UpdatedOnUtc") + .HasColumnType("TEXT") + .HasColumnOrder(12); + + b.HasKey("Id"); + + b.HasIndex("Status"); + + b.HasIndex("OwnerType", "OwnerId", "ArtworkType", "Ordinal") + .IsUnique(); + + b.ToTable("MusicArtwork", (string)null); + }); + + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicLibraryScanItemMetadataEntity", b => + { + b.Property("Id") + .HasColumnType("TEXT") + .HasColumnOrder(0); + + b.Property("AcoustId") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(25); + + b.Property("ArtistName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(4); + + b.Property("AudioCodec") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(15); + + b.Property("BitDepth") + .HasColumnType("INTEGER") + .HasColumnOrder(14); + + b.Property("Bitrate") + .HasColumnType("INTEGER") + .HasColumnOrder(16); + + b.Property("Channels") + .HasColumnType("INTEGER") + .HasColumnOrder(13); + + b.Property("DiscNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(10); + + b.Property("DurationInSeconds") + .HasColumnType("INTEGER") + .HasColumnOrder(11); + + b.Property("LibraryId") + .HasColumnType("TEXT") + .HasColumnOrder(2); + + b.Property("LibraryScanId") + .HasColumnType("TEXT") + .HasColumnOrder(1); + + b.PrimitiveCollection("Moods") + .IsRequired() + .HasColumnType("TEXT") + .HasColumnOrder(30); + + b.Property("MusicBrainzArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(17); + + b.Property("MusicBrainzRecordingId") + .HasColumnType("TEXT") + .HasColumnOrder(21); + + b.Property("MusicBrainzReleaseArtistId") + .HasColumnType("TEXT") + .HasColumnOrder(18); + + b.Property("MusicBrainzReleaseGroupId") + .HasColumnType("TEXT") + .HasColumnOrder(19); + + b.Property("MusicBrainzReleaseId") + .HasColumnType("TEXT") + .HasColumnOrder(20); + + b.Property("MusicBrainzTrackId") + .HasColumnType("TEXT") + .HasColumnOrder(22); + + b.Property("MusicBrainzWorkId") + .HasColumnType("TEXT") + .HasColumnOrder(23); + + b.Property("Path") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("TEXT") + .HasColumnOrder(3); + + b.Property("ReleaseName") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(7); + + b.Property("ReleaseType") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(5); + + b.Property("ReleaseYear") + .HasColumnType("INTEGER") + .HasColumnOrder(6); + + b.Property("ReplayGainAlbumGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(28); + + b.Property("ReplayGainAlbumPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(29); + + b.Property("ReplayGainTrackGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(26); + + b.Property("ReplayGainTrackPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(27); + + b.Property("SampleRate") + .HasColumnType("INTEGER") + .HasColumnOrder(12); + + b.Property("TrackNumber") + .HasColumnType("INTEGER") + .HasColumnOrder(9); + + b.Property("TrackTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(8); + + b.Property("WorkTitle") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(24); + + b.HasKey("Id"); + + b.HasIndex("LibraryScanId", "Path") + .IsUnique(); + + b.ToTable("MusicLibraryScanItemMetadata", (string)null); + }); + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackContributorEntity", b => { b.Property("Id") @@ -666,6 +1007,11 @@ namespace Lumina.DataAccess.Common.Migrations .HasColumnType("TEXT") .HasColumnOrder(0); + b.Property("AcoustId") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(44); + b.Property("AlbumId") .HasColumnType("TEXT") .HasColumnOrder(1); @@ -673,97 +1019,123 @@ namespace Lumina.DataAccess.Common.Migrations b.Property("AudioCodec") .HasMaxLength(50) .HasColumnType("TEXT") - .HasColumnOrder(23); + .HasColumnOrder(24); b.Property("BitDepth") .HasColumnType("INTEGER") - .HasColumnOrder(22); + .HasColumnOrder(23); b.Property("Bitrate") .HasColumnType("INTEGER") - .HasColumnOrder(24); + .HasColumnOrder(25); b.Property("Bpm") .HasColumnType("INTEGER") - .HasColumnOrder(29); + .HasColumnOrder(30); b.Property("Channels") .HasColumnType("INTEGER") - .HasColumnOrder(21); + .HasColumnOrder(22); b.Property("CreatedBy") .HasColumnType("TEXT") - .HasColumnOrder(35); + .HasColumnOrder(38); b.Property("CreatedOnUtc") .HasColumnType("TEXT") - .HasColumnOrder(34); + .HasColumnOrder(37); b.Property("Description") .HasMaxLength(2000) .HasColumnType("TEXT") .HasColumnOrder(6); + b.Property("Disambiguation") + .HasMaxLength(255) + .HasColumnType("TEXT") + .HasColumnOrder(7); + b.Property("DiscNumber") .HasColumnType("INTEGER") - .HasColumnOrder(26); + .HasColumnOrder(27); b.Property("DurationInSeconds") .HasColumnType("INTEGER") - .HasColumnOrder(19); + .HasColumnOrder(20); + + b.Property("IsVideo") + .HasColumnType("INTEGER") + .HasColumnOrder(31); b.Property("Key") .HasMaxLength(50) .HasColumnType("TEXT") - .HasColumnOrder(28); + .HasColumnOrder(29); b.Property("LanguageCode") .HasColumnType("TEXT") - .HasColumnOrder(13); + .HasColumnOrder(14); b.Property("LanguageName") .HasColumnType("TEXT") - .HasColumnOrder(14); + .HasColumnOrder(15); b.Property("LanguageNativeName") .HasColumnType("TEXT") - .HasColumnOrder(15); + .HasColumnOrder(16); + + b.Property("LastMetadataUpdateUtc") + .HasColumnType("TEXT") + .HasColumnOrder(42); b.Property("LibraryId") .HasColumnType("TEXT") .HasColumnOrder(2); + b.Property("MetadataProvider") + .HasMaxLength(100) + .HasColumnType("TEXT") + .HasColumnOrder(43); + + b.Property("MetadataStatus") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(20) + .HasColumnType("TEXT") + .HasDefaultValue("Pending") + .HasColumnOrder(41); + b.Property("MusicBrainzRecordingId") .HasColumnType("TEXT") - .HasColumnOrder(31); + .HasColumnOrder(34); b.Property("MusicBrainzTrackId") .HasColumnType("TEXT") - .HasColumnOrder(32); + .HasColumnOrder(35); b.Property("MusicBrainzWorkId") .HasColumnType("TEXT") - .HasColumnOrder(33); + .HasColumnOrder(36); b.Property("OriginalLanguageCode") .HasColumnType("TEXT") - .HasColumnOrder(16); + .HasColumnOrder(17); b.Property("OriginalLanguageName") .HasColumnType("TEXT") - .HasColumnOrder(17); + .HasColumnOrder(18); b.Property("OriginalLanguageNativeName") .HasColumnType("TEXT") - .HasColumnOrder(18); + .HasColumnOrder(19); b.Property("OriginalReleaseDate") .HasColumnType("TEXT") - .HasColumnOrder(7); + .HasColumnOrder(8); b.Property("OriginalReleaseYear") .HasColumnType("INTEGER") - .HasColumnOrder(8); + .HasColumnOrder(9); b.Property("OriginalTitle") .HasMaxLength(255) @@ -778,29 +1150,45 @@ namespace Lumina.DataAccess.Common.Migrations b.Property("ReReleaseDate") .HasColumnType("TEXT") - .HasColumnOrder(9); + .HasColumnOrder(10); b.Property("ReReleaseYear") .HasColumnType("INTEGER") - .HasColumnOrder(10); + .HasColumnOrder(11); b.Property("ReleaseCountry") .HasMaxLength(2) .HasColumnType("TEXT") - .HasColumnOrder(11); + .HasColumnOrder(12); b.Property("ReleaseVersion") .HasColumnType("TEXT") - .HasColumnOrder(12); + .HasColumnOrder(13); + + b.Property("ReplayGainAlbumGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(47); + + b.Property("ReplayGainAlbumPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(48); + + b.Property("ReplayGainTrackGain") + .HasColumnType("decimal(8,2)") + .HasColumnOrder(45); + + b.Property("ReplayGainTrackPeak") + .HasColumnType("decimal(8,6)") + .HasColumnOrder(46); b.Property("SampleRate") .HasColumnType("INTEGER") - .HasColumnOrder(20); + .HasColumnOrder(21); b.Property("Script") .HasMaxLength(50) .HasColumnType("TEXT") - .HasColumnOrder(27); + .HasColumnOrder(28); b.Property("Title") .IsRequired() @@ -810,20 +1198,25 @@ namespace Lumina.DataAccess.Common.Migrations b.Property("TrackNumber") .HasColumnType("INTEGER") - .HasColumnOrder(25); + .HasColumnOrder(26); b.Property("UpdatedBy") .HasColumnType("TEXT") - .HasColumnOrder(37); + .HasColumnOrder(40); b.Property("UpdatedOnUtc") .HasColumnType("TEXT") - .HasColumnOrder(36); + .HasColumnOrder(39); - b.Property("Work") + b.Property("WorkTitle") .HasMaxLength(255) .HasColumnType("TEXT") - .HasColumnOrder(30); + .HasColumnOrder(32); + + b.Property("WorkType") + .HasMaxLength(50) + .HasColumnType("TEXT") + .HasColumnOrder(33); b.HasKey("Id"); @@ -884,11 +1277,11 @@ namespace Lumina.DataAccess.Common.Migrations b.Property("CreatedBy") .HasColumnType("TEXT") - .HasColumnOrder(12); + .HasColumnOrder(13); b.Property("CreatedOnUtc") .HasColumnType("TEXT") - .HasColumnOrder(11); + .HasColumnOrder(12); b.Property("IsEnabled") .ValueGeneratedOnAdd() @@ -910,6 +1303,11 @@ namespace Lumina.DataAccess.Common.Migrations .HasColumnType("TEXT") .HasColumnOrder(9); + b.Property("PathTemplateFingerprint") + .HasMaxLength(64) + .HasColumnType("TEXT") + .HasColumnOrder(11); + b.Property("ShouldSaveMetadataInMediaDirectories") .HasColumnType("INTEGER") .HasColumnOrder(7); @@ -926,11 +1324,11 @@ namespace Lumina.DataAccess.Common.Migrations b.Property("UpdatedBy") .HasColumnType("TEXT") - .HasColumnOrder(14); + .HasColumnOrder(15); b.Property("UpdatedOnUtc") .HasColumnType("TEXT") - .HasColumnOrder(13); + .HasColumnOrder(14); b.Property("UserId") .HasColumnType("TEXT"); @@ -1963,6 +2361,10 @@ namespace Lumina.DataAccess.Common.Migrations .HasColumnType("INTEGER") .HasColumnOrder(3); + b.Property("ShouldAggregateArtworkWhenMissing") + .HasColumnType("INTEGER") + .HasColumnOrder(13); + b.Property("ShouldAggregateMetadataWhenMissing") .HasColumnType("INTEGER") .HasColumnOrder(10); @@ -2059,6 +2461,36 @@ namespace Lumina.DataAccess.Common.Migrations .IsRequired(); }); + modelBuilder.Entity("ArtistGenres", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", null) + .WithMany() + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null) + .WithMany() + .HasForeignKey("GenreId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ArtistTags", b => + { + b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", null) + .WithMany() + .HasForeignKey("ArtistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null) + .WithMany() + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("BookGenres", b => { b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null) @@ -2163,6 +2595,30 @@ namespace Lumina.DataAccess.Common.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumCatalogNumberEntity", "CatalogNumbers", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("AlbumId") + .HasColumnType("TEXT"); + + b1.Property("CatalogNumber") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("AlbumId"); + + b1.ToTable("AlbumCatalogNumbers", (string)null); + + b1.WithOwner() + .HasForeignKey("AlbumId"); + }); + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AudioRatingEntity", "Ratings", b1 => { b1.Property("Id") @@ -2195,9 +2651,37 @@ namespace Lumina.DataAccess.Common.Migrations .HasForeignKey("AlbumId"); }); + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AlbumReleaseTypeEntity", "ReleaseTypes", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("AlbumId") + .HasColumnType("TEXT"); + + b1.Property("ReleaseType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("AlbumId"); + + b1.ToTable("AlbumReleaseTypes", (string)null); + + b1.WithOwner() + .HasForeignKey("AlbumId"); + }); + b.Navigation("Artist"); + b.Navigation("CatalogNumbers"); + b.Navigation("Ratings"); + + b.Navigation("ReleaseTypes"); }); modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistContributorEntity", b => @@ -2209,6 +2693,238 @@ namespace Lumina.DataAccess.Common.Migrations .IsRequired(); }); + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistEntity", b => + { + b.OwnsOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicAreaEntity", "Area", b1 => + { + b1.Property("ArtistEntityId"); + + b1.Property("Disambiguation"); + + b1.Property("Iso3166Code"); + + b1.Property("MusicBrainzAreaId"); + + b1.Property("Name") + .IsRequired(); + + b1.Property("SortName"); + + b1.Property("Type"); + + b1.HasKey("ArtistEntityId"); + + b1.ToTable("Artists"); + + b1 + .ToJson("Area") + .HasColumnType("TEXT"); + + b1.WithOwner() + .HasForeignKey("ArtistEntityId"); + }); + + b.OwnsOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicAreaEntity", "BeginArea", b1 => + { + b1.Property("ArtistEntityId"); + + b1.Property("Disambiguation"); + + b1.Property("Iso3166Code"); + + b1.Property("MusicBrainzAreaId"); + + b1.Property("Name") + .IsRequired(); + + b1.Property("SortName"); + + b1.Property("Type"); + + b1.HasKey("ArtistEntityId"); + + b1.ToTable("Artists"); + + b1 + .ToJson("BeginArea") + .HasColumnType("TEXT"); + + b1.WithOwner() + .HasForeignKey("ArtistEntityId"); + }); + + b.OwnsOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.MusicAreaEntity", "EndArea", b1 => + { + b1.Property("ArtistEntityId"); + + b1.Property("Disambiguation"); + + b1.Property("Iso3166Code"); + + b1.Property("MusicBrainzAreaId"); + + b1.Property("Name") + .IsRequired(); + + b1.Property("SortName"); + + b1.Property("Type"); + + b1.HasKey("ArtistEntityId"); + + b1.ToTable("Artists"); + + b1 + .ToJson("EndArea") + .HasColumnType("TEXT"); + + b1.WithOwner() + .HasForeignKey("ArtistEntityId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistAliasEntity", "Aliases", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("BeginDate") + .HasColumnType("TEXT"); + + b1.Property("EndDate") + .HasColumnType("TEXT"); + + b1.Property("IsEnded") + .HasColumnType("INTEGER"); + + b1.Property("IsPrimary") + .HasColumnType("INTEGER"); + + b1.Property("Locale") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.Property("Name") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b1.Property("SortName") + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b1.Property("Type") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistAliases", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.AudioRatingEntity", "Ratings", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("MaxValue") + .HasColumnType("decimal(3,2)"); + + b1.Property("Source") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b1.Property("Value") + .HasColumnType("decimal(3,2)"); + + b1.Property("VoteCount") + .HasColumnType("INTEGER"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistRatings", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistIpiEntity", "Ipis", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistIpis", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.ArtistIsniEntity", "Isnis", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("ArtistId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("ArtistId"); + + b1.ToTable("ArtistIsnis", (string)null); + + b1.WithOwner() + .HasForeignKey("ArtistId"); + }); + + b.Navigation("Aliases"); + + b.Navigation("Area"); + + b.Navigation("BeginArea"); + + b.Navigation("EndArea"); + + b.Navigation("Ipis"); + + b.Navigation("Isnis"); + + b.Navigation("Ratings"); + }); + modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackContributorEntity", b => { b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackEntity", null) @@ -2307,6 +3023,63 @@ namespace Lumina.DataAccess.Common.Migrations .HasForeignKey("TrackId"); }); + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackWorkIswcEntity", "WorkIswcs", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.Property("Value") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackWorkIswcs", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary.TrackWorkLanguageEntity", "WorkLanguages", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("LanguageCode") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("TEXT"); + + b1.Property("LanguageName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b1.Property("NativeName") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b1.Property("TrackId") + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("TrackId"); + + b1.ToTable("TrackWorkLanguages", (string)null); + + b1.WithOwner() + .HasForeignKey("TrackId"); + }); + b.Navigation("Album"); b.Navigation("Isrcs"); @@ -2314,6 +3087,10 @@ namespace Lumina.DataAccess.Common.Migrations b.Navigation("Moods"); b.Navigation("Ratings"); + + b.Navigation("WorkIswcs"); + + b.Navigation("WorkLanguages"); }); modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.DirectoryScanFingerprintEntity", b => @@ -2358,8 +3135,47 @@ namespace Lumina.DataAccess.Common.Migrations .HasForeignKey("LibraryId"); }); + b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryPathTemplatePartEntity", "PathTemplateParts", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b1.Property("IsOptional") + .HasColumnType("INTEGER"); + + b1.Property("Kind") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("TEXT"); + + b1.Property("LibraryId") + .HasColumnType("TEXT"); + + b1.Property("Position") + .HasColumnType("INTEGER") + .HasColumnName("Position"); + + b1.Property("Representation") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("TEXT"); + + b1.HasKey("Id"); + + b1.HasIndex("LibraryId", "Position") + .IsUnique(); + + b1.ToTable("LibraryPathTemplateParts", (string)null); + + b1.WithOwner() + .HasForeignKey("LibraryId"); + }); + b.Navigation("ContentLocations"); + b.Navigation("PathTemplateParts"); + b.Navigation("User"); }); diff --git a/src/Lumina.DataAccess/Core/Repositories/Libraries/LibraryRepository.cs b/src/Lumina.DataAccess/Core/Repositories/Libraries/LibraryRepository.cs index c5168a61..4ecc888d 100644 --- a/src/Lumina.DataAccess/Core/Repositories/Libraries/LibraryRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/Libraries/LibraryRepository.cs @@ -64,6 +64,7 @@ internal sealed class LibraryRepository : ILibraryRepository if (shouldIncludeNavigationProperties) query = query .Include(library => library.ContentLocations) + .Include(library => library.PathTemplateParts) .AsSplitQuery(); return await query.FirstOrDefaultAsync(library => library.Id == id, cancellationToken).ConfigureAwait(false); } @@ -77,6 +78,7 @@ internal sealed class LibraryRepository : ILibraryRepository { return await _luminaDbContext.Libraries .Include(library => library.ContentLocations) + .Include(library => library.PathTemplateParts) .AsSplitQuery() .Where(library => library.IsEnabled) .ToListAsync(cancellationToken).ConfigureAwait(false); @@ -91,6 +93,7 @@ internal sealed class LibraryRepository : ILibraryRepository { return await _luminaDbContext.Libraries .Include(library => library.ContentLocations) + .Include(library => library.PathTemplateParts) .AsSplitQuery() .Where(library => library.IsEnabled && !library.IsLocked) .ToListAsync(cancellationToken).ConfigureAwait(false); @@ -116,6 +119,7 @@ internal sealed class LibraryRepository : ILibraryRepository if (shouldIncludeNavigationProperties) query = query .Include(library => library.ContentLocations) + .Include(library => library.PathTemplateParts) .AsSplitQuery(); // If no pagination was requested, return all the media libraries. @@ -161,6 +165,7 @@ internal sealed class LibraryRepository : ILibraryRepository { LibraryEntity? foundLibrary = await _luminaDbContext.Libraries .Include(library => library.ContentLocations) + .Include(library => library.PathTemplateParts) .AsSplitQuery() .FirstOrDefaultAsync(library => library.Id == data.Id, cancellationToken).ConfigureAwait(false); if (foundLibrary is null) @@ -179,6 +184,17 @@ internal sealed class LibraryRepository : ILibraryRepository shouldReplace: (existingContentLocation, incomingContentLocation) => false, createNew: incomingContentLocation => incomingContentLocation); + // A path template part is matched by its position in the template, and is replaced only when its editable values actually changed. + CollectionReconciler.Reconcile( + foundLibrary.PathTemplateParts, + data.PathTemplateParts, + existingPart => existingPart.Position, + incomingPart => incomingPart.Position, + shouldReplace: (existingPart, incomingPart) => existingPart.Kind != incomingPart.Kind + || existingPart.Representation != incomingPart.Representation + || existingPart.IsOptional != incomingPart.IsOptional, + createNew: incomingPart => incomingPart); + return Result.Updated; } @@ -192,6 +208,7 @@ internal sealed class LibraryRepository : ILibraryRepository { LibraryEntity? library = await _luminaDbContext.Libraries .Include(library => library.ContentLocations) + .Include(library => library.PathTemplateParts) .AsSplitQuery() .FirstOrDefaultAsync(library => library.Id == id, cancellationToken) .ConfigureAwait(false); diff --git a/src/Lumina.Domain.SharedKernel/Common/Enums/MediaLibrary/LibraryPathPartKind.cs b/src/Lumina.Domain.SharedKernel/Common/Enums/MediaLibrary/LibraryPathPartKind.cs new file mode 100644 index 00000000..588af99f --- /dev/null +++ b/src/Lumina.Domain.SharedKernel/Common/Enums/MediaLibrary/LibraryPathPartKind.cs @@ -0,0 +1,82 @@ +namespace Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; + +/// +/// Enumeration for the kinds of parts that make up a media library path template. +/// +public enum LibraryPathPartKind +{ + /// + /// A free text part, used for arbitrary on-disk text and for the literal glue between value parts (e.g. " - "). + /// + Literal, + + /// + /// The path separator between two directories of the library structure. + /// + Separator, + + /// + /// The name of the artist the release belongs to. + /// + Artist, + + /// + /// The type of the release (e.g. Album, Single, Compilation). + /// + ReleaseType, + + /// + /// The year the release was published. + /// + ReleaseYear, + + /// + /// The title of the release. + /// + ReleaseName, + + /// + /// The number of the track on its disc. + /// + TrackNumber, + + /// + /// The title of the track. + /// + TrackName, + + /// + /// The file name extension of the track, without the leading dot. + /// + Extension, + + /// + /// The number of the disc the track belongs to. + /// + DiscNumber, + + /// + /// The name of the author of a book. + /// + Author, + + /// + /// The title of a book. + /// + Title, + + /// + /// The name of the series a book belongs to. + /// + Series, + + /// + /// The number of the book within its series. + /// + SeriesNumber, + + /// + /// The identifier Calibre assigns to a book on disk. + /// + BookId +} diff --git a/src/Lumina.Domain.SharedKernel/Common/Enums/MediaLibrary/LibraryPathValueType.cs b/src/Lumina.Domain.SharedKernel/Common/Enums/MediaLibrary/LibraryPathValueType.cs new file mode 100644 index 00000000..8f23a3ca --- /dev/null +++ b/src/Lumina.Domain.SharedKernel/Common/Enums/MediaLibrary/LibraryPathValueType.cs @@ -0,0 +1,32 @@ +namespace Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; + +/// +/// Enumeration for the value types captured by the typed parts of a media library path template. +/// +public enum LibraryPathValueType +{ + /// + /// The part carries no captured value, like a literal or a path separator. + /// + None, + + /// + /// The part captures a free text value. + /// + Text, + + /// + /// The part captures an integer value. + /// + Integer, + + /// + /// The part captures a four digit year. + /// + Year, + + /// + /// The part captures a value that is later resolved against an enumeration. + /// + Enum +} diff --git a/src/Lumina.Domain/Common/DependencyInjection/DomainLayerServices.cs b/src/Lumina.Domain/Common/DependencyInjection/DomainLayerServices.cs index b7ce03d8..58f81171 100644 --- a/src/Lumina.Domain/Common/DependencyInjection/DomainLayerServices.cs +++ b/src/Lumina.Domain/Common/DependencyInjection/DomainLayerServices.cs @@ -6,7 +6,10 @@ using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.File using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Progress; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate; +using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Services.PathTemplate; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Scanners; +using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.PathTemplate; using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Scanners; using Microsoft.Extensions.DependencyInjection; using System.Diagnostics.CodeAnalysis; @@ -50,6 +53,9 @@ public static class DomainLayerServices services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/Lumina.Domain/Common/Errors/Errors.Library.cs b/src/Lumina.Domain/Common/Errors/Errors.Library.cs index 906b5c69..498e8d6f 100644 --- a/src/Lumina.Domain/Common/Errors/Errors.Library.cs +++ b/src/Lumina.Domain/Common/Errors/Errors.Library.cs @@ -25,5 +25,10 @@ public static partial class Errors public static Error PathsListCannotBeEmpty => Error.Validation(description: nameof(PathsListCannotBeEmpty)); public static Error TitleCannotBeEmpty => Error.Validation(description: nameof(TitleCannotBeEmpty)); public static Error TitleMustBeMaximum255CharactersLong => Error.Validation(description: nameof(TitleMustBeMaximum255CharactersLong)); + public static Error PathTemplateLiteralCannotBeEmpty => Error.Validation(description: nameof(PathTemplateLiteralCannotBeEmpty)); + public static Error PathTemplateValuePartMustContainSinglePlaceholder => Error.Validation(description: nameof(PathTemplateValuePartMustContainSinglePlaceholder)); + public static Error PathTemplateCannotContainDuplicateValuePart => Error.Validation(description: nameof(PathTemplateCannotContainDuplicateValuePart)); + public static Error PathTemplatePartKindNotSupportedForLibraryType => Error.Validation(description: nameof(PathTemplatePartKindNotSupportedForLibraryType)); + public static Error PathTemplateIsNotSupportedForLibraryType => Error.Validation(description: nameof(PathTemplateIsNotSupportedForLibraryType)); } } diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/Services/PathTemplate/MusicLibraryPathPartCatalog.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/Services/PathTemplate/MusicLibraryPathPartCatalog.cs new file mode 100644 index 00000000..83cd8493 --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/Services/PathTemplate/MusicLibraryPathPartCatalog.cs @@ -0,0 +1,69 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System.Collections.Generic; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Services.PathTemplate; + +/// +/// Catalog of the path parts available for music libraries, together with the default structure the application expects on disk. +/// +public sealed class MusicLibraryPathPartCatalog : ILibraryPathPartCatalog +{ + /// + /// Gets the media library type that this catalog supports. + /// + public LibraryType SupportedLibraryType => LibraryType.Music; + + /// + /// Gets the parts that can be used in the path template of a music library. + /// + /// The available path parts. + public IReadOnlyList GetPartDefinitions() + { + return + [ + new(LibraryPathPartKind.Literal, LibraryPathValueType.None, string.Empty, false), + new(LibraryPathPartKind.Separator, LibraryPathValueType.None, string.Empty, false), + new(LibraryPathPartKind.Artist, LibraryPathValueType.Text, "{0}", false), + new(LibraryPathPartKind.ReleaseType, LibraryPathValueType.Enum, "{0}", false), + new(LibraryPathPartKind.ReleaseYear, LibraryPathValueType.Year, "{0}", false), + new(LibraryPathPartKind.ReleaseName, LibraryPathValueType.Text, "{0}", false), + new(LibraryPathPartKind.TrackNumber, LibraryPathValueType.Integer, "{0:00}", false), + new(LibraryPathPartKind.TrackName, LibraryPathValueType.Text, "{0}", false), + new(LibraryPathPartKind.Extension, LibraryPathValueType.Text, "{0}", false), + new(LibraryPathPartKind.DiscNumber, LibraryPathValueType.Integer, "{0:00}", true) + ]; + } + + /// + /// Gets the default path template of a music library, describing the ideal structure the application expects. The disc segment is + /// optional, so that both single disc and multi disc releases are understood. + /// + /// The default path template. + public LibraryPathTemplate GetDefaultTemplate() + { + return LibraryPathTemplate.Create( + [ + LibraryPathPart.Create(LibraryPathPartKind.Artist, "{0}", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Separator, null, false).Value, + LibraryPathPart.Create(LibraryPathPartKind.ReleaseType, "{0}", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Separator, null, false).Value, + LibraryPathPart.Create(LibraryPathPartKind.ReleaseYear, "{0}", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Literal, " - ", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.ReleaseName, "{0}", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Separator, null, true).Value, + LibraryPathPart.Create(LibraryPathPartKind.Literal, "Disk ", true).Value, + LibraryPathPart.Create(LibraryPathPartKind.DiscNumber, "{0:00}", true).Value, + LibraryPathPart.Create(LibraryPathPartKind.Separator, null, false).Value, + LibraryPathPart.Create(LibraryPathPartKind.TrackNumber, "{0:00}", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Literal, " - ", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.TrackName, "{0}", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Literal, ".", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Extension, "{0}", false).Value + ]); + } +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicLibraryPathMetadata.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicLibraryPathMetadata.cs new file mode 100644 index 00000000..0a5a9f8e --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicLibraryPathMetadata.cs @@ -0,0 +1,121 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; +using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System; +using System.Collections.Generic; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects; + +/// +/// Value Object for the metadata derived from the file system path of a music library item. +/// +public class MusicLibraryPathMetadata : ValueObject +{ + /// + /// Gets the name of the artist derived from the path, if applicable. + /// + public Optional ArtistName { get; } + + /// + /// Gets the type of the release derived from the path, if applicable. + /// + public Optional ReleaseType { get; } + + /// + /// Gets the release year derived from the path, if applicable. + /// + public Optional ReleaseYear { get; } + + /// + /// Gets the name of the release derived from the path, if applicable. + /// + public Optional ReleaseName { get; } + + /// + /// Gets the number of the track derived from the path, if applicable. + /// + public Optional TrackNumber { get; } + + /// + /// Gets the number of the disc the track belongs to, derived from the path, if applicable. + /// + public Optional DiscNumber { get; } + + /// + /// Gets the title of the track derived from the path, if applicable. + /// + public Optional TrackTitle { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The name of the artist derived from the path, if applicable. + /// The type of the release derived from the path, if applicable. + /// The release year derived from the path, if applicable. + /// The name of the release derived from the path, if applicable. + /// The number of the track derived from the path, if applicable. + /// The number of the disc derived from the path, if applicable. + /// The title of the track derived from the path, if applicable. + private MusicLibraryPathMetadata( + Optional artistName, + Optional releaseType, + Optional releaseYear, + Optional releaseName, + Optional trackNumber, + Optional discNumber, + Optional trackTitle) + { + ArtistName = artistName; + ReleaseType = releaseType; + ReleaseYear = releaseYear; + ReleaseName = releaseName; + TrackNumber = trackNumber; + DiscNumber = discNumber; + TrackTitle = trackTitle; + } + + /// + /// Creates a new instance of the class from the values captured from a path template. + /// + /// The values captured from the path of the music library item. + /// The metadata derived from the captured values. + public static MusicLibraryPathMetadata FromParsedLibraryPath(ParsedLibraryPath parsedPath) + { + Optional releaseType = Optional.None(); + Optional releaseTypeValue = parsedPath.GetString(LibraryPathPartKind.ReleaseType); + if (releaseTypeValue.HasValue) + { + // An unrecognized release type folder does not prevent the rest of the path from being derived, it is simply reported as the catch-all type. + releaseType = Enum.TryParse(releaseTypeValue.Value, ignoreCase: true, out MusicReleaseType parsedReleaseType) + ? Optional.Some(parsedReleaseType) + : Optional.Some(MusicReleaseType.Other); + } + return new MusicLibraryPathMetadata( + parsedPath.GetString(LibraryPathPartKind.Artist), + releaseType, + parsedPath.GetInt(LibraryPathPartKind.ReleaseYear), + parsedPath.GetString(LibraryPathPartKind.ReleaseName), + parsedPath.GetInt(LibraryPathPartKind.TrackNumber), + parsedPath.GetInt(LibraryPathPartKind.DiscNumber), + parsedPath.GetString(LibraryPathPartKind.TrackName)); + } + + /// + /// Gets the list of items that define equality of the object. + /// + /// A list of items defining the equality. + public override IEnumerable GetEqualityComponents() + { + yield return ArtistName; + yield return ReleaseType; + yield return ReleaseYear; + yield return ReleaseName; + yield return TrackNumber; + yield return DiscNumber; + yield return TrackTitle; + } +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/Library.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/Library.cs index 91d8ee8f..b404e77d 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/Library.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/Library.cs @@ -76,6 +76,11 @@ public class Library : AggregateRoot /// public bool ShouldSkipUnchangedDirectoriesDuringScan { get; private set; } + /// + /// Gets the template describing the structure of the media library on disk, always populated, with the ideal structure of the library type as its default. + /// + public LibraryPathTemplate PathTemplate { get; private set; } + /// /// Gets the list of objects representing the file system paths that make up the media library. /// @@ -100,6 +105,7 @@ public class Library : AggregateRoot /// Whether this media library should update the metadata of its elements from the web, or not. /// Whether this media library should copy the downloaded metadata into the media library content locations, or not. /// Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. + /// The template describing the structure of the media library on disk. /// The list of objects representing the unique identifier of scans of the media library. private Library( LibraryId id, @@ -113,6 +119,7 @@ public class Library : AggregateRoot bool canDownloadMetadataFromWeb, bool shouldSaveMetadataInMediaDirectories, bool shouldSkipUnchangedDirectoriesDuringScan, + LibraryPathTemplate pathTemplate, List scanIds) : base(id) { UserId = userId; @@ -125,6 +132,7 @@ public class Library : AggregateRoot CanDownloadMetadataFromWeb = canDownloadMetadataFromWeb; ShouldSaveMetadataInMediaDirectories = shouldSaveMetadataInMediaDirectories; ShouldSkipUnchangedDirectoriesDuringScan = shouldSkipUnchangedDirectoriesDuringScan; + PathTemplate = pathTemplate; _scanIds = scanIds; } @@ -141,6 +149,7 @@ public class Library : AggregateRoot /// Whether this media library should update the metadata of its elements from the web, or not. /// Whether this media library should copy the downloaded metadata into the media library content locations, or not. /// Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. + /// The template describing the structure of the media library on disk. /// The list of objects representing the unique identifier of scans of the media library. /// /// An containing either a successfully created , or an error message. @@ -156,6 +165,7 @@ public class Library : AggregateRoot bool canDownloadMetadataFromWeb, bool shouldSaveMetadataInMediaDirectories, bool shouldSkipUnchangedDirectoriesDuringScan, + LibraryPathTemplate pathTemplate, List scanIds) { List tempContentLocations = []; @@ -179,6 +189,7 @@ public class Library : AggregateRoot canDownloadMetadataFromWeb, shouldSaveMetadataInMediaDirectories, shouldSkipUnchangedDirectoriesDuringScan, + pathTemplate, scanIds ); } @@ -197,6 +208,7 @@ public class Library : AggregateRoot /// Whether this media library should update the metadata of its elements from the web, or not. /// Whether this media library should copy the downloaded metadata into the media library content locations, or not. /// Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. + /// The template describing the structure of the media library on disk. /// The list of objects representing the unique identifier of scans of the media library. /// /// An containing either a successfully created , or an error message. @@ -213,6 +225,7 @@ public class Library : AggregateRoot bool canDownloadMetadataFromWeb, bool shouldSaveMetadataInMediaDirectories, bool shouldSkipUnchangedDirectoriesDuringScan, + LibraryPathTemplate pathTemplate, List scanIds) { List tempContentLocations = []; @@ -236,6 +249,7 @@ public class Library : AggregateRoot canDownloadMetadataFromWeb, shouldSaveMetadataInMediaDirectories, shouldSkipUnchangedDirectoriesDuringScan, + pathTemplate, scanIds ); } diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/ValueObjects/LibraryPathPart.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/ValueObjects/LibraryPathPart.cs new file mode 100644 index 00000000..7ba12252 --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/ValueObjects/LibraryPathPart.cs @@ -0,0 +1,91 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using DomainErrors = Lumina.Domain.Common.Errors.Errors; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; + +/// +/// Value Object for one part of a media library path template. +/// +/// +/// A part is either a , which renders the platform path separator, a , which renders its +/// verbatim, or a typed value part, whose is a mask that contains a single {0} placeholder where the captured value goes, +/// optionally with a fixed digit width for numeric kinds, like {0:00}. +/// +public class LibraryPathPart : ValueObject +{ + /// + /// Matches the value placeholder of a typed part, capturing the optional fixed digit width. + /// + private static readonly Regex s_placeholderRegex = new(@"\{0(?::(?0+))?\}", RegexOptions.Compiled | RegexOptions.CultureInvariant); + + /// + /// Gets the kind of the path part. + /// + public LibraryPathPartKind Kind { get; } + + /// + /// Gets the representation of the path part, which is the literal text for a literal part, and the value mask for a typed part. + /// + public string Representation { get; } + + /// + /// Gets whether the path part can be absent from the path. + /// + public bool IsOptional { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The kind of the path part. + /// The literal text or the value mask of the path part. + /// Whether the path part can be absent from the path. + private LibraryPathPart(LibraryPathPartKind kind, string representation, bool isOptional) + { + Kind = kind; + Representation = representation; + IsOptional = isOptional; + } + + /// + /// Creates a new instance of the class. + /// + /// The kind of the path part. + /// The literal text or the value mask of the path part. + /// Whether the path part can be absent from the path. + /// + /// An containing either a successfully created , or an error message. + /// + public static Result Create(LibraryPathPartKind kind, string? representation, bool isOptional) + { + // a separator carries no representation, it always renders the platform path separator. + if (kind == LibraryPathPartKind.Separator) + return new LibraryPathPart(kind, string.Empty, isOptional); + + if (string.IsNullOrWhiteSpace(representation)) + return DomainErrors.Library.PathTemplateLiteralCannotBeEmpty; + + // typed parts must carry exactly one value placeholder, so that the position of the captured value is unambiguous. + if (kind != LibraryPathPartKind.Literal && s_placeholderRegex.Matches(representation).Count != 1) + return DomainErrors.Library.PathTemplateValuePartMustContainSinglePlaceholder; + + return new LibraryPathPart(kind, representation, isOptional); + } + + /// + /// Gets the list of items that define equality of the object. + /// + /// A list of items defining the equality. + public override IEnumerable GetEqualityComponents() + { + yield return Kind; + yield return Representation; + yield return IsOptional; + } +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/ValueObjects/LibraryPathTemplate.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/ValueObjects/LibraryPathTemplate.cs new file mode 100644 index 00000000..9288f758 --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/ValueObjects/LibraryPathTemplate.cs @@ -0,0 +1,62 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Models.Core; +using System.Collections.Generic; +using System.Linq; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; + +/// +/// Value Object for the ordered sequence of parts that make up the structure of a media library on disk. +/// +public class LibraryPathTemplate : ValueObject +{ + private readonly List _parts; + + /// + /// Gets the ordered parts that make up the path template. + /// + public IReadOnlyList Parts => _parts.AsReadOnly(); + + /// + /// Gets whether the template carries no parts, which means no path derived metadata can be obtained from it. + /// + public bool IsEmpty => _parts.Count == 0; + + /// + /// Initializes a new instance of the class. + /// + /// The ordered parts that make up the path template. + private LibraryPathTemplate(List parts) + { + _parts = parts; + } + + /// + /// Creates a new instance of the class. + /// + /// The ordered parts that make up the path template. + /// The created path template. + public static LibraryPathTemplate Create(IEnumerable parts) + { + return new LibraryPathTemplate([.. parts]); + } + + /// + /// Creates an empty path template, used by the library types that have no path part catalog yet. + /// + /// The created empty path template. + public static LibraryPathTemplate Empty() + { + return new LibraryPathTemplate([]); + } + + /// + /// Gets the list of items that define equality of the object. + /// + /// A list of items defining the equality. + public override IEnumerable GetEqualityComponents() + { + return _parts; + } +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/PathTemplate/ILibraryPathPartCatalog.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/PathTemplate/ILibraryPathPartCatalog.cs new file mode 100644 index 00000000..83233fde --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/PathTemplate/ILibraryPathPartCatalog.cs @@ -0,0 +1,31 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System.Collections.Generic; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate; + +/// +/// Interface for the catalog of the path parts available for a given media library type. +/// +public interface ILibraryPathPartCatalog +{ + /// + /// Gets the media library type that this catalog supports. + /// + LibraryType SupportedLibraryType { get; } + + /// + /// Gets the parts that can be used in the path template of the supported library type. + /// + /// The available path parts. + IReadOnlyList GetPartDefinitions(); + + /// + /// Gets the default path template of the supported library type, describing the ideal structure the application expects. + /// + /// The default path template. + LibraryPathTemplate GetDefaultTemplate(); +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/PathTemplate/ILibraryPathTemplateService.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/PathTemplate/ILibraryPathTemplateService.cs new file mode 100644 index 00000000..200a21f3 --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/PathTemplate/ILibraryPathTemplateService.cs @@ -0,0 +1,42 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate; + +/// +/// Interface for the service that validates media library path templates and derives metadata from paths using them. +/// +public interface ILibraryPathTemplateService +{ + /// + /// Gets the default path template of the provided , or an empty template when the type has no path part catalog yet. + /// + /// The media library type whose default path template is retrieved. + /// The default path template. + LibraryPathTemplate GetDefaultTemplate(LibraryType libraryType); + + /// + /// Validates the provided against the catalog of the provided . + /// + /// The media library type the template belongs to. + /// The path template to validate. + /// An representing either a successful operation, or an error. + Result Validate(LibraryType libraryType, LibraryPathTemplate template); + + /// + /// Derives the metadata of a media library item from its relative path, using the provided . + /// + /// The media library type the template belongs to. + /// The path template used to parse the path. + /// The path of the media library item, relative to the root of its content location. + /// The character used to separate path segments on the current platform. + /// + /// An containing either the derived metadata, or an error. A successful result whose value is + /// means the path does not match the template. + /// + Result Parse(LibraryType libraryType, LibraryPathTemplate template, string relativePath, char pathSeparator); +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/PathTemplate/LibraryPathTemplateService.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/PathTemplate/LibraryPathTemplateService.cs new file mode 100644 index 00000000..7f255b6c --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/Services/PathTemplate/LibraryPathTemplateService.cs @@ -0,0 +1,197 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using DomainErrors = Lumina.Domain.Common.Errors.Errors; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate; + +/// +/// Validates media library path templates and derives metadata from paths using them. +/// +public sealed class LibraryPathTemplateService : ILibraryPathTemplateService +{ + /// + /// Matches the value placeholder of a typed part, capturing the optional fixed digit width. + /// + private static readonly Regex s_placeholderRegex = new(@"\{0(?::(?0+))?\}", RegexOptions.Compiled | RegexOptions.CultureInvariant); + + private readonly IReadOnlyList _catalogs; + + /// + /// Initializes a new instance of the class. + /// + /// The path part catalogs of all the supported media library types. + public LibraryPathTemplateService(IEnumerable catalogs) + { + _catalogs = [.. catalogs]; + } + + /// + /// Gets the default path template of the provided , or an empty template when the type has no path part catalog yet. + /// + /// The media library type whose default path template is retrieved. + /// The default path template. + public LibraryPathTemplate GetDefaultTemplate(LibraryType libraryType) + { + return ResolveCatalog(libraryType)?.GetDefaultTemplate() ?? LibraryPathTemplate.Empty(); + } + + /// + /// Validates the provided against the catalog of the provided . + /// + /// The media library type the template belongs to. + /// The path template to validate. + /// An representing either a successful operation, or an error. + public Result Validate(LibraryType libraryType, LibraryPathTemplate template) + { + if (template.IsEmpty) + return Result.Success; + + ILibraryPathPartCatalog? catalog = ResolveCatalog(libraryType); + if (catalog is null) + return DomainErrors.Library.PathTemplateIsNotSupportedForLibraryType; + + HashSet supportedKinds = [.. catalog.GetPartDefinitions().Select(definition => definition.Kind)]; + foreach (LibraryPathPart part in template.Parts) + if (!supportedKinds.Contains(part.Kind)) + return DomainErrors.Library.PathTemplatePartKindNotSupportedForLibraryType; + return Result.Success; + } + + /// + /// Derives the metadata of a media library item from its relative path, using the provided . + /// + /// The media library type the template belongs to. + /// The path template used to parse the path. + /// The path of the media library item, relative to the root of its content location. + /// The character used to separate path segments on the current platform. + /// + /// An containing either the derived metadata, or an error. A successful result whose value is + /// means the path does not match the template. + /// + public Result Parse(LibraryType libraryType, LibraryPathTemplate template, string relativePath, char pathSeparator) + { + if (string.IsNullOrWhiteSpace(relativePath) || template.IsEmpty) + return Result.Success(null); + + Result validationResult = Validate(libraryType, template); + if (validationResult.IsFailure) + return validationResult.Errors; + + ILibraryPathPartCatalog catalog = ResolveCatalog(libraryType)!; + Dictionary definitions = catalog.GetPartDefinitions() + .ToDictionary(definition => definition.Kind); + Regex pattern = BuildPattern(template, definitions, pathSeparator); + Match match = pattern.Match(relativePath); + if (!match.Success) + return Result.Success(null); + + Dictionary values = []; + foreach (LibraryPathPart part in template.Parts) + { + if (part.Kind == LibraryPathPartKind.Literal || part.Kind == LibraryPathPartKind.Separator) + continue; + // a kind can legitimately appear more than once, like the title and the author appearing both in the directory and in the file name, + // so the first non-empty capture is kept. + if (values.ContainsKey(part.Kind)) + continue; + Group group = match.Groups[part.Kind.ToString()]; + if (!group.Success) + continue; + string? value = group.Captures.Cast().Select(capture => capture.Value).FirstOrDefault(captured => !string.IsNullOrWhiteSpace(captured)); + if (!string.IsNullOrWhiteSpace(value)) + values[part.Kind] = value; + } + return Result.Success(ParsedLibraryPath.Create(values)); + } + + /// + /// Resolves the catalog of the provided . + /// + /// The media library type whose catalog is resolved. + /// The resolved catalog, or when the type has no catalog. + private ILibraryPathPartCatalog? ResolveCatalog(LibraryType libraryType) + { + return _catalogs.FirstOrDefault(catalog => catalog.SupportedLibraryType == libraryType); + } + + /// + /// Builds the regular expression that matches the provided . + /// + /// The path template to compile. + /// The available part definitions of the template's library type. + /// The character used to separate path segments on the current platform. + /// The compiled regular expression. + private static Regex BuildPattern(LibraryPathTemplate template, IReadOnlyDictionary definitions, char pathSeparator) + { + StringBuilder patternBuilder = new("^"); + int index = 0; + while (index < template.Parts.Count) + { + int runStart = index; + bool isOptionalRun = template.Parts[index].IsOptional; + do + { + index++; + } + while (index < template.Parts.Count && template.Parts[index].IsOptional == isOptionalRun); + + StringBuilder runBuilder = new(); + for (int runIndex = runStart; runIndex < index; runIndex++) + runBuilder.Append(BuildFragment(template.Parts[runIndex], definitions, pathSeparator)); + + if (isOptionalRun) + patternBuilder.Append("(?:").Append(runBuilder).Append(")?"); + else + patternBuilder.Append(runBuilder); + } + patternBuilder.Append('$'); + return new Regex(patternBuilder.ToString(), RegexOptions.Compiled | RegexOptions.CultureInvariant); + } + + /// + /// Builds the regular expression fragment of a single path part. + /// + /// The path part to compile. + /// The available part definitions of the template's library type. + /// The character used to separate path segments on the current platform. + /// The compiled regular expression fragment. + private static string BuildFragment(LibraryPathPart part, IReadOnlyDictionary definitions, char pathSeparator) + { + if (part.Kind == LibraryPathPartKind.Separator) + return Regex.Escape(pathSeparator.ToString()); + if (part.Kind == LibraryPathPartKind.Literal) + return Regex.Escape(part.Representation); + + LibraryPathPartDefinition definition = definitions[part.Kind]; + Match placeholder = s_placeholderRegex.Match(part.Representation); + string prefix = part.Representation[..placeholder.Index]; + string suffix = part.Representation[(placeholder.Index + placeholder.Length)..]; + Group width = placeholder.Groups["width"]; + // a fixed width narrows the capture to an exact number of digits, otherwise the base pattern of the value type is used. + string valuePattern = width.Success ? $@"\d{{{width.Value.Length}}}" : GetValuePattern(definition.ValueType); + return Regex.Escape(prefix) + $"(?<{part.Kind}>{valuePattern})" + Regex.Escape(suffix); + } + + /// + /// Gets the base regular expression pattern of the provided . + /// + /// The value type whose base pattern is retrieved. + /// The base regular expression pattern. + private static string GetValuePattern(LibraryPathValueType valueType) + { + return valueType switch + { + LibraryPathValueType.Year => @"\d{4}", + LibraryPathValueType.Integer => @"\d+", + _ => @"[^/\\]+" + }; + } +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/ValueObjects/LibraryPathPartDefinition.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/ValueObjects/LibraryPathPartDefinition.cs new file mode 100644 index 00000000..f3363a59 --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/ValueObjects/LibraryPathPartDefinition.cs @@ -0,0 +1,60 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System.Collections.Generic; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; + +/// +/// Value Object that describes one available part of a media library path template, for a given library type. +/// +public sealed class LibraryPathPartDefinition : ValueObject +{ + /// + /// Gets the kind of the described part. + /// + public LibraryPathPartKind Kind { get; } + + /// + /// Gets the value type captured by the described part. + /// + public LibraryPathValueType ValueType { get; } + + /// + /// Gets the default representation of the described part, pre-filled for the user when the part is added to a template. + /// + public string DefaultRepresentation { get; } + + /// + /// Gets whether the described part is optional by default. + /// + public bool IsOptionalByDefault { get; } + + /// + /// Initializes a new instance of the class. + /// + /// The kind of the described part. + /// The value type captured by the described part. + /// The default representation of the described part. + /// Whether the described part is optional by default. + public LibraryPathPartDefinition(LibraryPathPartKind kind, LibraryPathValueType valueType, string defaultRepresentation, bool isOptionalByDefault) + { + Kind = kind; + ValueType = valueType; + DefaultRepresentation = defaultRepresentation; + IsOptionalByDefault = isOptionalByDefault; + } + + /// + /// Gets the list of items that define equality of the object. + /// + /// A list of items defining the equality. + public override IEnumerable GetEqualityComponents() + { + yield return Kind; + yield return ValueType; + yield return DefaultRepresentation; + yield return IsOptionalByDefault; + } +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/ValueObjects/ParsedLibraryPath.cs b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/ValueObjects/ParsedLibraryPath.cs new file mode 100644 index 00000000..a71096c1 --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryScanAggregate/ValueObjects/ParsedLibraryPath.cs @@ -0,0 +1,89 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; + +/// +/// Value Object for the values captured from the relative path of a media library item, keyed by the semantic kind of the path part that produced them. +/// +public class ParsedLibraryPath : ValueObject +{ + private readonly IReadOnlyDictionary _values; + + /// + /// Gets the captured values, keyed by their part kind. + /// + public IReadOnlyDictionary Values => _values; + + /// + /// Initializes a new instance of the class. + /// + /// The captured values, keyed by their part kind. + private ParsedLibraryPath(IReadOnlyDictionary values) + { + _values = values; + } + + /// + /// Creates a new instance of the class. + /// + /// The captured values, keyed by their part kind. + /// The created parsed path. + public static ParsedLibraryPath Create(IReadOnlyDictionary values) + { + return new ParsedLibraryPath(values); + } + + /// + /// Gets the captured value of the part of the provided . + /// + /// The kind of the part whose value is retrieved. + /// An containing the captured value, or no value when the part was not captured. + public Optional GetString(LibraryPathPartKind kind) + { + return _values.TryGetValue(kind, out string? value) && !string.IsNullOrWhiteSpace(value) + ? Optional.Some(value.Trim()) + : Optional.None(); + } + + /// + /// Gets the captured integer value of the part of the provided . + /// + /// The kind of the part whose value is retrieved. + /// An containing the captured integer, or no value when the part was not captured or is not an integer. + public Optional GetInt(LibraryPathPartKind kind) + { + return _values.TryGetValue(kind, out string? value) && int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int parsed) + ? Optional.Some(parsed) + : Optional.None(); + } + + /// + /// Gets the captured values as a dictionary, for callers that need to iterate over all of them. + /// + /// The captured values keyed by part kind. + public IReadOnlyDictionary ToDictionary() + { + return _values.ToDictionary(pair => pair.Key, pair => pair.Value); + } + + /// + /// Gets the list of items that define equality of the object. + /// + /// A list of items defining the equality. + public override IEnumerable GetEqualityComponents() + { + // the captured values are stored in a dictionary, so they are ordered by their kind to keep equality independent of insertion order. + foreach (KeyValuePair capturedValue in _values.OrderBy(capturedValue => capturedValue.Key)) + { + yield return capturedValue.Key; + yield return capturedValue.Value; + } + } +} diff --git a/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/Services/PathTemplate/BookLibraryPathPartCatalog.cs b/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/Services/PathTemplate/BookLibraryPathPartCatalog.cs new file mode 100644 index 00000000..a13e622e --- /dev/null +++ b/src/Lumina.Domain/Core/BoundedContexts/WrittenContentLibraryBoundedContext/BookLibraryAggregate/Services/PathTemplate/BookLibraryPathPartCatalog.cs @@ -0,0 +1,66 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System.Collections.Generic; +#endregion + +namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.PathTemplate; + +/// +/// Catalog of the path parts available for book libraries, together with the default structure the application expects on disk. +/// +/// +/// The default structure mirrors the Calibre library layout, where each book lives in an author directory and a book directory named after +/// the title and the Calibre identifier, holding the book file named after the title and the author. +/// +public sealed class BookLibraryPathPartCatalog : ILibraryPathPartCatalog +{ + /// + /// Gets the media library type that this catalog supports. + /// + public LibraryType SupportedLibraryType => LibraryType.Book; + + /// + /// Gets the parts that can be used in the path template of a book library. + /// + /// The available path parts. + public IReadOnlyList GetPartDefinitions() + { + return + [ + new(LibraryPathPartKind.Literal, LibraryPathValueType.None, string.Empty, false), + new(LibraryPathPartKind.Separator, LibraryPathValueType.None, string.Empty, false), + new(LibraryPathPartKind.Author, LibraryPathValueType.Text, "{0}", false), + new(LibraryPathPartKind.Title, LibraryPathValueType.Text, "{0}", false), + new(LibraryPathPartKind.Series, LibraryPathValueType.Text, "{0}", true), + new(LibraryPathPartKind.SeriesNumber, LibraryPathValueType.Integer, "{0}", true), + new(LibraryPathPartKind.BookId, LibraryPathValueType.Integer, "{0}", false), + new(LibraryPathPartKind.Extension, LibraryPathValueType.Text, "{0}", false) + ]; + } + + /// + /// Gets the default path template of a book library, describing the Calibre structure the application expects. + /// + /// The default path template. + public LibraryPathTemplate GetDefaultTemplate() + { + return LibraryPathTemplate.Create( + [ + LibraryPathPart.Create(LibraryPathPartKind.Author, "{0}", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Separator, null, false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Title, "{0}", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Literal, " (", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.BookId, "{0}", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Literal, ")", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Separator, null, false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Title, "{0}", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Literal, " - ", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Author, "{0}", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Literal, ".", false).Value, + LibraryPathPart.Create(LibraryPathPartKind.Extension, "{0}", false).Value + ]); + } +} diff --git a/src/Lumina.Presentation.Api/Common/Routes/Library/Management/ApiRoutes.Libraries.cs b/src/Lumina.Presentation.Api/Common/Routes/Library/Management/ApiRoutes.Libraries.cs index 364276fa..2f6fd0de 100644 --- a/src/Lumina.Presentation.Api/Common/Routes/Library/Management/ApiRoutes.Libraries.cs +++ b/src/Lumina.Presentation.Api/Common/Routes/Library/Management/ApiRoutes.Libraries.cs @@ -28,6 +28,7 @@ public static partial class ApiRoutes public const string GET_LIBRARY_ARTWORK_PROVIDERS = "/libraries/{libraryId}/artwork-providers"; public const string SET_LIBRARY_ARTWORK_PROVIDER_ENABLED = "/libraries/{libraryId}/artwork-providers/{pluginId}/enabled"; public const string REORDER_LIBRARY_ARTWORK_PROVIDERS = "/libraries/{libraryId}/artwork-providers/reorder"; + public const string GET_LIBRARY_PATH_TEMPLATE_PARTS = "/libraries/path-template-parts/{libraryType}"; public const string GET_LIBRARY_BOOK_READERS = "/libraries/{libraryId}/book-readers"; public const string SET_LIBRARY_BOOK_READER_ENABLED = "/libraries/{libraryId}/book-readers/{pluginId}/enabled"; } diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/AddLibrary/AddLibraryEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/AddLibrary/AddLibraryEndpointSummary.cs index 4eda96e1..32ac9e8a 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/AddLibrary/AddLibraryEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/AddLibrary/AddLibraryEndpointSummary.cs @@ -36,7 +36,8 @@ public class AddLibraryEndpointSummary : Summary r.Title, "The title of the media library. Required."); @@ -48,6 +49,7 @@ public class AddLibraryEndpointSummary : Summary r.CanDownloadMetadataFromWeb, "Whether this media library should update the metadata of its elements from the web, or not. Optional."); RequestParam(r => r.ShouldSaveMetadataInMediaDirectories, "Whether this media library should copy the downloaded metadata into the media library content locations, or not. Optional."); RequestParam(r => r.ShouldSkipUnchangedDirectoriesDuringScan, "Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. Optional."); + RequestParam(r => r.PathTemplateParts, "The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent."); ResponseParam(r => r.Id, "The unique identifier of the entity."); ResponseParam(r => r.UserId, "The unique identifier of the user owning the media library."); @@ -60,6 +62,7 @@ public class AddLibraryEndpointSummary : Summary(r => r.CanDownloadMetadataFromWeb, "Whether this media library should update the metadata of its elements from the web, or not."); ResponseParam(r => r.ShouldSaveMetadataInMediaDirectories, "Whether this media library should copy the downloaded metadata into the media library content locations, or not."); ResponseParam(r => r.ShouldSkipUnchangedDirectoriesDuringScan, "Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not."); + ResponseParam(r => r.PathTemplateParts, "The ordered parts of the template describing the structure of the media library on disk."); ResponseParam(r => r.CreatedOnUtc, "The date and time when the entity was created."); ResponseParam(r => r.UpdatedOnUtc, "The date and time when the entity was last updated."); @@ -76,6 +79,7 @@ public class AddLibraryEndpointSummary : Summary(r => r.Id, "The unique identifier of the entity."); + ResponseParam(r => r.UserId, "The unique identifier of the user owning the media library."); + ResponseParam(r => r.Title, "The title of the media library."); + ResponseParam(r => r.LibraryType, "The type of the media library."); + ResponseParam(r => r.ContentLocations, "The file system paths of the directories where the media library elements are located."); + ResponseParam(r => r.CoverImage, "The path of the image file used as the cover for the library."); + ResponseParam(r => r.IsEnabled, "Whether this media library is enabled or not. A disabled media library is never shown or changed."); + ResponseParam(r => r.IsLocked, "Whether this media library is locked or not. A locked media library is displayed, but is never changed or updated."); + ResponseParam(r => r.CanDownloadMetadataFromWeb, "Whether this media library should update the metadata of its elements from the web, or not."); + ResponseParam(r => r.ShouldSaveMetadataInMediaDirectories, "Whether this media library should copy the downloaded metadata into the media library content locations, or not."); + ResponseParam(r => r.ShouldSkipUnchangedDirectoriesDuringScan, "Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not."); + ResponseParam(r => r.PathTemplateParts, "The ordered parts of the template describing the structure of the media library on disk."); + ResponseParam(r => r.CreatedOnUtc, "The date and time when the entity was created."); + ResponseParam(r => r.UpdatedOnUtc, "The date and time when the entity was last updated."); + Response(200, "The media libraries are returned.", example: new LibraryResponse[] { new ( @@ -36,6 +51,7 @@ public class GetEnabledLibrariesEndpointSummary : Summary(r => r.Id, "The unique identifier of the entity."); + ResponseParam(r => r.UserId, "The unique identifier of the user owning the media library."); + ResponseParam(r => r.Title, "The title of the media library."); + ResponseParam(r => r.LibraryType, "The type of the media library."); + ResponseParam(r => r.ContentLocations, "The file system paths of the directories where the media library elements are located."); + ResponseParam(r => r.CoverImage, "The path of the image file used as the cover for the library."); + ResponseParam(r => r.IsEnabled, "Whether this media library is enabled or not. A disabled media library is never shown or changed."); + ResponseParam(r => r.IsLocked, "Whether this media library is locked or not. A locked media library is displayed, but is never changed or updated."); + ResponseParam(r => r.CanDownloadMetadataFromWeb, "Whether this media library should update the metadata of its elements from the web, or not."); + ResponseParam(r => r.ShouldSaveMetadataInMediaDirectories, "Whether this media library should copy the downloaded metadata into the media library content locations, or not."); + ResponseParam(r => r.ShouldSkipUnchangedDirectoriesDuringScan, "Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not."); + ResponseParam(r => r.PathTemplateParts, "The ordered parts of the template describing the structure of the media library on disk."); + ResponseParam(r => r.CreatedOnUtc, "The date and time when the entity was created."); + ResponseParam(r => r.UpdatedOnUtc, "The date and time when the entity was last updated."); + Response(200, "The media libraries are returned.", example: new LibraryResponse[] { new ( @@ -36,6 +51,7 @@ public class GetLibrariesEndpointSummary : Summary(r => r.CanDownloadMetadataFromWeb, "Whether this media library should update the metadata of its elements from the web, or not."); ResponseParam(r => r.ShouldSaveMetadataInMediaDirectories, "Whether this media library should copy the downloaded metadata into the media library content locations, or not."); ResponseParam(r => r.ShouldSkipUnchangedDirectoriesDuringScan, "Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not."); + ResponseParam(r => r.PathTemplateParts, "The ordered parts of the template describing the structure of the media library on disk."); ResponseParam(r => r.CreatedOnUtc, "The date and time when the entity was created."); ResponseParam(r => r.UpdatedOnUtc, "The date and time when the entity was last updated."); @@ -56,6 +57,7 @@ public class GetLibraryEndpointSummary : Summary +/// API endpoint for the /libraries/path-template-parts/{libraryType} route. +/// +public class GetLibraryPathTemplatePartsEndpoint : BaseEndpoint +{ + private readonly IQueryHandler> _getLibraryPathTemplatePartsQueryHandler; + + /// + /// Initializes a new instance of the class. + /// + /// Injected service for handling get library path template parts queries. + public GetLibraryPathTemplatePartsEndpoint(IQueryHandler> getLibraryPathTemplatePartsQueryHandler) + { + _getLibraryPathTemplatePartsQueryHandler = getLibraryPathTemplatePartsQueryHandler; + } + + /// + /// Configures the API endpoint. + /// + public override void Configure() + { + Verbs(Http.GET); + Routes(ApiRoutes.Libraries.GET_LIBRARY_PATH_TEMPLATE_PARTS); + Version(1); + DontCatchExceptions(); + } + + /// + /// Gets the path parts available for a media library type. + /// + /// The request containing the media library type whose available path parts are retrieved. + /// Cancellation token that can be used to stop the execution. + public override async Task ExecuteAsync(GetLibraryPathTemplatePartsRequest request, CancellationToken cancellationToken) + { + Result result = await _getLibraryPathTemplatePartsQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false); + return result.Match(success => TypedResults.Ok(success), Problem); + } +} diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/UpdateLibrary/UpdateLibraryEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/UpdateLibrary/UpdateLibraryEndpointSummary.cs index d6cc49d1..89f3c3f9 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/UpdateLibrary/UpdateLibraryEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/Management/UpdateLibrary/UpdateLibraryEndpointSummary.cs @@ -38,7 +38,8 @@ public class UpdateLibraryEndpointSummary : Summary r.Id, "The unique identifier of the media library. Required."); @@ -52,6 +53,7 @@ public class UpdateLibraryEndpointSummary : Summary r.CanDownloadMetadataFromWeb, "Whether this media library should update the metadata of its elements from the web, or not. Optional."); RequestParam(r => r.ShouldSaveMetadataInMediaDirectories, "Whether this media library should copy the downloaded metadata into the media library content locations, or not. Optional."); RequestParam(r => r.ShouldSkipUnchangedDirectoriesDuringScan, "Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not. Optional."); + RequestParam(r => r.PathTemplateParts, "The ordered parts of the template describing the structure of the media library on disk. Optional, the ideal structure of the library type is used when absent."); ResponseParam(r => r.Id, "The unique identifier of the entity."); ResponseParam(r => r.UserId, "The unique identifier of the user owning the media library."); @@ -64,6 +66,7 @@ public class UpdateLibraryEndpointSummary : Summary(r => r.CanDownloadMetadataFromWeb, "Whether this media library should update the metadata of its elements from the web, or not."); ResponseParam(r => r.ShouldSaveMetadataInMediaDirectories, "Whether this media library should copy the downloaded metadata into the media library content locations, or not."); ResponseParam(r => r.ShouldSkipUnchangedDirectoriesDuringScan, "Whether this media library should skip the directories whose contents have not changed since the last scan, during the scan, or not."); + ResponseParam(r => r.PathTemplateParts, "The ordered parts of the template describing the structure of the media library on disk."); ResponseParam(r => r.CreatedOnUtc, "The date and time when the entity was created."); ResponseParam(r => r.UpdatedOnUtc, "The date and time when the entity was last updated."); @@ -80,6 +83,7 @@ public class UpdateLibraryEndpointSummary : Summary public bool ShouldSkipUnchangedDirectoriesDuringScan { get; set; } = false; + + /// + /// Gets or sets the ordered parts of the template describing the structure of the media library on disk. + /// + public List PathTemplateParts { get; set; } = []; } diff --git a/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryPathPartDefinitionDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryPathPartDefinitionDto.cs new file mode 100644 index 00000000..b7300ea5 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryPathPartDefinitionDto.cs @@ -0,0 +1,32 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Libraries; + +/// +/// Data transfer object for a path part available for a media library type. +/// +[DebuggerDisplay("Kind: {Kind}")] +public class LibraryPathPartDefinitionDto +{ + /// + /// Gets or sets the kind of the path part. + /// + public string Kind { get; set; } = string.Empty; + + /// + /// Gets or sets the value type captured by the path part. + /// + public string ValueType { get; set; } = string.Empty; + + /// + /// Gets or sets the default representation of the path part. + /// + public string DefaultRepresentation { get; set; } = string.Empty; + + /// + /// Gets or sets whether the path part is optional by default. + /// + public bool IsOptionalByDefault { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryPathTemplateCatalogDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryPathTemplateCatalogDto.cs new file mode 100644 index 00000000..9e2c9509 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryPathTemplateCatalogDto.cs @@ -0,0 +1,23 @@ +#region ========================================================================= USING ===================================================================================== +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Libraries; + +/// +/// Data transfer object for the path template catalog of a media library type. +/// +[DebuggerDisplay("Parts: {Parts.Count}; DefaultTemplateParts: {DefaultTemplateParts.Count}")] +public class LibraryPathTemplateCatalogDto +{ + /// + /// Gets or sets the path parts that can be used in the path template of the library type. + /// + public List Parts { get; set; } = []; + + /// + /// Gets or sets the ordered parts of the default path template of the library type. + /// + public List DefaultTemplateParts { get; set; } = []; +} diff --git a/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryPathTemplatePartDto.cs b/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryPathTemplatePartDto.cs new file mode 100644 index 00000000..ef68c908 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/DTO/Libraries/LibraryPathTemplatePartDto.cs @@ -0,0 +1,27 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.DTO.Libraries; + +/// +/// Data transfer object for one part of the path template of a media library. +/// +[DebuggerDisplay("Kind: {Kind}; Representation: {Representation}")] +public class LibraryPathTemplatePartDto +{ + /// + /// Gets or sets the kind of the path part. + /// + public string Kind { get; set; } = string.Empty; + + /// + /// Gets or sets the literal text or the value mask of the path part. + /// + public string Representation { get; set; } = string.Empty; + + /// + /// Gets or sets whether the path part can be absent from the path. + /// + public bool IsOptional { get; set; } +} diff --git a/src/Lumina.Presentation.Web/Common/Requests/Library/Management/GetLibraryPathTemplatePartsRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/Library/Management/GetLibraryPathTemplatePartsRequest.cs new file mode 100644 index 00000000..978d481a --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/Library/Management/GetLibraryPathTemplatePartsRequest.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.Library.Management; + +/// +/// Represents the request for retrieving the path parts available for a media library type. +/// +/// The media library type whose available path parts are retrieved. Required. +[DebuggerDisplay("LibraryType: {LibraryType}")] +public record GetLibraryPathTemplatePartsRequest( + string LibraryType +); diff --git a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Libraries.cs b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Libraries.cs index 63f358f4..64ebcdc6 100644 --- a/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Libraries.cs +++ b/src/Lumina.Presentation.Web/Common/Routes/ApiRoutes.Libraries.cs @@ -21,6 +21,7 @@ public static partial class ApiRoutes public const string GET_RUNNING_LIBRARIES_SCAN = "libraries/scans/running"; public const string CANCEL_LIBRARIES_SCAN = "libraries/scans/cancel"; public const string CANCEL_LIBRARY_SCAN = "libraries/{libraryId}/scans/{scanId}/cancel"; + public const string GET_LIBRARY_PATH_TEMPLATE_PARTS = "libraries/path-template-parts/{libraryType}"; public const string GET_LIBRARY_METADATA_PROVIDERS = "libraries/{libraryId}/metadata-providers"; public const string SET_LIBRARY_METADATA_PROVIDER_ENABLED = "libraries/{libraryId}/metadata-providers/{pluginId}/enabled"; public const string REORDER_LIBRARY_METADATA_PROVIDERS = "libraries/{libraryId}/metadata-providers/reorder"; diff --git a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.LibraryManagement.cs b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.LibraryManagement.cs index dd582a50..d89cf6a3 100644 --- a/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.LibraryManagement.cs +++ b/src/Lumina.Presentation.Web/Common/Routes/WebRoutes.LibraryManagement.cs @@ -22,6 +22,7 @@ public static partial class WebRoutes public const string SCAN_LIBRARY = "{culture}/libraries/manage/api-scan-library/{id}"; public const string CANCEL_LIBRARIES_SCAN = "{culture}/libraries/manage/api-cancel-libraries-scan"; public const string CANCEL_LIBRARY_SCAN = "{culture}/libraries/manage/{libraryId}/api-cancel-library-scan/{scanId}"; + public const string GET_LIBRARY_PATH_TEMPLATE_PARTS = "{culture}/libraries/manage/api-get-path-template-parts/{libraryType}"; public const string GET_METADATA_PROVIDERS = "{culture}/libraries/manage/api-get-metadata-providers/{libraryId}"; public const string SET_METADATA_PROVIDER_ENABLED = "{culture}/libraries/manage/api-set-metadata-provider-enabled"; public const string REORDER_METADATA_PROVIDERS = "{culture}/libraries/manage/api-reorder-metadata-providers"; diff --git a/src/Lumina.Presentation.Web/Core/Endpoints/Library/Management/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsEndpoint.cs b/src/Lumina.Presentation.Web/Core/Endpoints/Library/Management/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsEndpoint.cs new file mode 100644 index 00000000..658ef01f --- /dev/null +++ b/src/Lumina.Presentation.Web/Core/Endpoints/Library/Management/GetLibraryPathTemplateParts/GetLibraryPathTemplatePartsEndpoint.cs @@ -0,0 +1,54 @@ +#region ========================================================================= USING ===================================================================================== +using FastEndpoints; +using Lumina.Presentation.Web.Common.Api; +using Lumina.Presentation.Web.Common.DTO.Libraries; +using Lumina.Presentation.Web.Common.Requests.Library.Management; +using Lumina.Presentation.Web.Common.Routes; +using Lumina.Presentation.Web.Core.Endpoints.Common; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Web.Core.Endpoints.Library.Management.GetLibraryPathTemplateParts; + +/// +/// API endpoint for the /{culture}/libraries/manage/api-get-path-template-parts/{libraryType} route. +/// +public class GetLibraryPathTemplatePartsEndpoint : BaseEndpoint +{ + private readonly IApiHttpClient _apiHttpClient; + + /// + /// Initializes a new instance of the class. + /// + /// Injected service for interactions with the API. + public GetLibraryPathTemplatePartsEndpoint(IApiHttpClient apiHttpClient) + { + _apiHttpClient = apiHttpClient; + } + + /// + /// Configures the endpoint. + /// + public override void Configure() + { + base.Configure(); + Verbs(Http.GET); + Routes(WebRoutes.LibraryManagement.GET_LIBRARY_PATH_TEMPLATE_PARTS); + DontAutoTag(); + Options(options => options.WithTags("Libraries")); + } + + /// + /// Retrieves the path parts available for a media library type. + /// + /// The request containing the media library type whose available path parts are retrieved. + /// Cancellation token that can be used to stop the execution. + public override async Task ExecuteAsync(GetLibraryPathTemplatePartsRequest request, CancellationToken cancellationToken) + { + LibraryPathTemplateCatalogDto response = await _apiHttpClient.GetAsync(ApiRoutes.Libraries.GET_LIBRARY_PATH_TEMPLATE_PARTS.Replace("{libraryType}", request.LibraryType), cancellationToken).ConfigureAwait(false); + return JsonSuccess(response); + } +} diff --git a/src/Lumina.Presentation.Web/Core/Resources/Views/Library/Management/Item.ar-SA.resx b/src/Lumina.Presentation.Web/Core/Resources/Views/Library/Management/Item.ar-SA.resx index 741a2000..d02b272f 100644 --- a/src/Lumina.Presentation.Web/Core/Resources/Views/Library/Management/Item.ar-SA.resx +++ b/src/Lumina.Presentation.Web/Core/Resources/Views/Library/Management/Item.ar-SA.resx @@ -1,4 +1,4 @@ - + -
+
+
@@ -34,7 +34,7 @@

@_localizer["GeneralInformation"]

- +
@@ -45,7 +45,7 @@
@_localizer["DescriptionTitle"]
- +
@@ -77,25 +77,25 @@
@_localizer["Movie"]
@_localizer["FilmSeries"]
@_localizer["FilmFranchise"]
-
@_localizer["Concert"]
+
@_localizer["Concert"]
@_localizer["Documentary"]
-
@_localizer["Tutorial"]
-
@_localizer["Personal"]
+
@_localizer["Tutorial"]
+
@_localizer["Personal"]
@_localizer["Anime"]
-
@_localizer["Youtube"]
-
@_localizer["Videoclip"]
+
@_localizer["Youtube"]
+
@_localizer["Videoclip"]
@_localizer["AudioContent"]
@_localizer["Music"]
-
@_localizer["AudioBook"]
-
@_localizer["LivePerformance"]
-
@_localizer["Interview"]
-
@_localizer["Cover"]
+
@_localizer["AudioBook"]
+
@_localizer["LivePerformance"]
+
@_localizer["Interview"]
+
@_localizer["Cover"]
@_localizer["Remix"]
-
@_localizer["Soundeffect"]
-
@_localizer["Podcast"]
+
@_localizer["Soundeffect"]
+
@_localizer["Podcast"]
@_localizer["RadioShow"]
@_localizer["VisualContent"]
-
@_localizer["PhotoAlbum"]
+
@_localizer["PhotoAlbum"]
@_localizer["MiscellaneousContent"]
@_localizer["Other"]
@@ -103,7 +103,7 @@
@_localizer["DescriptionLibraryType"]
- +
: @@ -122,7 +122,7 @@
@_localizer["DescriptionCover"]
- +
@@ -204,6 +204,38 @@
@_localizer["DescriptionShouldSkipUnchangedDirectoriesDuringScan"]
+ + + + @if (id is not null) {

@_localizer["MetadataProviders"]

@@ -217,7 +249,7 @@ - + @_localizer["DescriptionMetadataProviders"] @@ -233,7 +265,7 @@ - + @_localizer["DescriptionArtworkProviders"] @@ -249,7 +281,7 @@ - + @_localizer["DescriptionBookReaders"] @@ -260,7 +292,7 @@
- +
@@ -307,7 +339,15 @@ IsLocked: chkIsLocked.checked, CanDownloadMetadataFromWeb: chkCanDownloadMetadataFromWeb.checked, ShouldSaveMetadataInMediaDirectories: chkShouldSaveMetadataInMediaDirectories.checked, - ShouldSkipUnchangedDirectoriesDuringScan: chkShouldSkipUnchangedDirectoriesDuringScan.checked + ShouldSkipUnchangedDirectoriesDuringScan: chkShouldSkipUnchangedDirectoriesDuringScan.checked, + PathTemplateParts: Array.from(pathTemplateDropzone.querySelectorAll('.path-template-pill')).map(pill => { + const optional = pill.querySelector('.path-template-optional'); + return { + Kind: pill.dataset.kind, + Representation: getPathTemplatePillRepresentation(pill), + IsOptional: optional ? optional.checked : false + }; + }) }; const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl(WebRoutes.LibraryManagement.SAVE_LIBRARY)', formData); if (data) { @@ -404,7 +444,7 @@ async function loadMetadataProvidersAsync() { if (!id || !metadataProvidersTbody) return; const url = '@_urlService.GetAbsoluteUrl(WebRoutes.LibraryManagement.GET_METADATA_PROVIDERS, new { libraryId = default(Guid) })' - .replace('/@(default(Guid))', `/${id}`); // libraryId needs to be replaced here, because GetAbsoluteUrl is server side, libraryId is client side. + .replace('/@(default(Guid))', `/${id}`); // The libraryId needs to be replaced here, because GetAbsoluteUrl is server side, libraryId is client side. const response = await callApiGetAsync(url); if (response && response.length > 0) { metadataProvidersTbody.innerHTML = response.map((provider, index) => renderMetadataProviderRow(provider, index, response.length)).join(''); @@ -475,7 +515,7 @@ async function loadArtworkProvidersAsync() { if (!id || !artworkProvidersTbody) return; const url = '@_urlService.GetAbsoluteUrl(WebRoutes.LibraryManagement.GET_ARTWORK_PROVIDERS, new { libraryId = default(Guid) })' - .replace('/@(default(Guid))', `/${id}`); // libraryId needs to be replaced here, because GetAbsoluteUrl is server side, libraryId is client side. + .replace('/@(default(Guid))', `/${id}`); // The libraryId needs to be replaced here, because GetAbsoluteUrl is server side, libraryId is client side. const response = await callApiGetAsync(url); if (response && response.length > 0) { artworkProvidersTbody.innerHTML = response.map((provider, index) => renderArtworkProviderRow(provider, index, response.length)).join(''); @@ -546,7 +586,7 @@ async function loadBookReadersAsync() { if (!id || !bookReadersTbody) return; const url = '@_urlService.GetAbsoluteUrl(WebRoutes.LibraryManagement.GET_BOOK_READERS, new { libraryId = default(Guid) })' - .replace('/@(default(Guid))', `/${id}`); // libraryId needs to be replaced here, because GetAbsoluteUrl is server side, libraryId is client side. + .replace('/@(default(Guid))', `/${id}`); // The libraryId needs to be replaced here, because GetAbsoluteUrl is server side, libraryId is client side. const response = await callApiGetAsync(url); if (response && response.length > 0) { bookReadersTbody.innerHTML = response.map(reader => renderBookReaderRow(reader)).join(''); @@ -582,6 +622,340 @@ } }; + // Path template editor. + const pathTemplateSection = document.getElementById('path-template-section'); + const pathTemplatePalette = document.getElementById('path-template-palette'); + const pathTemplateDropzone = document.getElementById('path-template-dropzone'); + const pathTemplatePreviewValue = document.getElementById('path-template-preview-value'); + const libraryTypeSelectedItem = document.getElementById('library-selected-item'); + // The type the library was loaded with, so that the saved template is only restored for it, and not when the user previews other types. + const initialLibraryType = libraryTypeSelectedItem ? libraryTypeSelectedItem.getAttribute('data-value') : null; + const libraryTypeDropdown = form.querySelector('.enlightenment-combobox .enlightenment-dropdown'); + const pathSeparator = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(System.IO.Path.DirectorySeparatorChar.ToString())); + const savedPathTemplateParts = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(Model.PathTemplateParts, new System.Text.Json.JsonSerializerOptions { PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase })); + // The localized strings used inside this script must be injected as JSON, not as raw HTML text: Razor HTML-encodes non-ASCII + // characters into numeric entities (e.g. "ă" becomes "ă"), and the browser does not decode entities inside a + // script element, so they would show up literally. JSON escapes them as \uXXXX, which the script reads correctly. + const pathPartLabels = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(new System.Collections.Generic.Dictionary + { + ["Literal"] = _localizer["PathPartLiteral"].Value, + ["Separator"] = _localizer["PathPartSeparator"].Value, + ["Artist"] = _localizer["PathPartArtist"].Value, + ["ReleaseType"] = _localizer["PathPartReleaseType"].Value, + ["ReleaseYear"] = _localizer["PathPartReleaseYear"].Value, + ["ReleaseName"] = _localizer["PathPartReleaseName"].Value, + ["TrackNumber"] = _localizer["PathPartTrackNumber"].Value, + ["TrackName"] = _localizer["PathPartTrackName"].Value, + ["Extension"] = _localizer["PathPartExtension"].Value, + ["DiscNumber"] = _localizer["PathPartDiscNumber"].Value, + ["Author"] = _localizer["PathPartAuthor"].Value, + ["Title"] = _localizer["PathPartTitle"].Value, + ["Series"] = _localizer["PathPartSeries"].Value, + ["SeriesNumber"] = _localizer["PathPartSeriesNumber"].Value, + ["BookId"] = _localizer["PathPartBookId"].Value + })); + const pathTemplateStrings = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(new System.Collections.Generic.Dictionary + { + ["optional"] = _localizer["PathPartOptional"].Value, + ["remove"] = _localizer["Remove"].Value, + ["literal"] = _localizer["PathPartLiteralPlaceholder"].Value, + ["digits"] = _localizer["PathPartDigits"].Value + })); + // The preview shows an example path built from a real example of each library type, so the user sees the effect of the template. + const pathTemplateSamples = { + Music: { + Artist: 'QUEEN', + ReleaseType: 'Album', + ReleaseYear: '1975', + ReleaseName: 'A night at the opera', + TrackNumber: '11', + TrackName: 'Bohemian rhapsody', + DiscNumber: '1', + Extension: 'mp3' + }, + Book: { + Author: 'J. R. R. Tolkien', + Title: 'The Fellowship of the Ring', + Series: 'The Lord of the Rings', + SeriesNumber: '1', + BookId: '42', + Extension: 'epub' + } + }; + let currentPathTemplateSample = {}; + const pathTemplateCatalogCache = {}; + const pathPartValueTypes = {}; + let draggedPathTemplatePill = null; + + // Gets the localized display name of a path part kind. + function pathTemplateKindLabel(kind) { + return pathPartLabels[kind] || kind; + } + + // Parses a value mask like "Disc {0:00}" into its literal prefix, digit width, and literal suffix. + function parsePathTemplateMask(representation) { + const match = (representation || '').match(/^(.*)\{0(?::(0+))?\}(.*)$/); + if (!match) + return { prefix: representation || '', width: 0, suffix: '' }; + return { prefix: match[1], width: match[2] ? match[2].length : 0, suffix: match[3] }; + } + + // Rebuilds a value mask from its literal prefix, digit width, and literal suffix. + function buildPathTemplateMask(prefix, width, suffix) { + return (prefix || '') + '{0' + (width > 0 ? ':' + '0'.repeat(width) : '') + '}' + (suffix || ''); + } + + // Creates an editable pill for one part of the path template, as it is placed in the drop zone. + function renderPathTemplatePill(part) { + const pill = document.createElement('div'); + pill.className = 'path-template-pill'; + pill.setAttribute('draggable', 'true'); + pill.dataset.kind = part.kind; + pill.title = pathTemplateKindLabel(part.kind); + + // The human readable name of the part, so the user knows what each pill means. + const label = document.createElement('span'); + label.className = 'path-template-part-label'; + label.textContent = pathTemplateKindLabel(part.kind); + pill.appendChild(label); + + if (part.kind === 'Separator') { + // A folder separator is shown as its own glyph, never as a raw mask. + const separator = document.createElement('span'); + separator.className = 'path-template-separator-chip'; + separator.textContent = pathSeparator; + pill.appendChild(separator); + } else if (part.kind === 'Literal') { + // An arbitrary text segment, like the "Disk " glue, is edited directly. + const input = document.createElement('input'); + input.type = 'text'; + input.className = 'enlightenment-input path-template-literal-input'; + input.value = part.representation || ''; + input.placeholder = pathTemplateStrings.literal; + input.addEventListener('input', updatePathTemplatePreview); + pill.appendChild(input); + } else { + // Numeric parts can be told how many digits they always use, so values like "01" are understood. + if (pathPartValueTypes[part.kind] === 'Integer') { + const parsed = parsePathTemplateMask(part.representation); + const widthInput = document.createElement('input'); + widthInput.type = 'number'; + widthInput.min = '0'; + widthInput.max = '10'; + widthInput.className = 'enlightenment-input path-template-width'; + widthInput.value = parsed.width; + widthInput.title = pathTemplateStrings.digits; + widthInput.placeholder = pathTemplateStrings.digits; + widthInput.addEventListener('input', updatePathTemplatePreview); + pill.appendChild(widthInput); + } + } + + const optionalLabel = document.createElement('label'); + optionalLabel.className = 'enlightenment-checkbox-label'; + optionalLabel.title = pathTemplateStrings.optional; + const optionalInput = document.createElement('input'); + optionalInput.type = 'checkbox'; + optionalInput.className = 'enlightenment-checkbox-hidden path-template-optional'; + optionalInput.checked = !!part.isOptional; + optionalInput.addEventListener('change', updatePathTemplatePreview); + const optionalSpan = document.createElement('span'); + optionalSpan.className = 'enlightenment-checkbox'; + optionalLabel.appendChild(optionalInput); + optionalLabel.appendChild(optionalSpan); + pill.appendChild(optionalLabel); + const remove = document.createElement('img'); + remove.src = '/images/ui/delete.svg'; + remove.alt = pathTemplateStrings.remove; + remove.title = pathTemplateStrings.remove; + remove.className = 'path-template-remove'; + remove.addEventListener('click', () => { pill.remove(); updatePathTemplatePreview(); }); + pill.appendChild(remove); + pill.addEventListener('dragstart', (e) => { + draggedPathTemplatePill = pill; + e.dataTransfer.effectAllowed = 'move'; + e.dataTransfer.setData('text/plain', 'pill'); + }); + pill.addEventListener('dragend', () => { draggedPathTemplatePill = null; clearPathTemplateDropIndicator(); }); + return pill; + } + + // Builds the stored representation mask of a pill from its human friendly editors. + function getPathTemplatePillRepresentation(pill) { + const kind = pill.dataset.kind; + if (kind === 'Separator') + return ''; + if (kind === 'Literal') { + const input = pill.querySelector('.path-template-literal-input'); + return input ? input.value : ''; + } + const width = pill.querySelector('.path-template-width'); + return buildPathTemplateMask('', width ? Math.max(0, parseInt(width.value || '0', 10)) : 0, ''); + } + + // Replaces the parts in the drop zone with the provided parts. + function renderPathTemplateParts(parts) { + if (!pathTemplateDropzone) return; + pathTemplateDropzone.innerHTML = ''; + (parts || []).forEach(part => pathTemplateDropzone.appendChild(renderPathTemplatePill(part))); + updatePathTemplatePreview(); + } + + // Renders the palette of the parts that can be added to the path template. + function renderPathTemplatePalette(parts) { + if (!pathTemplatePalette) return; + pathTemplatePalette.innerHTML = ''; + (parts || []).forEach(definition => { + const pill = document.createElement('div'); + pill.className = 'path-template-palette-pill'; + pill.setAttribute('draggable', 'true'); + pill.textContent = pathTemplateKindLabel(definition.kind); + pill.addEventListener('dragstart', (e) => { + e.dataTransfer.effectAllowed = 'copy'; + e.dataTransfer.setData('application/json', JSON.stringify({ + source: 'palette', + kind: definition.kind, + representation: definition.defaultRepresentation, + isOptional: definition.isOptionalByDefault + })); + }); + pathTemplatePalette.appendChild(pill); + }); + } + + // Formats the sample value of a part according to its mask, for the preview. + function formatPathTemplateValue(representation, value) { + const match = representation.match(/\{0(?::(0+))?\}/); + if (!match) + return representation + value; + const formatted = match[1] ? String(value).padStart(match[1].length, '0') : value; + return representation.slice(0, match.index) + formatted + representation.slice(match.index + match[0].length); + } + + // Rebuilds the preview path from the pills currently in the drop zone. + function updatePathTemplatePreview() { + if (!pathTemplatePreviewValue || !pathTemplateDropzone) return; + let result = ''; + pathTemplateDropzone.querySelectorAll('.path-template-pill').forEach(pill => { + const kind = pill.dataset.kind; + if (kind === 'Separator') { result += pathSeparator; return; } + const representation = getPathTemplatePillRepresentation(pill); + if (kind === 'Literal') { result += representation; return; } + result += formatPathTemplateValue(representation, currentPathTemplateSample[kind] || ''); + }); + pathTemplatePreviewValue.textContent = result; + } + + // Loads the path template catalog of the selected library type, and the template to display in the editor. + async function loadPathTemplateAsync() { + if (!libraryTypeSelectedItem || !pathTemplateDropzone) return; + const libraryType = libraryTypeSelectedItem.getAttribute('data-value'); + if (!libraryType) return; + currentPathTemplateSample = pathTemplateSamples[libraryType] || {}; + let catalog = pathTemplateCatalogCache[libraryType]; + if (!catalog) { + const url = '@_urlService.GetAbsoluteUrl(WebRoutes.LibraryManagement.GET_LIBRARY_PATH_TEMPLATE_PARTS, new { libraryType = "Music" })'.replace('/Music', `/${libraryType}`); + catalog = await callApiGetAsync(url); + if (!catalog) catalog = { parts: [], defaultTemplateParts: [] }; + pathTemplateCatalogCache[libraryType] = catalog; + } + // Only library types that define path parts get the editor; the others have no structure to describe. + const hasParts = (catalog.parts || []).length > 0; + if (pathTemplateSection) pathTemplateSection.classList.toggle('hidden', !hasParts); + if (!hasParts) { + renderPathTemplatePalette([]); + renderPathTemplateParts([]); + return; + } + (catalog.parts || []).forEach(definition => { pathPartValueTypes[definition.kind] = definition.valueType; }); + renderPathTemplatePalette(catalog.parts); + // The stored template belongs to the library type it was saved for, so it is only restored for that type. + const parts = (savedPathTemplateParts && savedPathTemplateParts.length > 0 && libraryType === initialLibraryType) + ? savedPathTemplateParts + : catalog.defaultTemplateParts; + renderPathTemplateParts(parts); + } + + // Finds the pill a drag or drop should be placed relative to, based on the pointer position. This also places a part dropped in a + // gap between pills, or anywhere in the drop zone, next to the nearest pill, instead of always sending it to the end. + function getPathTemplateInsertReference(e, excludePill) { + const pills = Array.from(pathTemplateDropzone.querySelectorAll('.path-template-pill')).filter(pill => pill !== excludePill); + if (pills.length === 0) return null; + let nearestPill = null; + let nearestRect = null; + let nearestDistance = Infinity; + for (const pill of pills) { + const rect = pill.getBoundingClientRect(); + const distance = Math.hypot(e.clientX - (rect.left + rect.width / 2), e.clientY - (rect.top + rect.height / 2)); + if (distance < nearestDistance) { + nearestDistance = distance; + nearestPill = pill; + nearestRect = rect; + } + } + return { pill: nearestPill, placeAfter: e.clientX > (nearestRect.left + nearestRect.width / 2) }; + } + + // Removes the insertion indicator from all pills. + function clearPathTemplateDropIndicator() { + pathTemplateDropzone.querySelectorAll('.path-template-pill').forEach(pill => pill.classList.remove('path-template-drop-before', 'path-template-drop-after')); + } + + // Highlights the side of the pill the dragged part would be inserted on. + function updatePathTemplateDropIndicator(e) { + clearPathTemplateDropIndicator(); + const reference = getPathTemplateInsertReference(e, draggedPathTemplatePill); + if (reference) + reference.pill.classList.add(reference.placeAfter ? 'path-template-drop-after' : 'path-template-drop-before'); + } + + // On a drag over the path template drop zone, allows the drop and shows where the part would be inserted. + const handlePathTemplateDragOver = function(e) { + e.preventDefault(); + e.dataTransfer.dropEffect = draggedPathTemplatePill ? 'move' : 'copy'; + updatePathTemplateDropIndicator(e); + }; + + // On a drop over the path template drop zone, inserts a palette part or moves a pill at the pointer position. + const handlePathTemplateDrop = function(e) { + e.preventDefault(); + const reference = getPathTemplateInsertReference(e, draggedPathTemplatePill); + clearPathTemplateDropIndicator(); + const insertAtReference = (pill) => { + if (reference) + reference.pill.insertAdjacentElement(reference.placeAfter ? 'afterend' : 'beforebegin', pill); + else + pathTemplateDropzone.appendChild(pill); + }; + const raw = e.dataTransfer.getData('application/json'); + if (raw) { + const part = JSON.parse(raw); + if (part.source === 'palette') { + insertAtReference(renderPathTemplatePill(part)); + updatePathTemplatePreview(); + return; + } + } + if (draggedPathTemplatePill) { + insertAtReference(draggedPathTemplatePill); + draggedPathTemplatePill = null; + updatePathTemplatePreview(); + } + }; + + // On dragging out of the drop zone, removes the insertion indicator. + const handlePathTemplateDragLeave = function(e) { + if (!pathTemplateDropzone.contains(e.relatedTarget)) + clearPathTemplateDropIndicator(); + }; + + // On selecting another library type, the available parts and the default template change. + const handleLibraryTypeChange = function(e) { + const option = e.target.closest('.enlightenment-option'); + if (!option || option.classList.contains('disabled') || !option.getAttribute('data-value')) return; + setTimeout(() => { loadPathTemplateAsync(); }, 0); + }; + // Add listeners. form.addEventListener('keypress', handleEnterKey); form.addEventListener('submit', handleSubmit); @@ -591,6 +965,10 @@ imgAddCover.addEventListener('click', handleImgAddCoverClick); mediaCoverFormTable.addEventListener('click', handleRowRemoval); mediaDirectoriesFormTable.addEventListener('click', handleRowRemoval); + pathTemplateDropzone.addEventListener('dragover', handlePathTemplateDragOver); + pathTemplateDropzone.addEventListener('drop', handlePathTemplateDrop); + pathTemplateDropzone.addEventListener('dragleave', handlePathTemplateDragLeave); + if (libraryTypeDropdown) libraryTypeDropdown.addEventListener('click', handleLibraryTypeChange); if (metadataProvidersTbody) { metadataProvidersTbody.addEventListener('click', handleMetadataProviderReorderAsync); metadataProvidersTbody.addEventListener('change', handleMetadataProviderEnabledChangeAsync); @@ -613,6 +991,10 @@ imgAddCover.removeEventListener('click', handleImgAddCoverClick); mediaCoverFormTable.removeEventListener('click', handleRowRemoval); mediaDirectoriesFormTable.removeEventListener('click', handleRowRemoval); + pathTemplateDropzone.removeEventListener('dragover', handlePathTemplateDragOver); + pathTemplateDropzone.removeEventListener('drop', handlePathTemplateDrop); + pathTemplateDropzone.removeEventListener('dragleave', handlePathTemplateDragLeave); + if (libraryTypeDropdown) libraryTypeDropdown.removeEventListener('click', handleLibraryTypeChange); if (metadataProvidersTbody) { metadataProvidersTbody.removeEventListener('click', handleMetadataProviderReorderAsync); metadataProvidersTbody.removeEventListener('change', handleMetadataProviderEnabledChangeAsync); @@ -633,6 +1015,9 @@ loadBookReadersAsync(); } + // Load the path template of the selected library type, and its default, for both new and existing libraries. + loadPathTemplateAsync(); + // Store all cleanups for this view on window object using the scriptId. window.viewCleanups = window.viewCleanups || {}; window.viewCleanups['@scriptId'] = () => { diff --git a/src/Lumina.sln b/src/Lumina.sln index 7aedef91..79c37544 100644 --- a/src/Lumina.sln +++ b/src/Lumina.sln @@ -294,6 +294,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "management", "management", ..\docs\technical\requests\library\management\GetEnabledLibraries.http = ..\docs\technical\requests\library\management\GetEnabledLibraries.http ..\docs\technical\requests\library\management\GetLibraries.http = ..\docs\technical\requests\library\management\GetLibraries.http ..\docs\technical\requests\library\management\GetLibrary.http = ..\docs\technical\requests\library\management\GetLibrary.http + ..\docs\technical\requests\library\management\GetLibraryPathTemplateParts.http = ..\docs\technical\requests\library\management\GetLibraryPathTemplateParts.http ..\docs\technical\requests\library\management\GetLibraryScanProgress.http = ..\docs\technical\requests\library\management\GetLibraryScanProgress.http ..\docs\technical\requests\library\management\GetRunningLibraryScans.http = ..\docs\technical\requests\library\management\GetRunningLibraryScans.http ..\docs\technical\requests\library\management\ScanLibraries.http = ..\docs\technical\requests\library\management\ScanLibraries.http diff --git a/tests/Common/Lumina.Application.Fixtures/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandFixture.cs b/tests/Common/Lumina.Application.Fixtures/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandFixture.cs index 96e537b3..4d129a24 100644 --- a/tests/Common/Lumina.Application.Fixtures/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandFixture.cs +++ b/tests/Common/Lumina.Application.Fixtures/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandFixture.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using Bogus; +using Lumina.Application.Common.DTO.MediaLibrary.Management; using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary; using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using System.Collections.Generic; @@ -27,6 +28,7 @@ public class AddLibraryCommandFixture /// Whether the media library should download metadata from the web or not. /// Whether the metadata should be saved in the media directories or not. /// Whether unchanged directories should be skipped during a scan or not. + /// Optional. The ordered parts of the path template of the media library. /// The created command. public AddLibraryCommand Create( string? title = null, @@ -37,7 +39,8 @@ public class AddLibraryCommandFixture bool isLocked = false, bool canDownloadMetadataFromWeb = true, bool shouldSaveMetadataInMediaDirectories = true, - bool shouldSkipUnchangedDirectoriesDuringScan = false) + bool shouldSkipUnchangedDirectoriesDuringScan = false, + LibraryPathTemplatePartDto[]? pathTemplateParts = null) { return new Faker() .CustomInstantiator(f => new AddLibraryCommand( @@ -49,7 +52,8 @@ public class AddLibraryCommandFixture false, true, true, - false + false, + null )) .RuleFor(x => x.Title, f => title ?? f.Lorem.Word()) .RuleFor(x => x.LibraryType, f => libraryType ?? f.Random.Enum().ToString()) @@ -60,6 +64,7 @@ public class AddLibraryCommandFixture .RuleFor(x => x.CanDownloadMetadataFromWeb, canDownloadMetadataFromWeb) .RuleFor(x => x.ShouldSaveMetadataInMediaDirectories, shouldSaveMetadataInMediaDirectories) .RuleFor(x => x.ShouldSkipUnchangedDirectoriesDuringScan, shouldSkipUnchangedDirectoriesDuringScan) + .RuleFor(x => x.PathTemplateParts, pathTemplateParts) .Generate(); } diff --git a/tests/Common/Lumina.Application.Fixtures/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandFixture.cs b/tests/Common/Lumina.Application.Fixtures/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandFixture.cs index 284c8d6d..d02b63b6 100644 --- a/tests/Common/Lumina.Application.Fixtures/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandFixture.cs +++ b/tests/Common/Lumina.Application.Fixtures/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandFixture.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using Bogus; +using Lumina.Application.Common.DTO.MediaLibrary.Management; using Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary; using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using System; @@ -30,6 +31,7 @@ public class UpdateLibraryCommandFixture /// Whether the media library should download metadata from the web or not. /// Whether the metadata should be saved in the media directories or not. /// Whether unchanged directories should be skipped during a scan or not. + /// Optional. The ordered parts of the path template of the media library. /// The created command. public UpdateLibraryCommand Create( Guid? id = null, @@ -42,7 +44,8 @@ public class UpdateLibraryCommandFixture bool isLocked = false, bool canDownloadMetadataFromWeb = true, bool shouldSaveMetadataInMediaDirectories = true, - bool shouldSkipUnchangedDirectoriesDuringScan = false) + bool shouldSkipUnchangedDirectoriesDuringScan = false, + LibraryPathTemplatePartDto[]? pathTemplateParts = null) { return new Faker() .CustomInstantiator(f => new UpdateLibraryCommand( @@ -56,7 +59,8 @@ public class UpdateLibraryCommandFixture false, true, true, - false + false, + null )) .RuleFor(x => x.Id, id ?? Guid.NewGuid()) .RuleFor(x => x.OwnerId, ownerId ?? Guid.NewGuid()) @@ -69,6 +73,7 @@ public class UpdateLibraryCommandFixture .RuleFor(x => x.CanDownloadMetadataFromWeb, canDownloadMetadataFromWeb) .RuleFor(x => x.ShouldSaveMetadataInMediaDirectories, shouldSaveMetadataInMediaDirectories) .RuleFor(x => x.ShouldSkipUnchangedDirectoriesDuringScan, shouldSkipUnchangedDirectoriesDuringScan) + .RuleFor(x => x.PathTemplateParts, pathTemplateParts) .Generate(); } diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/MediaLibrary/Management/AddLibraryRequestFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/MediaLibrary/Management/AddLibraryRequestFixture.cs index b48be3f2..f48ad45d 100644 --- a/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/MediaLibrary/Management/AddLibraryRequestFixture.cs +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/MediaLibrary/Management/AddLibraryRequestFixture.cs @@ -28,6 +28,7 @@ public class AddLibraryRequestFixture /// Optional. Whether metadata should be downloaded from the web. /// Optional. Whether metadata should be saved in the media directories. /// Optional. Whether unchanged directories should be skipped during scan. + /// Optional. The ordered parts of the path template of the media library. /// The created . public AddLibraryRequest Create( string? title = null, @@ -38,7 +39,8 @@ public class AddLibraryRequestFixture bool? isLocked = null, bool? canDownloadMetadataFromWeb = null, bool? shouldSaveMetadataInMediaDirectories = null, - bool? shouldSkipUnchangedDirectoriesDuringScan = null) + bool? shouldSkipUnchangedDirectoriesDuringScan = null, + LibraryPathTemplatePartRequest[]? pathTemplateParts = null) { return new AddLibraryRequest( title ?? _faker.Commerce.Department(), @@ -49,7 +51,8 @@ public class AddLibraryRequestFixture isLocked ?? _faker.Random.Bool(), canDownloadMetadataFromWeb ?? _faker.Random.Bool(), shouldSaveMetadataInMediaDirectories ?? _faker.Random.Bool(), - shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool() + shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool(), + pathTemplateParts ); } diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/MediaLibrary/Management/UpdateLibraryRequestFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/MediaLibrary/Management/UpdateLibraryRequestFixture.cs index ca1bd352..782f337b 100644 --- a/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/MediaLibrary/Management/UpdateLibraryRequestFixture.cs +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/MediaLibrary/Management/UpdateLibraryRequestFixture.cs @@ -31,6 +31,7 @@ public class UpdateLibraryRequestFixture /// Optional. Whether metadata should be downloaded from the web. /// Optional. Whether metadata should be saved in the media directories. /// Optional. Whether unchanged directories should be skipped during scan. + /// Optional. The ordered parts of the path template of the media library. /// The created . public UpdateLibraryRequest Create( Guid? id = null, @@ -43,7 +44,8 @@ public class UpdateLibraryRequestFixture bool? isLocked = null, bool? canDownloadMetadataFromWeb = null, bool? shouldSaveMetadataInMediaDirectories = null, - bool? shouldSkipUnchangedDirectoriesDuringScan = null) + bool? shouldSkipUnchangedDirectoriesDuringScan = null, + LibraryPathTemplatePartRequest[]? pathTemplateParts = null) { return new UpdateLibraryRequest( id ?? _faker.Random.Guid(), @@ -56,7 +58,8 @@ public class UpdateLibraryRequestFixture isLocked ?? _faker.Random.Bool(), canDownloadMetadataFromWeb ?? _faker.Random.Bool(), shouldSaveMetadataInMediaDirectories ?? _faker.Random.Bool(), - shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool() + shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool(), + pathTemplateParts ); } diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/Management/LibraryResponseFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/Management/LibraryResponseFixture.cs index 06493766..145e7748 100644 --- a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/Management/LibraryResponseFixture.cs +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/Management/LibraryResponseFixture.cs @@ -32,6 +32,7 @@ public class LibraryResponseFixture /// Optional. Whether metadata should be downloaded from the web. /// Optional. Whether metadata should be saved in the media directories. /// Optional. Whether unchanged directories should be skipped during scan. + /// Optional. The ordered parts of the path template of the media library. /// Optional. The date and time when the library was created. /// Optional. The date and time when the library was updated. /// The created . @@ -47,6 +48,7 @@ public class LibraryResponseFixture bool? canDownloadMetadataFromWeb = null, bool? shouldSaveMetadataInMediaDirectories = null, bool? shouldSkipUnchangedDirectoriesDuringScan = null, + List? pathTemplateParts = null, DateTime? createdOnUtc = null, DateTime? updatedOnUtc = null) { @@ -62,6 +64,7 @@ public class LibraryResponseFixture canDownloadMetadataFromWeb ?? _faker.Random.Bool(), shouldSaveMetadataInMediaDirectories ?? _faker.Random.Bool(), shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool(), + pathTemplateParts ?? [], createdOnUtc ?? _faker.Date.Past().ToUniversalTime(), updatedOnUtc ); diff --git a/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/LibraryFixture.cs b/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/LibraryFixture.cs index 9dfa2bee..a4a80153 100644 --- a/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/LibraryFixture.cs +++ b/tests/Common/Lumina.Domain.Fixtures/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/LibraryFixture.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Bogus; using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects; @@ -42,6 +43,7 @@ public class LibraryFixture /// Whether metadata should be saved in the media directories. /// Whether unchanged directories should be skipped during scan. /// Optional. The scan Ids associated with the library. + /// Optional. The path template of the library. /// Whether the cover image should be included, or left unset, meaning the library has no cover. /// The created . public Library Create( @@ -57,6 +59,7 @@ public class LibraryFixture bool shouldSaveMetadataInMediaDirectories = false, bool shouldSkipUnchangedDirectoriesDuringScan = false, IEnumerable? scanIds = null, + LibraryPathTemplate? pathTemplate = null, bool includeCoverImage = true) { List validPaths = @@ -83,6 +86,7 @@ public class LibraryFixture canDownloadMetadataFromWeb, shouldSaveMetadataInMediaDirectories, shouldSkipUnchangedDirectoriesDuringScan, + pathTemplate ?? LibraryPathTemplate.Empty(), resolvedScanIds ) : Library.Create( @@ -97,6 +101,7 @@ public class LibraryFixture canDownloadMetadataFromWeb, shouldSaveMetadataInMediaDirectories, shouldSkipUnchangedDirectoriesDuringScan, + pathTemplate ?? LibraryPathTemplate.Empty(), resolvedScanIds ); diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandlerTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandlerTests.cs index 153e4fe7..9f94b513 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandlerTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/Management/Commands/AddLibrary/AddLibraryCommandHandlerTests.cs @@ -12,6 +12,8 @@ using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Manage using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Commands.AddLibrary; using Lumina.Contracts.Responses.MediaLibrary.Management; using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events; @@ -42,6 +44,7 @@ public class AddLibraryCommandHandlerTests private readonly IDomainEventsQueue _mockDomainEventsQueue; private readonly IEnvironmentContext _mockEnvironmentContext; private readonly IMediaLibraryProviderConfigurationStore _mockProviderConfigurationStore; + private readonly ILibraryPathTemplateService _mockLibraryPathTemplateService; private readonly IValidator _mockValidator; private readonly AddLibraryCommandHandler _sut; private readonly AddLibraryCommandFixture _addLibraryCommandFixture = new(); @@ -62,6 +65,7 @@ public class AddLibraryCommandHandlerTests _mockDomainEventsQueue = Substitute.For(); _mockEnvironmentContext = Substitute.For(); _mockProviderConfigurationStore = Substitute.For(); + _mockLibraryPathTemplateService = Substitute.For(); _mockValidator = Substitute.For>(); _userId = Guid.NewGuid(); @@ -75,8 +79,10 @@ public class AddLibraryCommandHandlerTests _mockProviderConfigurationStore.EnsureProviderConfigurationsAsync(Arg.Any(), Arg.Any(), Arg.Any()) .Returns(Result.Success); _mockValidator.Validate(Arg.Any()).Returns([]); + _mockLibraryPathTemplateService.GetDefaultTemplate(Arg.Any()).Returns(LibraryPathTemplate.Empty()); + _mockLibraryPathTemplateService.Validate(Arg.Any(), Arg.Any()).Returns(Result.Success); - _sut = new AddLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockEnvironmentContext, _mockProviderConfigurationStore, _mockUnitOfWork, _mockValidator); + _sut = new AddLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockEnvironmentContext, _mockProviderConfigurationStore, _mockLibraryPathTemplateService, _mockUnitOfWork, _mockValidator); } [Fact] diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandHandlerTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandHandlerTests.cs index 942f528f..f4dc5a27 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandHandlerTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/Management/Commands/UpdateLibrary/UpdateLibraryCommandHandlerTests.cs @@ -13,6 +13,8 @@ using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Manage using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Commands.UpdateLibrary; using Lumina.Contracts.Responses.MediaLibrary.Management; using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment; using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events; @@ -44,6 +46,7 @@ public class UpdateLibraryCommandHandlerTests private readonly IDomainEventsQueue _mockDomainEventsQueue; private readonly IEnvironmentContext _mockEnvironmentContext; private readonly IMediaLibraryProviderConfigurationStore _mockProviderConfigurationStore; + private readonly ILibraryPathTemplateService _mockLibraryPathTemplateService; private readonly IValidator _mockValidator; private readonly UpdateLibraryCommandHandler _sut; private readonly UpdateLibraryCommandFixture _updateLibraryCommandFixture = new(); @@ -64,6 +67,7 @@ public class UpdateLibraryCommandHandlerTests _mockDomainEventsQueue = Substitute.For(); _mockEnvironmentContext = Substitute.For(); _mockProviderConfigurationStore = Substitute.For(); + _mockLibraryPathTemplateService = Substitute.For(); _mockValidator = Substitute.For>(); _userId = Guid.NewGuid(); @@ -78,8 +82,10 @@ public class UpdateLibraryCommandHandlerTests _mockProviderConfigurationStore.ReconcileProviderConfigurationsAsync(Arg.Any(), Arg.Any(), Arg.Any()) .Returns(Result.Success); _mockValidator.Validate(Arg.Any()).Returns([]); + _mockLibraryPathTemplateService.GetDefaultTemplate(Arg.Any()).Returns(LibraryPathTemplate.Empty()); + _mockLibraryPathTemplateService.Validate(Arg.Any(), Arg.Any()).Returns(Result.Success); - _sut = new UpdateLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockEnvironmentContext, _mockProviderConfigurationStore, _mockUnitOfWork, _mockValidator); + _sut = new UpdateLibraryCommandHandler(_mockAuthorizationService, _mockCurrentUserService, _mockDomainEventsQueue, _mockEnvironmentContext, _mockProviderConfigurationStore, _mockLibraryPathTemplateService, _mockUnitOfWork, _mockValidator); } [Fact] diff --git a/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/LibraryTests.cs b/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/LibraryTests.cs index 0a6d35fa..8b5af5d2 100644 --- a/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/LibraryTests.cs +++ b/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/LibraryManagementBoundedContext/LibraryAggregate/LibraryTests.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Domain.Common.Events; using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events; using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects; @@ -51,6 +52,7 @@ public class LibraryTests canDownloadMetadataFromWeb: false, shouldSaveMetadataInMediaDirectories: true, shouldSkipUnchangedDirectoriesDuringScan: true, + LibraryPathTemplate.Empty(), scanIds); // Assert @@ -89,6 +91,7 @@ public class LibraryTests canDownloadMetadataFromWeb: true, shouldSaveMetadataInMediaDirectories: false, shouldSkipUnchangedDirectoriesDuringScan: false, + LibraryPathTemplate.Empty(), scanIds); // Assert @@ -115,6 +118,7 @@ public class LibraryTests canDownloadMetadataFromWeb: true, shouldSaveMetadataInMediaDirectories: false, shouldSkipUnchangedDirectoriesDuringScan: false, + LibraryPathTemplate.Empty(), []); // Assert @@ -150,6 +154,7 @@ public class LibraryTests canDownloadMetadataFromWeb: true, shouldSaveMetadataInMediaDirectories: false, shouldSkipUnchangedDirectoriesDuringScan: false, + LibraryPathTemplate.Empty(), []); // Assert @@ -177,6 +182,7 @@ public class LibraryTests canDownloadMetadataFromWeb: true, shouldSaveMetadataInMediaDirectories: false, shouldSkipUnchangedDirectoriesDuringScan: false, + LibraryPathTemplate.Empty(), []); // Assert