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,53 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.Plugins;
using Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
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.SetLibraryBookReaderEnabled;
/// <summary>
/// API endpoint for the <c>/libraries/{libraryId}/book-readers/{pluginId}/enabled</c> route.
/// </summary>
public class SetLibraryBookReaderEnabledEndpoint : BaseEndpoint<SetLibraryBookReaderEnabledRequest, IResult>
{
private readonly ICommandHandler<SetLibraryBookReaderEnabledCommand, Result<Success>> _setLibraryBookReaderEnabledCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="SetLibraryBookReaderEnabledEndpoint"/> class.
/// </summary>
/// <param name="setLibraryBookReaderEnabledCommandHandler">Injected service for handling set library book reader enabled commands.</param>
public SetLibraryBookReaderEnabledEndpoint(ICommandHandler<SetLibraryBookReaderEnabledCommand, Result<Success>> setLibraryBookReaderEnabledCommandHandler)
{
_setLibraryBookReaderEnabledCommandHandler = setLibraryBookReaderEnabledCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.PUT);
Routes(ApiRoutes.Libraries.SET_LIBRARY_BOOK_READER_ENABLED);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Enables or disables the book reader 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 book reader.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(SetLibraryBookReaderEnabledRequest request, CancellationToken cancellationToken)
{
Result<Success> result = await _setLibraryBookReaderEnabledCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,99 @@
#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.SetLibraryBookReaderEnabled;
/// <summary>
/// Class used for providing a textual description for the <see cref="SetLibraryBookReaderEnabledEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetLibraryBookReaderEnabledEndpointSummary : Summary<SetLibraryBookReaderEnabledEndpoint, SetLibraryBookReaderEnabledRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="SetLibraryBookReaderEnabledEndpointSummary"/> class.
/// </summary>
public SetLibraryBookReaderEnabledEndpointSummary()
{
Summary = "Enables or disables a book reader for a media library.";
Description = "Enables or disables the book reader of the media library identified by the request.";
ExampleRequest = new SetLibraryBookReaderEnabledRequest(
LibraryId: Guid.NewGuid(),
PluginId: Guid.NewGuid(),
IsEnabled: true
);
RequestParam(r => r.LibraryId, "The Id of the media library whose book reader is enabled or disabled. Required.");
RequestParam(r => r.PluginId, "The unique identifier of the plugin providing the book reader. Required.");
RequestParam(r => r.IsEnabled, "Whether the book reader should be enabled for the media library. Required.");
Response(200, "The book reader of the media library is enabled or disabled.",
example: new
{
success = true
}
);
Response(401, "Authentication required.", "application/problem+json",
example: 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/{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}/book-readers/{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}/book-readers/{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}/book-readers/{pluginId}/enabled",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"PluginIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}