Adds provider configuration to media library saves

Moves metadata provider, artwork provider, and book reader choices into the add and update library requests, adds the library type lookups, removes the per-provider enable and reorder endpoints, and reconciles the stored configurations in one provider store call. Tightens library update and delete authorization to require ownership and the manage permission, and cleans up enum validation, comments, resource diacritics, and Razor imports.
This commit is contained in:
BinaryAlley committed 2026-11-02 10:00:00 +02:00
1 parent 2e7563199a
commit 48ad8692af
148 files changed
+6305 -2936

No files matched your search

@@ -0,0 +1,17 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DTO.MediaLibrary.Management;
/// <summary>
/// Data transfer object for the choice made for one metadata provider, artwork provider or book reader of a media library, carried by the commands that create or update a media library.
/// </summary>
/// <param name="PluginId">The Id of the plugin providing the metadata provider, artwork provider or book reader.</param>
/// <param name="IsEnabled">Whether the provider or reader is enabled for the media library. When absent, the stored state is kept, and a provider or reader without a stored state starts disabled.</param>
[DebuggerDisplay("PluginId: {PluginId}; IsEnabled: {IsEnabled}")]
public record LibraryProviderSelectionDto(
Guid PluginId,
bool? IsEnabled
);
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Plugins;
using Lumina.Application.Common.DTO.MediaLibrary.Management;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
@@ -11,7 +12,7 @@ using System.Threading.Tasks;
namespace Lumina.Application.Common.Infrastructure.Plugins;
/// <summary>
/// Store of the metadata and artwork provider configurations of the media libraries.
/// Store of the metadata provider, artwork provider and book reader configurations of the media libraries.
/// </summary>
public interface IMediaLibraryProviderConfigurationStore
{
@@ -24,25 +25,18 @@ public interface IMediaLibraryProviderConfigurationStore
Task<Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>> GetConfigurationsAsync(Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Adds a disabled provider configuration for every loaded plugin that supports the provided library type and has no
/// Adds a disabled metadata provider, artwork provider and book reader configuration for every loaded plugin that supports the provided library type and has no
/// configuration yet for the media library identified by <paramref name="libraryId"/>.
/// </summary>
/// <remarks>
/// The added configurations are only staged until the unit of work is saved, and are not visible to a later ensure, so it must be called at most once per media library before the changes are saved.
/// </remarks>
/// <param name="libraryId">The Id of the media library whose provider configurations are ensured.</param>
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers apply.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Success>> EnsureProviderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
/// <summary>
/// Replaces the provider configurations of the media library identified by <paramref name="libraryId"/> so that they
/// match the plugins supporting the provided library type.
/// </summary>
/// <param name="libraryId">The Id of the media library whose provider configurations are reconciled.</param>
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers apply.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Success>> ReconcileProviderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
/// <summary>
/// Deletes all the provider configurations of the media library identified by <paramref name="libraryId"/>.
/// </summary>
@@ -60,36 +54,52 @@ public interface IMediaLibraryProviderConfigurationStore
Task<Result<Deleted>> RemoveProviderConfigurationsAsync(Guid pluginId, CancellationToken cancellationToken);
/// <summary>
/// Adds a disabled book reader configuration for every loaded plugin that supports the provided library type and has no configuration yet, for the media library identified by <paramref name="libraryId"/>.
/// Makes the provider and book reader configurations of the media library identified by <paramref name="libraryId"/> match the plugins supporting the provided library type, and applies the choices made for them.
/// </summary>
/// <param name="libraryId">The Id of the media library whose book reader configurations are ensured.</param>
/// <param name="libraryType">The type of the media library, used to determine the plugins whose book readers apply.</param>
/// <remarks>
/// A list that is provided reconciles that kind of configuration with the library type and applies the choices: the configurations of the plugins that do not support the library type
/// are removed, even when the list does not name them, every supported plugin gets a configuration, and the list sets the enabled state of every provider or reader it names and, for the
/// metadata and artwork providers, their order. A choice without an enabled state keeps the stored state, the supported plugins the list does not name keep their stored state and are
/// ordered after the named ones, and a plugin without a stored configuration starts disabled. A list that is <see langword="null"/> leaves that kind of configuration untouched, unless
/// <paramref name="shouldReconcileOmittedKinds"/> is <see langword="true"/>, in which case it is reconciled the same way, without choices. Whenever the book reader configurations are
/// reconciled or chosen, the cached reader enablements of the library are dropped.
/// </remarks>
/// <param name="libraryId">The Id of the media library whose provider and book reader configurations are configured.</param>
/// <param name="libraryType">The type of the media library, used to determine the plugins whose providers and book readers apply.</param>
/// <param name="metadataProviders">The choices made for the metadata providers, in the order in which they are tried.</param>
/// <param name="artworkProviders">The choices made for the artwork providers, in the order in which they are tried.</param>
/// <param name="bookReaders">The choices made for the book readers.</param>
/// <param name="shouldReconcileOmittedKinds">Whether the kinds of configuration whose list of choices is <see langword="null"/> are reconciled with the library type, which is needed when the
/// library is new or its type changed.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Success>> EnsureBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error when a choice names a plugin that does not support the library type.</returns>
Task<Result<Success>> ConfigureProvidersAsync(
Guid libraryId,
LibraryType libraryType,
IReadOnlyList<LibraryProviderSelectionDto>? metadataProviders,
IReadOnlyList<LibraryProviderSelectionDto>? artworkProviders,
IReadOnlyList<LibraryProviderSelectionDto>? bookReaders,
bool shouldReconcileOmittedKinds,
CancellationToken cancellationToken);
/// <summary>
/// Replaces the book reader configurations of the media library identified by <paramref name="libraryId"/> so that they match the plugins supporting the provided library type.
/// Gets the Ids of the loaded plugins that provide metadata for the provided library type, ordered alphabetically by plugin name.
/// </summary>
/// <param name="libraryId">The Id of the media library whose book reader configurations are reconciled.</param>
/// <param name="libraryType">The type of the media library, used to determine the plugins whose book readers apply.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Success>> ReconcileBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
/// <param name="libraryType">The type of the media library the metadata providers must support.</param>
/// <returns>The Ids of the plugins providing metadata for the library type.</returns>
IReadOnlyList<Guid> GetSupportedMetadataProviderPluginIds(LibraryType libraryType);
/// <summary>
/// Deletes all the book reader configurations of the media library identified by <paramref name="libraryId"/>.
/// Gets the Ids of the loaded plugins that provide artwork for the provided library type, ordered alphabetically by plugin name.
/// </summary>
/// <param name="libraryId">The Id of the media library whose book reader configurations are deleted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Deleted>> RemoveBookReaderConfigurationsForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
/// <param name="libraryType">The type of the media library the artwork providers must support.</param>
/// <returns>The Ids of the plugins providing artwork for the library type.</returns>
IReadOnlyList<Guid> GetSupportedArtworkProviderPluginIds(LibraryType libraryType);
/// <summary>
/// Deletes all the book reader configurations referencing the plugin identified by <paramref name="pluginId"/>.
/// Gets the Ids of the loaded plugins that provide a book reader for the provided library type, ordered alphabetically by plugin name.
/// </summary>
/// <param name="pluginId">The Id of the plugin whose book reader configurations are deleted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Deleted>> RemoveBookReaderConfigurationsAsync(Guid pluginId, CancellationToken cancellationToken);
/// <param name="libraryType">The type of the media library the book readers must support.</param>
/// <returns>The Ids of the plugins providing a book reader for the library type.</returns>
IReadOnlyList<Guid> GetSupportedBookReaderPluginIds(LibraryType libraryType);
}
@@ -2,6 +2,7 @@
using Lumina.Application.Common.DTO.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Linq;
#endregion
@@ -15,6 +16,10 @@ public static class AddMediaLibraryRequestMapping
/// <summary>
/// Converts <paramref name="request"/> to <see cref="AddLibraryCommand"/>.
/// </summary>
/// <remarks>
/// A path template part that is <see langword="null"/> is converted to a part without a kind, and a provider or book reader choice that is <see langword="null"/> is
/// converted to a choice without a plugin Id, so that the validation of the command reports them, instead of the conversion failing before the command is validated.
/// </remarks>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static AddLibraryCommand ToCommand(this AddLibraryRequest request)
@@ -32,7 +37,10 @@ public static class AddMediaLibraryRequestMapping
request.IsContentOnSsd,
request.ShouldTrackConsumptionProgress,
request.CompletionThresholdPercentage,
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part.Kind, part.Representation, part.IsOptional)).ToArray()
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part?.Kind, part?.Representation, part?.IsOptional ?? false)).ToArray(),
request.MetadataProviders?.Select(provider => new LibraryProviderSelectionDto(provider?.PluginId ?? Guid.Empty, provider?.IsEnabled)).ToArray(),
request.ArtworkProviders?.Select(provider => new LibraryProviderSelectionDto(provider?.PluginId ?? Guid.Empty, provider?.IsEnabled)).ToArray(),
request.BookReaders?.Select(reader => new LibraryProviderSelectionDto(reader?.PluginId ?? Guid.Empty, reader?.IsEnabled)).ToArray()
);
}
}
@@ -2,6 +2,7 @@
using Lumina.Application.Common.DTO.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Linq;
#endregion
@@ -15,13 +16,16 @@ public static class UpdateLibraryRequestMapping
/// <summary>
/// Converts <paramref name="request"/> to <see cref="UpdateLibraryCommand"/>.
/// </summary>
/// <remarks>
/// A path template part that is <see langword="null"/> is converted to a part without a kind, and a provider or book reader choice that is <see langword="null"/> is
/// converted to a choice without a plugin Id, so that the validation of the command reports them, instead of the conversion failing before the command is validated.
/// </remarks>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static UpdateLibraryCommand ToCommand(this UpdateLibraryRequest request)
{
return new UpdateLibraryCommand(
request.Id,
request.UserId,
request.Title,
request.LibraryType,
request.ContentLocations,
@@ -34,7 +38,10 @@ public static class UpdateLibraryRequestMapping
request.IsContentOnSsd,
request.ShouldTrackConsumptionProgress,
request.CompletionThresholdPercentage,
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part.Kind, part.Representation, part.IsOptional)).ToArray()
request.PathTemplateParts?.Select(part => new LibraryPathTemplatePartDto(part?.Kind, part?.Representation, part?.IsOptional ?? false)).ToArray(),
request.MetadataProviders?.Select(provider => new LibraryProviderSelectionDto(provider?.PluginId ?? Guid.Empty, provider?.IsEnabled)).ToArray(),
request.ArtworkProviders?.Select(provider => new LibraryProviderSelectionDto(provider?.PluginId ?? Guid.Empty, provider?.IsEnabled)).ToArray(),
request.BookReaders?.Select(reader => new LibraryProviderSelectionDto(reader?.PluginId ?? Guid.Empty, reader?.IsEnabled)).ToArray()
);
}
}
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Plugins.Queries.GetLibraryTypeArtworkProviders;
using Lumina.Contracts.Requests.Plugins;
#endregion
namespace Lumina.Application.Common.Mapping.Plugins;
/// <summary>
/// Extension methods for converting <see cref="GetLibraryTypeArtworkProvidersRequest"/>.
/// </summary>
public static class GetLibraryTypeArtworkProvidersRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetLibraryTypeArtworkProvidersQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetLibraryTypeArtworkProvidersQuery ToQuery(this GetLibraryTypeArtworkProvidersRequest request)
{
return new GetLibraryTypeArtworkProvidersQuery(
request.LibraryType
);
}
}
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Plugins.Queries.GetLibraryTypeBookReaders;
using Lumina.Contracts.Requests.Plugins;
#endregion
namespace Lumina.Application.Common.Mapping.Plugins;
/// <summary>
/// Extension methods for converting <see cref="GetLibraryTypeBookReadersRequest"/>.
/// </summary>
public static class GetLibraryTypeBookReadersRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetLibraryTypeBookReadersQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetLibraryTypeBookReadersQuery ToQuery(this GetLibraryTypeBookReadersRequest request)
{
return new GetLibraryTypeBookReadersQuery(
request.LibraryType
);
}
}
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Plugins.Queries.GetLibraryTypeMetadataProviders;
using Lumina.Contracts.Requests.Plugins;
#endregion
namespace Lumina.Application.Common.Mapping.Plugins;
/// <summary>
/// Extension methods for converting <see cref="GetLibraryTypeMetadataProvidersRequest"/>.
/// </summary>
public static class GetLibraryTypeMetadataProvidersRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetLibraryTypeMetadataProvidersQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetLibraryTypeMetadataProvidersQuery ToQuery(this GetLibraryTypeMetadataProvidersRequest request)
{
return new GetLibraryTypeMetadataProvidersQuery(
request.LibraryType
);
}
}
@@ -1,25 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryArtworkProviders;
using Lumina.Contracts.Requests.Plugins;
#endregion
namespace Lumina.Application.Common.Mapping.Plugins;
/// <summary>
/// Extension methods for converting <see cref="ReorderLibraryArtworkProvidersRequest"/>.
/// </summary>
public static class ReorderLibraryArtworkProvidersRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="ReorderLibraryArtworkProvidersCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static ReorderLibraryArtworkProvidersCommand ToCommand(this ReorderLibraryArtworkProvidersRequest request)
{
return new ReorderLibraryArtworkProvidersCommand(
LibraryId: request.LibraryId,
PluginIds: request.PluginIds
);
}
}
@@ -1,22 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
using Lumina.Contracts.Requests.Plugins;
#endregion
namespace Lumina.Application.Common.Mapping.Plugins;
/// <summary>
/// Extension methods for converting <see cref="ReorderLibraryMetadataProvidersRequest"/>.
/// </summary>
public static class ReorderLibraryMetadataProvidersRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="ReorderLibraryMetadataProvidersCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static ReorderLibraryMetadataProvidersCommand ToCommand(this ReorderLibraryMetadataProvidersRequest request)
{
return new ReorderLibraryMetadataProvidersCommand(request.LibraryId, request.PluginIds);
}
}
@@ -1,26 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
using Lumina.Contracts.Requests.Plugins;
#endregion
namespace Lumina.Application.Common.Mapping.Plugins;
/// <summary>
/// Extension methods for converting <see cref="SetLibraryArtworkProviderEnabledRequest"/>.
/// </summary>
public static class SetLibraryArtworkProviderEnabledRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="SetLibraryArtworkProviderEnabledCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static SetLibraryArtworkProviderEnabledCommand ToCommand(this SetLibraryArtworkProviderEnabledRequest request)
{
return new SetLibraryArtworkProviderEnabledCommand(
LibraryId: request.LibraryId,
PluginId: request.PluginId,
IsEnabled: request.IsEnabled
);
}
}
@@ -1,26 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
using Lumina.Contracts.Requests.Plugins;
#endregion
namespace Lumina.Application.Common.Mapping.Plugins;
/// <summary>
/// Extension methods for converting <see cref="SetLibraryBookReaderEnabledRequest"/>.
/// </summary>
public static class SetLibraryBookReaderEnabledRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="SetLibraryBookReaderEnabledCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static SetLibraryBookReaderEnabledCommand ToCommand(this SetLibraryBookReaderEnabledRequest request)
{
return new SetLibraryBookReaderEnabledCommand(
request.LibraryId,
request.PluginId,
request.IsEnabled
);
}
}
@@ -1,22 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
using Lumina.Contracts.Requests.Plugins;
#endregion
namespace Lumina.Application.Common.Mapping.Plugins;
/// <summary>
/// Extension methods for converting <see cref="SetLibraryMetadataProviderEnabledRequest"/>.
/// </summary>
public static class SetLibraryMetadataProviderEnabledRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="SetLibraryMetadataProviderEnabledCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static SetLibraryMetadataProviderEnabledCommand ToCommand(this SetLibraryMetadataProviderEnabledRequest request)
{
return new SetLibraryMetadataProviderEnabledCommand(request.LibraryId, request.PluginId, request.IsEnabled);
}
}