Adds book reading support with EPUB and PDF reader plugins

This commit is contained in:
BinaryAlley committed 2026-09-02 04:45:11 -07:00
1 parent 275fd83ff2
commit f7ccdf3d1c
271 files changed
+11501 -361

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.GetLibraryBookReaders;
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.GetLibraryBookReaders;
/// <summary>
/// API endpoint for the <c>/libraries/{libraryId}/book-readers</c> route.
/// </summary>
public class GetLibraryBookReadersEndpoint : BaseEndpoint<GetLibraryBookReadersRequest, IResult>
{
private readonly IQueryHandler<GetLibraryBookReadersQuery, Result<IReadOnlyList<LibraryBookReaderResponse>>> _getLibraryBookReadersQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetLibraryBookReadersEndpoint"/> class.
/// </summary>
/// <param name="getLibraryBookReadersQueryHandler">Injected service for handling get library book readers queries.</param>
public GetLibraryBookReadersEndpoint(IQueryHandler<GetLibraryBookReadersQuery, Result<IReadOnlyList<LibraryBookReaderResponse>>> getLibraryBookReadersQueryHandler)
{
_getLibraryBookReadersQueryHandler = getLibraryBookReadersQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Libraries.GET_LIBRARY_BOOK_READERS);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the book readers configured for the media library identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the Id of the media library whose book readers are retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetLibraryBookReadersRequest request, CancellationToken cancellationToken)
{
Result<IReadOnlyList<LibraryBookReaderResponse>> result = await _getLibraryBookReadersQueryHandler.HandleAsync(request.ToQuery(), 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 Lumina.Contracts.Responses.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Plugins.GetLibraryBookReaders;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetLibraryBookReadersEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryBookReadersEndpointSummary : Summary<GetLibraryBookReadersEndpoint, GetLibraryBookReadersRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetLibraryBookReadersEndpointSummary"/> class.
/// </summary>
public GetLibraryBookReadersEndpointSummary()
{
Summary = "Retrieves the book readers configured for a media library.";
Description = "Retrieves the book readers configured for a media library, with their supported file extensions and enabled state.";
ExampleRequest = new GetLibraryBookReadersRequest(
LibraryId: Guid.NewGuid()
);
RequestParam(r => r.LibraryId, "The Id of the media library whose book readers are retrieved. Required.");
ResponseParam<LibraryBookReaderResponse>(r => r.PluginId, "The unique identifier of the plugin providing the book reader.");
ResponseParam<LibraryBookReaderResponse>(r => r.Name, "The display name of the book reader.");
ResponseParam<LibraryBookReaderResponse>(r => r.SupportedExtensions, "The file extensions supported by the book reader.");
ResponseParam<LibraryBookReaderResponse>(r => r.IsEnabled, "Whether the book reader is enabled for the media library.");
Response(200, "The book readers configured for the media library are returned.",
example: new LibraryBookReaderResponse[] {
new(
PluginId: Guid.NewGuid(),
Name: "EPUB Reader",
SupportedExtensions: [".epub"],
IsEnabled: true
),
new(
PluginId: Guid.NewGuid(),
Name: "PDF Reader",
SupportedExtensions: [".pdf"],
IsEnabled: false
)
}
);
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}/book-readers"
}
}
);
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}/book-readers",
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}/book-readers",
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}/book-readers",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}