mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11:10 +00:00
Adds dynamic path templates for media libraries, so that the scanner can derive the meaning of each path part
This commit is contained in:
1 parent
62b0e9297a
commit
ca4f308b0a
86 files changed
+7406
-151
No files matched your search
+13
@@ -0,0 +1,13 @@
|
||||
namespace Lumina.Application.Common.DTO.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="Kind">The kind of the path part.</param>
|
||||
/// <param name="Representation">The literal text or the value mask of the path part.</param>
|
||||
/// <param name="IsOptional">Whether the path part can be absent from the path.</param>
|
||||
public record LibraryPathTemplatePartDto(
|
||||
string? Kind,
|
||||
string? Representation,
|
||||
bool IsOptional
|
||||
);
|
||||
+11
@@ -45,6 +45,11 @@ public class LibraryEntity : IStorageEntity, IAuditableEntity
|
||||
/// </summary>
|
||||
public required ICollection<LibraryContentLocationEntity> ContentLocations { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ordered parts of the template describing the structure of the media library on disk.
|
||||
/// </summary>
|
||||
public ICollection<LibraryPathTemplatePartEntity> PathTemplateParts { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of scans of the media library.
|
||||
/// </summary>
|
||||
@@ -87,6 +92,12 @@ public class LibraryEntity : IStorageEntity, IAuditableEntity
|
||||
/// </summary>
|
||||
public string? ArtworkProvidersConfigurationFingerprint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public string? PathTemplateFingerprint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user that owns the media library.
|
||||
/// </summary>
|
||||
|
||||
+33
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Repository entity for one part of the path template of a media library.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Kind: {Kind}; Position: {Position}")]
|
||||
public class LibraryPathTemplatePartEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the zero based position of the part in the path template.
|
||||
/// </summary>
|
||||
public required int Position { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the kind of the path part.
|
||||
/// </summary>
|
||||
public required LibraryPathPartKind Kind { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the literal text or the value mask of the path part.
|
||||
/// </summary>
|
||||
public required string Representation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the path part can be absent from the path.
|
||||
/// </summary>
|
||||
public required bool IsOptional { get; set; }
|
||||
}
|
||||
+4
-1
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
+24
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetLibraryPathTemplatePartsRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetLibraryPathTemplatePartsRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetLibraryPathTemplatePartsQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetLibraryPathTemplatePartsQuery ToQuery(this GetLibraryPathTemplatePartsRequest request)
|
||||
{
|
||||
return new GetLibraryPathTemplatePartsQuery(
|
||||
request.LibraryType
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
/// </returns>
|
||||
public static Result<Library> ToDomainEntity(this LibraryEntity repositoryEntity)
|
||||
{
|
||||
Result<LibraryPathTemplate> 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))]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the path template of a media library from its ordered stored parts.
|
||||
/// </summary>
|
||||
/// <param name="parts">The stored parts of the path template.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the built <see cref="LibraryPathTemplate"/>, or an error message.
|
||||
/// </returns>
|
||||
private static Result<LibraryPathTemplate> BuildPathTemplate(IEnumerable<LibraryPathTemplatePartEntity> parts)
|
||||
{
|
||||
List<LibraryPathPart> orderedParts = [];
|
||||
foreach (LibraryPathTemplatePartEntity part in parts.OrderBy(part => part.Position))
|
||||
{
|
||||
Result<LibraryPathPart> partResult = LibraryPathPart.Create(part.Kind, part.Representation, part.IsOptional);
|
||||
if (partResult.IsFailure)
|
||||
return partResult.Errors;
|
||||
orderedParts.Add(partResult.Value);
|
||||
}
|
||||
return LibraryPathTemplate.Create(orderedParts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Library"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -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,
|
||||
|
||||
+44
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="LibraryPathTemplatePartDto"/>.
|
||||
/// </summary>
|
||||
public static class LibraryPathTemplatePartDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the provided path template parts to their domain path parts.
|
||||
/// </summary>
|
||||
/// <param name="parts">The path template parts to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the converted domain path parts, or an error message.
|
||||
/// </returns>
|
||||
public static Result<IReadOnlyList<LibraryPathPart>> ToDomainParts(this IEnumerable<LibraryPathTemplatePartDto>? parts)
|
||||
{
|
||||
List<LibraryPathPart> 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<LibraryPathPart> partResult = LibraryPathPart.Create(kind, part.Representation, part.IsOptional);
|
||||
if (partResult.IsFailure)
|
||||
return partResult.Errors;
|
||||
|
||||
domainParts.Add(partResult.Value);
|
||||
}
|
||||
return domainParts;
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user