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
+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