Adds artwork provider system and Calibre plugin

This commit is contained in:
BinaryAlley committed 2026-08-24 14:18:14 -07:00
1 parent c82fadc7a2
commit 6693ff3f60
124 files changed
+9715 -74

No files matched your search

@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.Plugins;
using Lumina.Application.Core.Plugins.Queries.GetLibraryArtworkProviders;
using Lumina.Contracts.Requests.Plugins;
using Lumina.Contracts.Responses.Plugins;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.Management;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetLibraryArtworkProviders;
/// <summary>
/// API endpoint for the <c>/libraries/{libraryId}/artwork-providers</c> route.
/// </summary>
public class GetLibraryArtworkProvidersEndpoint : BaseEndpoint<GetLibraryArtworkProvidersRequest, IResult>
{
private readonly IQueryHandler<GetLibraryArtworkProvidersQuery, Result<IReadOnlyList<LibraryArtworkProviderResponse>>> _getLibraryArtworkProvidersQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetLibraryArtworkProvidersEndpoint"/> class.
/// </summary>
/// <param name="getLibraryArtworkProvidersQueryHandler">Injected service for handling get library artwork providers queries.</param>
public GetLibraryArtworkProvidersEndpoint(IQueryHandler<GetLibraryArtworkProvidersQuery, Result<IReadOnlyList<LibraryArtworkProviderResponse>>> getLibraryArtworkProvidersQueryHandler)
{
_getLibraryArtworkProvidersQueryHandler = getLibraryArtworkProvidersQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Libraries.GET_LIBRARY_ARTWORK_PROVIDERS);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the artwork providers configured for the media library identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the Id of the media library whose artwork providers are retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetLibraryArtworkProvidersRequest request, CancellationToken cancellationToken)
{
Result<IReadOnlyList<LibraryArtworkProviderResponse>> result = await _getLibraryArtworkProvidersQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,130 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.Plugins;
using Lumina.Contracts.Responses.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetLibraryArtworkProviders;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetLibraryArtworkProvidersEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryArtworkProvidersEndpointSummary : Summary<GetLibraryArtworkProvidersEndpoint, GetLibraryArtworkProvidersRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetLibraryArtworkProvidersEndpointSummary"/> class.
/// </summary>
public GetLibraryArtworkProvidersEndpointSummary()
{
Summary = "Retrieves the artwork providers configured for a media library.";
Description = "Retrieves the artwork providers configured for a media library, with their enabled state and rank.";
ExampleRequest = new GetLibraryArtworkProvidersRequest(
LibraryId: Guid.NewGuid()
);
RequestParam(r => r.LibraryId, "The Id of the media library whose artwork providers are retrieved. Required.");
ResponseParam<LibraryArtworkProviderResponse>(r => r.PluginId, "The unique identifier of the plugin providing the artwork.");
ResponseParam<LibraryArtworkProviderResponse>(r => r.Name, "The display name of the artwork provider.");
ResponseParam<LibraryArtworkProviderResponse>(r => r.IsEnabled, "Whether the artwork provider is enabled for the media library.");
ResponseParam<LibraryArtworkProviderResponse>(r => r.Rank, "The rank of the artwork provider, determining the order in which providers are tried.");
Response(200, "The artwork providers configured for the media library are returned.",
example: new LibraryArtworkProviderResponse[] {
new(
PluginId: Guid.NewGuid(),
Name: "Calibre",
IsEnabled: true,
Rank: 1
),
new(
PluginId: Guid.NewGuid(),
Name: "Goodreads",
IsEnabled: false,
Rank: 2
)
}
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artwork-providers"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artwork-providers"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artwork-providers"
}
}
);
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/libraries/{libraryId}/artwork-providers",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested media library does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = "/api/v1/libraries/{libraryId}/artwork-providers",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
);
Response(422, "The request did not pass validation checks.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/libraries/{libraryId}/artwork-providers",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.Plugins;
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryArtworkProviders;
using Lumina.Contracts.Requests.Plugins;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.Management;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Microsoft.AspNetCore.Http;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.ReorderLibraryArtworkProviders;
/// <summary>
/// API endpoint for the <c>/libraries/{libraryId}/artwork-providers/reorder</c> route.
/// </summary>
public class ReorderLibraryArtworkProvidersEndpoint : BaseEndpoint<ReorderLibraryArtworkProvidersRequest, IResult>
{
private readonly ICommandHandler<ReorderLibraryArtworkProvidersCommand, Result<Success>> _reorderLibraryArtworkProvidersCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="ReorderLibraryArtworkProvidersEndpoint"/> class.
/// </summary>
/// <param name="reorderLibraryArtworkProvidersCommandHandler">Injected service for handling reorder library artwork providers commands.</param>
public ReorderLibraryArtworkProvidersEndpoint(ICommandHandler<ReorderLibraryArtworkProvidersCommand, Result<Success>> reorderLibraryArtworkProvidersCommandHandler)
{
_reorderLibraryArtworkProvidersCommandHandler = reorderLibraryArtworkProvidersCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.PUT);
Routes(ApiRoutes.Libraries.REORDER_LIBRARY_ARTWORK_PROVIDERS);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Reorders the artwork providers of the media library identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the Id of the media library and the plugin Ids in the new order.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(ReorderLibraryArtworkProvidersRequest request, CancellationToken cancellationToken)
{
Result<Success> result = await _reorderLibraryArtworkProvidersCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,116 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.ReorderLibraryArtworkProviders;
/// <summary>
/// Class used for providing a textual description for the <see cref="ReorderLibraryArtworkProvidersEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class ReorderLibraryArtworkProvidersEndpointSummary : Summary<ReorderLibraryArtworkProvidersEndpoint, ReorderLibraryArtworkProvidersRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="ReorderLibraryArtworkProvidersEndpointSummary"/> class.
/// </summary>
public ReorderLibraryArtworkProvidersEndpointSummary()
{
Summary = "Reorders the artwork providers of a media library.";
Description = "Reorders the artwork providers of a media library, determining the order in which the providers are tried during the artwork enrichment of the library scans.";
ExampleRequest = new ReorderLibraryArtworkProvidersRequest(
LibraryId: Guid.NewGuid(),
PluginIds:
[
Guid.NewGuid(),
Guid.NewGuid()
]
);
RequestParam(r => r.LibraryId, "The Id of the media library whose artwork providers are reordered. Required.");
RequestParam(r => r.PluginIds, "The plugin Ids in the new order, from highest to lowest rank. Required.");
Response(200, "The artwork providers of the media library were successfully reordered.");
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artwork-providers/reorder"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artwork-providers/reorder"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artwork-providers/reorder"
}
}
);
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/libraries/{libraryId}/artwork-providers/reorder",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested media library does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = "/api/v1/libraries/{libraryId}/artwork-providers/reorder",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
);
Response(422, "The request did not pass validation checks.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/libraries/{libraryId}/artwork-providers/reorder",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"PluginIdsListCannotBeNull",
"PluginIdsListCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.Plugins;
using Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
using Lumina.Contracts.Requests.Plugins;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.Management;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Microsoft.AspNetCore.Http;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.SetLibraryArtworkProviderEnabled;
/// <summary>
/// API endpoint for the <c>/libraries/{libraryId}/artwork-providers/{pluginId}/enabled</c> route.
/// </summary>
public class SetLibraryArtworkProviderEnabledEndpoint : BaseEndpoint<SetLibraryArtworkProviderEnabledRequest, IResult>
{
private readonly ICommandHandler<SetLibraryArtworkProviderEnabledCommand, Result<Success>> _setLibraryArtworkProviderEnabledCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="SetLibraryArtworkProviderEnabledEndpoint"/> class.
/// </summary>
/// <param name="setLibraryArtworkProviderEnabledCommandHandler">Injected service for handling set library artwork provider enabled commands.</param>
public SetLibraryArtworkProviderEnabledEndpoint(ICommandHandler<SetLibraryArtworkProviderEnabledCommand, Result<Success>> setLibraryArtworkProviderEnabledCommandHandler)
{
_setLibraryArtworkProviderEnabledCommandHandler = setLibraryArtworkProviderEnabledCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.PUT);
Routes(ApiRoutes.Libraries.SET_LIBRARY_ARTWORK_PROVIDER_ENABLED);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Enables or disables the artwork provider identified by <paramref name="request"/> for the media library.
/// </summary>
/// <param name="request">The request containing the Ids of the media library and of the artwork provider.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(SetLibraryArtworkProviderEnabledRequest request, CancellationToken cancellationToken)
{
Result<Success> result = await _setLibraryArtworkProviderEnabledCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,113 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.SetLibraryArtworkProviderEnabled;
/// <summary>
/// Class used for providing a textual description for the <see cref="SetLibraryArtworkProviderEnabledEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetLibraryArtworkProviderEnabledEndpointSummary : Summary<SetLibraryArtworkProviderEnabledEndpoint, SetLibraryArtworkProviderEnabledRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="SetLibraryArtworkProviderEnabledEndpointSummary"/> class.
/// </summary>
public SetLibraryArtworkProviderEnabledEndpointSummary()
{
Summary = "Enables or disables an artwork provider for a media library.";
Description = "Enables or disables the artwork provider for the media library, so that it is included or excluded from the artwork enrichment of the library scans.";
ExampleRequest = new SetLibraryArtworkProviderEnabledRequest(
LibraryId: Guid.NewGuid(),
PluginId: Guid.NewGuid(),
IsEnabled: true
);
RequestParam(r => r.LibraryId, "The Id of the media library whose artwork provider is enabled or disabled. Required.");
RequestParam(r => r.PluginId, "The unique identifier of the plugin providing the artwork. Required.");
RequestParam(r => r.IsEnabled, "Whether the artwork provider should be enabled for the media library. Required.");
Response(200, "The artwork provider was successfully enabled or disabled for the media library.");
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artwork-providers/{pluginId}/enabled"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artwork-providers/{pluginId}/enabled"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artwork-providers/{pluginId}/enabled"
}
}
);
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/libraries/{libraryId}/artwork-providers/{pluginId}/enabled",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested media library does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = "/api/v1/libraries/{libraryId}/artwork-providers/{pluginId}/enabled",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
);
Response(422, "The request did not pass validation checks.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/libraries/{libraryId}/artwork-providers/{pluginId}/enabled",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"PluginIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}