tableOfContents = [];
+ using (PdfDocument pdfDocument = PdfDocument.Open(pdfPath))
+ {
+ foreach (Page page in pdfDocument.GetPages())
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+ if (page.Number > MAX_PAGES)
+ break;
+
+ // The location reference of a page is its 1-based page number (PdfPig pages are numbered from 1), which is the only stable identifier a PDF page has, and it doubles as the name of the section file.
+ string locationRef = $"page:{page.Number}";
+ string fileName = $"{page.Number}.html";
+ string pageHtml = BuildPageHtml(page);
+ // A page may have no text at all, in which case the HTML is only the empty section wrapper; the text-content
+ // detection looks at the paragraphs actually produced, because the wrapper is always present.
+ if (pageHtml.Contains(""))
+ hasTextContent = true;
+ File.WriteAllText(Path.Combine(sectionsDirectory, fileName), pageHtml, Encoding.UTF8);
+ spine.Add(new ReadingSpineItemDto(locationRef, null, $"sections/{fileName}"));
+ }
+
+ // The table of contents is read from the document that was already opened for the pages, so the PDF is not opened twice.
+ tableOfContents = ReadTableOfContents(pdfDocument);
+ }
+
+ // The author and the cover are not extracted in this text-only iteration, and a PDF has no embedded resources to serve, so the resources dictionary is empty.
+ return new ReadingDocumentDto(Path.GetFileNameWithoutExtension(pdfPath), null, null, tableOfContents, spine, new Dictionary(), hasTextContent);
+ }
+
+ ///
+ /// Builds the HTML content of a PDF page, wrapping its extracted text into paragraphs.
+ ///
+ /// The PDF page whose content is built.
+ /// The HTML content of the PDF page.
+ private static string BuildPageHtml(Page page)
+ {
+ // The extracted text comes from the untrusted document, so each line is HTML-encoded before it is wrapped, keeping any embedded markup inert until the host sanitizes the whole section anyway;
+ // the lines are wrapped in paragraphs so that the page reads like a document, instead of one unbroken wall of text.
+ StringBuilder stringBuilder = new();
+ stringBuilder.Append("");
+ string text = page.Text ?? string.Empty;
+ foreach (string line in text.Replace("\r\n", "\n").Split('\n'))
+ {
+ if (string.IsNullOrWhiteSpace(line))
+ continue;
+ stringBuilder.Append("").Append(WebUtility.HtmlEncode(line)).Append("
");
+ }
+ stringBuilder.Append("");
+ return stringBuilder.ToString();
+ }
+
+ ///
+ /// Reads the table of contents of the PDF from the bookmarks of the already open document.
+ ///
+ /// The open PDF document whose bookmarks are read.
+ /// The table of contents of the PDF, or an empty list when the PDF has no usable bookmarks.
+ private static List ReadTableOfContents(PdfDocument pdfDocument)
+ {
+ try
+ {
+ // Many PDFs have no bookmarks at all (for example a book exported from a word processor), in which case the reader simply shows no table of contents instead of failing the whole book.
+ if (!pdfDocument.TryGetBookmarks(out Bookmarks? bookmarks) || bookmarks is null || bookmarks.Roots.Count == 0)
+ return [];
+
+ return [.. bookmarks.Roots.Select(ToTocEntry)];
+ }
+ catch (OperationCanceledException)
+ {
+ // A cancelled parse must not silently succeed with an empty table of contents, so the cancellation is rethrown instead of
+ // being swallowed: the request was aborted, not the bookmarks found unreadable.
+ throw;
+ }
+ catch (Exception)
+ {
+ // The bookmarks of a malformed PDF are best effort, so the table of contents is skipped instead of failing the book; the pages themselves are still readable
+ return [];
+ }
+ }
+
+ ///
+ /// Converts a bookmark of the PDF into a table of contents entry.
+ ///
+ /// The bookmark to convert.
+ /// The converted table of contents entry.
+ private static ReadingTocEntryDto ToTocEntry(BookmarkNode bookmark)
+ {
+ // Only a document bookmark has a destination page; the other bookmark kinds (external, embedded, URI) cannot be navigated inside the reader, so they yield an entry that points nowhere,
+ // and the client simply does not render it as navigable.
+ int? pageNumber = bookmark is DocumentBookmarkNode documentBookmark ? documentBookmark.PageNumber : null;
+ string locationRef = pageNumber is null ? string.Empty : $"page:{pageNumber.Value}";
+ // The nested bookmarks of a bookmark become the children of the entry, preserving the hierarchy of the outline.
+ List children = [.. bookmark.Children.Select(ToTocEntry)];
+ return new ReadingTocEntryDto(bookmark.Title ?? string.Empty, locationRef, children);
+ }
+}
diff --git a/plugins/Lumina.Plugins.Pdf/Core/PdfPlugin.cs b/plugins/Lumina.Plugins.Pdf/Core/PdfPlugin.cs
new file mode 100644
index 00000000..2853b4bc
--- /dev/null
+++ b/plugins/Lumina.Plugins.Pdf/Core/PdfPlugin.cs
@@ -0,0 +1,64 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Plugins.Contracts.Common.Models.DTO.Settings;
+using Lumina.Plugins.Contracts.Core.Plugins;
+using Lumina.Plugins.Pdf.Common.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+#endregion
+
+namespace Lumina.Plugins.Pdf.Core;
+
+///
+/// Plugin that decodes PDF books into a normalized reading document.
+///
+public sealed class PdfPlugin : IPlugin, IPluginServiceRegistrator
+{
+ ///
+ /// The unique identifier of the plugin.
+ ///
+ public static readonly Guid s_pluginId = new("c2f9b8f0-5a4b-4e3d-8b2f-7e4a9c1d3e5f");
+
+ ///
+ /// Gets the unique identifier of the plugin.
+ ///
+ public Guid Id => s_pluginId;
+
+ ///
+ /// Gets the display name of the plugin.
+ ///
+ public string Name => "PDF Reader";
+
+ ///
+ /// Gets the author of the plugin.
+ ///
+ public string Author => "Lumina";
+
+ ///
+ /// Gets the version of the plugin.
+ ///
+ public Version Version => new(1, 0, 0);
+
+ ///
+ /// Gets the description of the plugin.
+ ///
+ public string Description => "Allows reading of PDF format books.";
+
+ ///
+ /// Gets the settings schema of the plugin.
+ ///
+ /// The settings descriptors of the plugin.
+ public IReadOnlyList GetSettingsSchema()
+ {
+ return [];
+ }
+
+ ///
+ /// Registers the services required by the plugin.
+ ///
+ /// The service collection to register the services into.
+ public void RegisterServices(IServiceCollection services)
+ {
+ services.AddPdfReader(pluginId: Id);
+ }
+}
diff --git a/plugins/Lumina.Plugins.Pdf/Core/PdfReader.cs b/plugins/Lumina.Plugins.Pdf/Core/PdfReader.cs
new file mode 100644
index 00000000..a0494e9b
--- /dev/null
+++ b/plugins/Lumina.Plugins.Pdf/Core/PdfReader.cs
@@ -0,0 +1,70 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
+using Lumina.Plugins.Contracts.Core.Reading;
+using Lumina.Plugins.Pdf.Core.Pdf;
+using System.Collections.Generic;
+using System.Runtime.Versioning;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Plugins.Pdf.Core;
+
+///
+/// Book reader for the PDF format.
+///
+///
+/// See for how a PDF is decoded; this class only declares the supported format and delegates the decoding to the parser.
+///
+internal sealed class PdfReader : IBookReader
+{
+ ///
+ /// Gets the file extensions supported by the reader.
+ ///
+ public IReadOnlyList SupportedExtensions => [".pdf"];
+
+ ///
+ /// Gets the media library types the reader supports.
+ ///
+ public IReadOnlyList SupportedLibraryTypes => [LibraryType.EBook, LibraryType.Book];
+
+ ///
+ /// Opens the PDF stored at , extracting its pages into ,
+ /// and returns its normalized reading document. When the PDF is rendered as page images, the page images are not rendered
+ /// here: a page is rendered only when its resource is requested, so that opening a large book is instant.
+ ///
+ /// The file system path of the PDF.
+ /// The directory into which the pages of the PDF are extracted.
+ /// Whether the PDF is rendered as page images instead of extracting its text layer. This is used for scanned PDFs whose pages are only images and therefore yield no text.
+ /// Cancellation token that can be used to stop the execution.
+ /// The normalized reading document of the PDF.
+ public Task OpenAsync(string path, string workingDirectory, bool shouldRenderPdfAsImages, CancellationToken cancellationToken)
+ {
+ return Task.FromResult(PdfDocumentParser.Parse(path, workingDirectory, shouldRenderPdfAsImages, cancellationToken));
+ }
+
+ ///
+ /// Produces the resource identified by of the PDF stored at ,
+ /// rendering the requested page to an image on demand. Only the page image whose resource is requested is rendered,
+ /// so that the user does not wait for every page of a large book to be rendered before seeing the first one.
+ ///
+ /// The file system path of the PDF.
+ /// The directory into which the pages of the PDF are extracted.
+ /// The opaque resource key of the resource to produce, of the form page:{n}.
+ /// Cancellation token that can be used to stop the execution.
+ /// The binary data of the rendered page image.
+ ///
+ /// The PDFtoImage and SkiaSharp APIs used by are annotated with the supported
+ /// platforms of the rendering engine, so this method must repeat that restriction or the CA1416 analyzer, which is a build error
+ /// here, flags the call. The attributes must not be removed, even though Windows, Linux and macOS are the only platforms Lumina runs on.
+ ///
+ [SupportedOSPlatform("windows")]
+ [SupportedOSPlatform("linux")]
+ [SupportedOSPlatform("macos")]
+ public Task GetResourceAsync(string path, string workingDirectory, string resourceKey, CancellationToken cancellationToken)
+ {
+ byte[] data = PdfDocumentParser.RenderResource(path, resourceKey, cancellationToken);
+ return Task.FromResult(data);
+ }
+}
diff --git a/plugins/Lumina.Plugins.Pdf/Lumina.Plugins.Pdf.csproj b/plugins/Lumina.Plugins.Pdf/Lumina.Plugins.Pdf.csproj
new file mode 100644
index 00000000..55750f63
--- /dev/null
+++ b/plugins/Lumina.Plugins.Pdf/Lumina.Plugins.Pdf.csproj
@@ -0,0 +1,50 @@
+
+
+ net10.0
+ disable
+ enable
+ $(SolutionDir)..\bin\plugins\
+ false
+ true
+ true
+ $(WarningsNotAsErrors);NU1901;NU1902;NU1903;NU1904
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+ <_CurrentRidNatives Include="$(OutDir)runtimes\$(NETCoreSdkRuntimeIdentifier)\native\*" />
+
+
+
+
+
+
+
+
+ false
+ runtime
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/plugins/Lumina.Plugins.Pdf/Properties/AssemblyInfo.cs b/plugins/Lumina.Plugins.Pdf/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000..fdfba7b5
--- /dev/null
+++ b/plugins/Lumina.Plugins.Pdf/Properties/AssemblyInfo.cs
@@ -0,0 +1,4 @@
+using System.Runtime.CompilerServices;
+
+[assembly: InternalsVisibleTo("Lumina.Plugins.Pdf.UnitTests")]
+[assembly: InternalsVisibleTo("Lumina.Plugins.Pdf.Fixtures")]
diff --git a/src/Lumina.Application/Common/DataAccess/Entities/Plugins/LibraryBookReaderConfigurationEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/Plugins/LibraryBookReaderConfigurationEntity.cs
new file mode 100644
index 00000000..a4ab4fc6
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Entities/Plugins/LibraryBookReaderConfigurationEntity.cs
@@ -0,0 +1,54 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Entities.Common;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Entities.Plugins;
+
+///
+/// Repository entity for the configuration of a book reader of a media library.
+///
+[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
+public class LibraryBookReaderConfigurationEntity : IStorageEntity, IAuditableEntity
+{
+ ///
+ /// Gets or sets the Id of the configuration.
+ ///
+ public required Guid Id { get; init; }
+
+ ///
+ /// Gets or sets the Id of the media library the configuration belongs to.
+ ///
+ public required Guid LibraryId { get; set; }
+
+ ///
+ /// Gets or sets the Id of the plugin providing the book reader.
+ ///
+ public required Guid PluginId { get; set; }
+
+ ///
+ /// Gets or sets whether the book reader is enabled for the media library.
+ ///
+ public required bool IsEnabled { get; set; }
+
+ ///
+ /// Gets or sets the time and date when the entity was added.
+ ///
+ public required DateTime CreatedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the Id of the user that created the entity.
+ ///
+ public required Guid CreatedBy { get; set; }
+
+ ///
+ /// Gets or sets the optional time and date when the entity was updated.
+ ///
+ public DateTime? UpdatedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the optional Id of the user that updated the entity.
+ ///
+ public required Guid? UpdatedBy { get; set; }
+}
diff --git a/src/Lumina.Application/Common/DataAccess/Entities/UsersManagement/UserSettingsEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/UsersManagement/UserSettingsEntity.cs
index 5e8de0bf..718dc8cb 100644
--- a/src/Lumina.Application/Common/DataAccess/Entities/UsersManagement/UserSettingsEntity.cs
+++ b/src/Lumina.Application/Common/DataAccess/Entities/UsersManagement/UserSettingsEntity.cs
@@ -47,6 +47,19 @@ public class UserSettingsEntity : IStorageEntity, IAuditableEntity
///
public bool ShouldAggregateMetadataWhenMissing { get; set; }
+ ///
+ /// Gets or sets whether PDF books are rendered as page images for the user, or not. Rendering PDFs as images preserves the
+ /// original layout, but the pages are not selectable or searchable, unlike their text layer.
+ ///
+ public bool ShouldRenderPdfAsImages { get; set; }
+
+ ///
+ /// Gets or sets whether the styles of the book content are preserved when it is rendered for the user, or not. Preserving them
+ /// keeps the original look of a book (its fonts, colors, and alignment), but the styles of a book can load resources from
+ /// external servers, which those servers could observe; stripping them removes that possibility, at the cost of the look of the book.
+ ///
+ public bool ShouldPreserveBookStyles { get; set; }
+
///
/// Gets or sets the time and date when the entity was added.
///
diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Plugins/ILibraryBookReaderConfigurationRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Plugins/ILibraryBookReaderConfigurationRepository.cs
new file mode 100644
index 00000000..0f0f3c55
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Repositories/Plugins/ILibraryBookReaderConfigurationRepository.cs
@@ -0,0 +1,68 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.Common.Primitives;
+using Lumina.Application.Common.DataAccess.Entities.Plugins;
+using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Repositories.Plugins;
+
+///
+/// Interface for the repository for the book reader configurations of media libraries.
+///
+public interface ILibraryBookReaderConfigurationRepository : IRepository
+{
+ ///
+ /// Gets all the book reader configurations of the media library identified by .
+ ///
+ /// The Id of the media library whose book reader configurations are retrieved.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either a collection of , or an error.
+ Task>> GetByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
+
+ ///
+ /// Gets the book reader configuration of the media library identified by for the plugin identified by .
+ ///
+ /// The Id of the media library whose book reader configuration is retrieved.
+ /// The Id of the plugin whose book reader configuration is retrieved.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the , or an error.
+ Task> GetByLibraryAndPluginIdAsync(Guid libraryId, Guid pluginId, CancellationToken cancellationToken);
+
+ ///
+ /// Inserts the provided into the storage medium, or updates it when it already exists.
+ ///
+ /// The book reader configuration to insert or update.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ Task> UpsertAsync(LibraryBookReaderConfigurationEntity configuration, CancellationToken cancellationToken);
+
+ ///
+ /// Deletes all the book reader configurations of the media library identified by .
+ ///
+ /// The Id of the media library whose book reader configurations are deleted.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ Task> DeleteByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
+
+ ///
+ /// Deletes all the book reader configurations referencing the plugin identified by .
+ ///
+ /// The Id of the plugin whose book reader configurations are deleted.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ Task> DeleteByPluginIdAsync(Guid pluginId, CancellationToken cancellationToken);
+
+ ///
+ /// Deletes the book reader configurations of the media library identified by that reference
+ /// one of the plugins identified by .
+ ///
+ /// The Id of the media library whose book reader configurations are deleted.
+ /// The Ids of the plugins whose configurations of the media library are deleted.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ Task> DeleteByLibraryIdAndPluginIdsAsync(Guid libraryId, IEnumerable pluginIds, CancellationToken cancellationToken);
+}
diff --git a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs
index b314bfab..f748d5dd 100644
--- a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs
+++ b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs
@@ -82,6 +82,11 @@ public interface IUnitOfWork
///
IArtworkProviderConfigurationRepository ArtworkProviderConfigurationRepository { get; }
+ ///
+ /// Gets the library book reader configuration repository.
+ ///
+ ILibraryBookReaderConfigurationRepository LibraryBookReaderConfigurationRepository { get; }
+
///
/// Gets the plugin repository.
///
diff --git a/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs b/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs
index b8f5bc7d..306cfeb9 100644
--- a/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs
+++ b/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs
@@ -12,13 +12,13 @@ using System.Reflection;
namespace Lumina.Application.Common.DependencyInjection;
///
-/// Contains all services of the Application layer.
+/// Utility class for registering the services of the Application layer into the Dependency Injection container.
///
[ExcludeFromCodeCoverage]
public static class ApplicationLayerServices
{
///
- /// Registers the services of the Application layer into the dependency injection container.
+ /// Registers the services of the Application layer into the Dependency Injection container.
///
/// The service collection to add the services to.
/// The updated .
@@ -52,7 +52,7 @@ public static class ApplicationLayerServices
continue;
}
- // wrap query, command, and domain event handlers in their telemetry decorator, so that every invocation emits traces, metrics, and structured logs
+ // Wrap query, command, and domain event handlers in their telemetry decorator, so that every invocation emits traces, metrics, and structured logs.
services.AddScoped(registration.Contract, serviceProvider =>
{
object handler = ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, registration.Implementation);
diff --git a/src/Lumina.Application/Common/Infrastructure/Plugins/IMediaLibraryProviderConfigurationStore.cs b/src/Lumina.Application/Common/Infrastructure/Plugins/IMediaLibraryProviderConfigurationStore.cs
index 6f81bcbd..3f911baa 100644
--- a/src/Lumina.Application/Common/Infrastructure/Plugins/IMediaLibraryProviderConfigurationStore.cs
+++ b/src/Lumina.Application/Common/Infrastructure/Plugins/IMediaLibraryProviderConfigurationStore.cs
@@ -58,4 +58,38 @@ public interface IMediaLibraryProviderConfigurationStore
/// Cancellation token that can be used to stop the execution.
/// An representing either a successful operation, or an error.
Task> RemoveProviderConfigurationsAsync(Guid pluginId, CancellationToken cancellationToken);
+
+ ///
+ /// 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 .
+ ///
+ /// The Id of the media library whose book reader configurations are ensured.
+ /// The type of the media library, used to determine the plugins whose book readers apply.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ Task> EnsureBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
+
+ ///
+ /// Replaces the book reader configurations of the media library identified by so that they match the plugins supporting the provided library type.
+ ///
+ /// The Id of the media library whose book reader configurations are reconciled.
+ /// The type of the media library, used to determine the plugins whose book readers apply.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ Task> ReconcileBookReaderConfigurationsAsync(Guid libraryId, LibraryType libraryType, CancellationToken cancellationToken);
+
+ ///
+ /// Deletes all the book reader configurations of the media library identified by .
+ ///
+ /// The Id of the media library whose book reader configurations are deleted.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ Task> RemoveBookReaderConfigurationsForLibraryAsync(Guid libraryId, CancellationToken cancellationToken);
+
+ ///
+ /// Deletes all the book reader configurations referencing the plugin identified by .
+ ///
+ /// The Id of the plugin whose book reader configurations are deleted.
+ /// Cancellation token that can be used to stop the execution.
+ /// An representing either a successful operation, or an error.
+ Task> RemoveBookReaderConfigurationsAsync(Guid pluginId, CancellationToken cancellationToken);
}
diff --git a/src/Lumina.Application/Common/Infrastructure/Reading/IBookReaderEnablementCache.cs b/src/Lumina.Application/Common/Infrastructure/Reading/IBookReaderEnablementCache.cs
new file mode 100644
index 00000000..b4025a78
--- /dev/null
+++ b/src/Lumina.Application/Common/Infrastructure/Reading/IBookReaderEnablementCache.cs
@@ -0,0 +1,48 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+#endregion
+
+namespace Lumina.Application.Common.Infrastructure.Reading;
+
+///
+/// Cache of whether the book reader of a plugin is enabled for a media library. The enablement is read from the database on its first
+/// use and cached afterwards, because it is consulted on every section and resource request, and it only changes when the user toggles
+/// a reader or a plugin is uninstalled; those operations invalidate the affected entries.
+///
+public interface IBookReaderEnablementCache
+{
+ ///
+ /// Gets the cached enablement of the book reader of the plugin identified by for the media library identified by .
+ ///
+ /// The Id of the media library whose book reader enablement is retrieved.
+ /// The Id of the plugin providing the book reader.
+ /// The cached enablement, or when it is not cached yet.
+ bool? Get(Guid libraryId, Guid pluginId);
+
+ ///
+ /// Caches the enablement of the book reader of the plugin identified by for the media library identified by .
+ ///
+ /// The Id of the media library whose book reader enablement is cached.
+ /// The Id of the plugin providing the book reader.
+ /// Whether the book reader is enabled for the media library.
+ void Set(Guid libraryId, Guid pluginId, bool isEnabled);
+
+ ///
+ /// Removes the cached enablement of the book reader of the plugin identified by for the media library identified by .
+ ///
+ /// The Id of the media library whose book reader enablement is invalidated.
+ /// The Id of the plugin providing the book reader.
+ void Invalidate(Guid libraryId, Guid pluginId);
+
+ ///
+ /// Removes every cached enablement of the media library identified by .
+ ///
+ /// The Id of the media library whose book reader enablements are invalidated.
+ void InvalidateLibrary(Guid libraryId);
+
+ ///
+ /// Removes every cached enablement of the plugin identified by .
+ ///
+ /// The Id of the plugin whose book reader enablements are invalidated.
+ void InvalidatePlugin(Guid pluginId);
+}
diff --git a/src/Lumina.Application/Common/Infrastructure/Reading/IBookReaderRegistry.cs b/src/Lumina.Application/Common/Infrastructure/Reading/IBookReaderRegistry.cs
new file mode 100644
index 00000000..b950c4a6
--- /dev/null
+++ b/src/Lumina.Application/Common/Infrastructure/Reading/IBookReaderRegistry.cs
@@ -0,0 +1,18 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Collections.Generic;
+#endregion
+
+namespace Lumina.Application.Common.Infrastructure.Reading;
+
+///
+/// Registry of the book readers provided by the loaded plugins.
+///
+public interface IBookReaderRegistry
+{
+ ///
+ /// Gets the file extensions supported by the book readers of each loaded plugin, keyed by the Id of the plugin.
+ ///
+ /// The supported extensions of the book readers, keyed by the Id of the plugin providing them.
+ IReadOnlyDictionary> GetSupportedExtensionsByPluginId();
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/AddBookRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/AddBookRequestMapping.cs
index 37aed932..0db3fb9f 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/AddBookRequestMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/AddBookRequestMapping.cs
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
-using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
+using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.AddBook;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
#endregion
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetBooksLiteRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetBooksLiteRequestMapping.cs
index 1a7ca813..8635f179 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetBooksLiteRequestMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetBooksLiteRequestMapping.cs
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DTO.Filtering;
using Lumina.Application.Common.DTO.Pagination;
-using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooksLite;
+using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooksLite;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
#endregion
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetBooksRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetBooksRequestMapping.cs
index a3b3255a..a1f6b92f 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetBooksRequestMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetBooksRequestMapping.cs
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DTO.Filtering;
using Lumina.Application.Common.DTO.Pagination;
-using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
+using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooks;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
#endregion
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetReadingAvailabilityRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetReadingAvailabilityRequestMapping.cs
new file mode 100644
index 00000000..4737e11e
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetReadingAvailabilityRequestMapping.cs
@@ -0,0 +1,24 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingAvailability;
+using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
+
+///
+/// Extension methods for converting .
+///
+public static class GetReadingAvailabilityRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted query.
+ public static GetReadingAvailabilityQuery ToQuery(this GetReadingAvailabilityRequest request)
+ {
+ return new GetReadingAvailabilityQuery(
+ request.BookId
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetReadingManifestRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetReadingManifestRequestMapping.cs
new file mode 100644
index 00000000..79e512c9
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetReadingManifestRequestMapping.cs
@@ -0,0 +1,24 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingManifest;
+using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
+
+///
+/// Extension methods for converting .
+///
+public static class GetReadingManifestRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted query.
+ public static GetReadingManifestQuery ToQuery(this GetReadingManifestRequest request)
+ {
+ return new GetReadingManifestQuery(
+ request.BookId
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetReadingResourceRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetReadingResourceRequestMapping.cs
new file mode 100644
index 00000000..68b5927c
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetReadingResourceRequestMapping.cs
@@ -0,0 +1,25 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingResource;
+using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
+
+///
+/// Extension methods for converting .
+///
+public static class GetReadingResourceRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted query.
+ public static GetReadingResourceQuery ToQuery(this GetReadingResourceRequest request)
+ {
+ return new GetReadingResourceQuery(
+ request.BookId,
+ request.ResourceKey
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetReadingSectionRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetReadingSectionRequestMapping.cs
new file mode 100644
index 00000000..6ed66d56
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/GetReadingSectionRequestMapping.cs
@@ -0,0 +1,25 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingSection;
+using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
+
+///
+/// Extension methods for converting .
+///
+public static class GetReadingSectionRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted query.
+ public static GetReadingSectionQuery ToQuery(this GetReadingSectionRequest request)
+ {
+ return new GetReadingSectionQuery(
+ request.BookId,
+ request.LocationRef
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/ReadingDocumentDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/ReadingDocumentDtoMapping.cs
new file mode 100644
index 00000000..5a2fe2b5
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/ReadingDocumentDtoMapping.cs
@@ -0,0 +1,31 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+using System.Linq;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
+
+///
+/// Extension methods for converting .
+///
+public static class ReadingDocumentDtoMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The reading document to be converted.
+ /// The converted reading manifest response.
+ public static ReadingManifestResponse ToResponse(this ReadingDocumentDto document)
+ {
+ return new ReadingManifestResponse(
+ document.Title,
+ document.Author,
+ document.CoverResourceKey,
+ [.. document.TableOfContents.Select(entry => entry.ToResponse())],
+ [.. document.Spine.Select(spineItem => new ReadingSpineItemResponse(spineItem.LocationRef, spineItem.Title))],
+ [.. document.Resources.Keys],
+ document.HasTextContent
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/ReadingTocEntryDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/ReadingTocEntryDtoMapping.cs
new file mode 100644
index 00000000..04dbddd2
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/ReadingTocEntryDtoMapping.cs
@@ -0,0 +1,27 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+using System.Linq;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
+
+///
+/// Extension methods for converting .
+///
+public static class ReadingTocEntryDtoMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The table of contents entry to be converted.
+ /// The converted table of contents entry response.
+ public static ReadingTocEntryResponse ToResponse(this ReadingTocEntryDto entry)
+ {
+ return new ReadingTocEntryResponse(
+ entry.Label,
+ entry.LocationRef,
+ [.. entry.Children.Select(child => child.ToResponse())]
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/Plugins/GetLibraryBookReadersRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Plugins/GetLibraryBookReadersRequestMapping.cs
new file mode 100644
index 00000000..39c06d81
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Plugins/GetLibraryBookReadersRequestMapping.cs
@@ -0,0 +1,24 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Core.Plugins.Queries.GetLibraryBookReaders;
+using Lumina.Contracts.Requests.Plugins;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.Plugins;
+
+///
+/// Extension methods for converting .
+///
+public static class GetLibraryBookReadersRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted query.
+ public static GetLibraryBookReadersQuery ToQuery(this GetLibraryBookReadersRequest request)
+ {
+ return new GetLibraryBookReadersQuery(
+ request.LibraryId
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/Plugins/LibraryBookReaderConfigurationEntityMapping.cs b/src/Lumina.Application/Common/Mapping/Plugins/LibraryBookReaderConfigurationEntityMapping.cs
new file mode 100644
index 00000000..5ea10108
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Plugins/LibraryBookReaderConfigurationEntityMapping.cs
@@ -0,0 +1,30 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Entities.Plugins;
+using Lumina.Contracts.Responses.Plugins;
+using System.Collections.Generic;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.Plugins;
+
+///
+/// Extension methods for converting .
+///
+public static class LibraryBookReaderConfigurationEntityMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The repository entity to be converted.
+ /// The display name of the book reader.
+ /// The file extensions supported by the book reader.
+ /// The converted response.
+ public static LibraryBookReaderResponse ToResponse(this LibraryBookReaderConfigurationEntity configuration, string readerName, IReadOnlyList supportedExtensions)
+ {
+ return new LibraryBookReaderResponse(
+ configuration.PluginId,
+ readerName,
+ supportedExtensions,
+ configuration.IsEnabled
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/Plugins/SetLibraryBookReaderEnabledRequestMapping.cs b/src/Lumina.Application/Common/Mapping/Plugins/SetLibraryBookReaderEnabledRequestMapping.cs
new file mode 100644
index 00000000..727601ca
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/Plugins/SetLibraryBookReaderEnabledRequestMapping.cs
@@ -0,0 +1,26 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
+using Lumina.Contracts.Requests.Plugins;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.Plugins;
+
+///
+/// Extension methods for converting .
+///
+public static class SetLibraryBookReaderEnabledRequestMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The request to be converted.
+ /// The converted command.
+ public static SetLibraryBookReaderEnabledCommand ToCommand(this SetLibraryBookReaderEnabledRequest request)
+ {
+ return new SetLibraryBookReaderEnabledCommand(
+ request.LibraryId,
+ request.PluginId,
+ request.IsEnabled
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/UsersManagement/Users/UpdateUserSettingsRequestMapping.cs b/src/Lumina.Application/Common/Mapping/UsersManagement/Users/UpdateUserSettingsRequestMapping.cs
index aff25a7d..e4c9c955 100644
--- a/src/Lumina.Application/Common/Mapping/UsersManagement/Users/UpdateUserSettingsRequestMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/UsersManagement/Users/UpdateUserSettingsRequestMapping.cs
@@ -22,7 +22,9 @@ public static class UpdateUserSettingsRequestMapping
request.ItemsPerPage,
request.ShouldIgnoreThePrefixForAlphaPicker,
request.IsThemeCachingEnabled,
- request.ShouldAggregateMetadataWhenMissing
+ request.ShouldAggregateMetadataWhenMissing,
+ request.ShouldRenderPdfAsImages,
+ request.ShouldPreserveBookStyles
);
}
}
diff --git a/src/Lumina.Application/Common/Mapping/UsersManagement/Users/UserSettingsEntityMapping.cs b/src/Lumina.Application/Common/Mapping/UsersManagement/Users/UserSettingsEntityMapping.cs
index b53990fd..f556846c 100644
--- a/src/Lumina.Application/Common/Mapping/UsersManagement/Users/UserSettingsEntityMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/UsersManagement/Users/UserSettingsEntityMapping.cs
@@ -30,7 +30,9 @@ public static class UserSettingsEntityMapping
repositoryEntity.ItemsPerPage,
repositoryEntity.ShouldIgnoreThePrefixForAlphaPicker,
repositoryEntity.IsThemeCachingEnabled,
- repositoryEntity.ShouldAggregateMetadataWhenMissing
+ repositoryEntity.ShouldAggregateMetadataWhenMissing,
+ repositoryEntity.ShouldRenderPdfAsImages,
+ repositoryEntity.ShouldPreserveBookStyles
);
}
@@ -47,7 +49,9 @@ public static class UserSettingsEntityMapping
repositoryEntity.ItemsPerPage,
repositoryEntity.ShouldIgnoreThePrefixForAlphaPicker,
repositoryEntity.IsThemeCachingEnabled,
- repositoryEntity.ShouldAggregateMetadataWhenMissing
+ repositoryEntity.ShouldAggregateMetadataWhenMissing,
+ repositoryEntity.ShouldRenderPdfAsImages,
+ repositoryEntity.ShouldPreserveBookStyles
);
}
}
diff --git a/src/Lumina.Application/Common/Mapping/UsersManagement/Users/UserSettingsMapping.cs b/src/Lumina.Application/Common/Mapping/UsersManagement/Users/UserSettingsMapping.cs
index cde37e56..01c0e99a 100644
--- a/src/Lumina.Application/Common/Mapping/UsersManagement/Users/UserSettingsMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/UsersManagement/Users/UserSettingsMapping.cs
@@ -26,7 +26,9 @@ public static class UserSettingsMapping
ItemsPerPage = domainEntity.ItemsPerPage,
ShouldIgnoreThePrefixForAlphaPicker = domainEntity.ShouldIgnoreThePrefixForAlphaPicker,
IsThemeCachingEnabled = domainEntity.IsThemeCachingEnabled,
- ShouldAggregateMetadataWhenMissing = domainEntity.ShouldAggregateMetadataWhenMissing
+ ShouldAggregateMetadataWhenMissing = domainEntity.ShouldAggregateMetadataWhenMissing,
+ ShouldRenderPdfAsImages = domainEntity.ShouldRenderPdfAsImages,
+ ShouldPreserveBookStyles = domainEntity.ShouldPreserveBookStyles
};
}
@@ -43,7 +45,9 @@ public static class UserSettingsMapping
domainEntity.ItemsPerPage,
domainEntity.ShouldIgnoreThePrefixForAlphaPicker,
domainEntity.IsThemeCachingEnabled,
- domainEntity.ShouldAggregateMetadataWhenMissing
+ domainEntity.ShouldAggregateMetadataWhenMissing,
+ domainEntity.ShouldRenderPdfAsImages,
+ domainEntity.ShouldPreserveBookStyles
);
}
}
diff --git a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryMediaItemDeletedDomainEventHandler.cs b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryMediaItemDeletedDomainEventHandler.cs
index 84050f4e..551cd269 100644
--- a/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryMediaItemDeletedDomainEventHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/Management/Events/LibraryMediaItemDeletedDomainEventHandler.cs
@@ -2,7 +2,7 @@
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.UoW;
-using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Artwork;
+using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Artwork;
using Lumina.Domain.Common.Events;
using Lumina.Domain.Common.Exceptions;
using Lumina.Domain.Common.Primitives;
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Artwork/IBookArtworkService.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Artwork/IBookArtworkService.cs
similarity index 98%
rename from src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Artwork/IBookArtworkService.cs
rename to src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Artwork/IBookArtworkService.cs
index 7967bf82..8db5934c 100644
--- a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Artwork/IBookArtworkService.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Artwork/IBookArtworkService.cs
@@ -6,7 +6,7 @@ using System.Threading;
using System.Threading.Tasks;
#endregion
-namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Artwork;
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Artwork;
///
/// Interface for the service for storing the artwork of a book into the internal media directory and serving its relative path.
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBook/AddBookCommand.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Commands/AddBook/AddBookCommand.cs
similarity index 98%
rename from src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBook/AddBookCommand.cs
rename to src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Commands/AddBook/AddBookCommand.cs
index 0d0b29c9..d83688e4 100644
--- a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBook/AddBookCommand.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Commands/AddBook/AddBookCommand.cs
@@ -9,7 +9,7 @@ using System.Collections.Generic;
using System.Diagnostics;
#endregion
-namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.AddBook;
///
/// Command for adding a book.
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBook/AddBookCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Commands/AddBook/AddBookCommandHandler.cs
similarity index 99%
rename from src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBook/AddBookCommandHandler.cs
rename to src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Commands/AddBook/AddBookCommandHandler.cs
index 82be9a0d..ea190340 100644
--- a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBook/AddBookCommandHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Commands/AddBook/AddBookCommandHandler.cs
@@ -23,7 +23,7 @@ using System.Threading.Tasks;
using Lumina.Contracts.DTO.MediaContributors;
#endregion
-namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.AddBook;
///
/// Handler for the command to add a book.
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBook/AddBookCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Commands/AddBook/AddBookCommandValidator.cs
similarity index 99%
rename from src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBook/AddBookCommandValidator.cs
rename to src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Commands/AddBook/AddBookCommandValidator.cs
index 0f7a760f..bcad4b8a 100644
--- a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBook/AddBookCommandValidator.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Commands/AddBook/AddBookCommandValidator.cs
@@ -6,7 +6,7 @@ using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
#endregion
-namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.AddBook;
///
/// Validates the needed validation rules for .
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooks/GetBooksQuery.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooks/GetBooksQuery.cs
similarity index 96%
rename from src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooks/GetBooksQuery.cs
rename to src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooks/GetBooksQuery.cs
index 5aef1242..480017ba 100644
--- a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooks/GetBooksQuery.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooks/GetBooksQuery.cs
@@ -5,7 +5,7 @@ using Lumina.Application.Common.DTO.Pagination;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
#endregion
-namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooks;
///
/// Query for getting all the books of a media library.
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooks/GetBooksQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooks/GetBooksQueryHandler.cs
similarity index 99%
rename from src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooks/GetBooksQueryHandler.cs
rename to src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooks/GetBooksQueryHandler.cs
index 44e25dfc..c75ec08b 100644
--- a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooks/GetBooksQueryHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooks/GetBooksQueryHandler.cs
@@ -19,7 +19,7 @@ using Lumina.Application.Common.Errors;
using Lumina.Application.Common.DTO.Pagination;
#endregion
-namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooks;
///
/// Handler for the query to get all books.
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooks/GetBooksQueryValidator.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooks/GetBooksQueryValidator.cs
similarity index 95%
rename from src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooks/GetBooksQueryValidator.cs
rename to src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooks/GetBooksQueryValidator.cs
index 576e755d..d091269c 100644
--- a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooks/GetBooksQueryValidator.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooks/GetBooksQueryValidator.cs
@@ -5,7 +5,7 @@ using Lumina.Domain.Common.Errors;
using System;
#endregion
-namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooks;
///
/// Validates the needed validation rules for .
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksLite/GetBooksLiteQuery.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooksLite/GetBooksLiteQuery.cs
similarity index 95%
rename from src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksLite/GetBooksLiteQuery.cs
rename to src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooksLite/GetBooksLiteQuery.cs
index 0aec829f..87dd8ef0 100644
--- a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksLite/GetBooksLiteQuery.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooksLite/GetBooksLiteQuery.cs
@@ -5,7 +5,7 @@ using Lumina.Application.Common.DTO.Pagination;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
#endregion
-namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooksLite;
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooksLite;
///
/// Query for getting the lightweight details of all the books of a media library.
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksLite/GetBooksLiteQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooksLite/GetBooksLiteQueryHandler.cs
similarity index 98%
rename from src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksLite/GetBooksLiteQueryHandler.cs
rename to src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooksLite/GetBooksLiteQueryHandler.cs
index f7c2ecf5..79c58486 100644
--- a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksLite/GetBooksLiteQueryHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooksLite/GetBooksLiteQueryHandler.cs
@@ -19,7 +19,7 @@ using Lumina.Application.Common.Errors;
using Lumina.Application.Common.DTO.Pagination;
#endregion
-namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooksLite;
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooksLite;
///
/// Handler for the query to get the lightweight details of all books.
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksLite/GetBooksLiteQueryValidator.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooksLite/GetBooksLiteQueryValidator.cs
similarity index 97%
rename from src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksLite/GetBooksLiteQueryValidator.cs
rename to src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooksLite/GetBooksLiteQueryValidator.cs
index 6c8fb14b..ba7c48eb 100644
--- a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksLite/GetBooksLiteQueryValidator.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Queries/GetBooksLite/GetBooksLiteQueryValidator.cs
@@ -6,7 +6,7 @@ using Lumina.Domain.Common.Errors;
using System;
#endregion
-namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooksLite;
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetBooksLite;
///
/// Validates the needed validation rules for .
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingAvailability/GetReadingAvailabilityQuery.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingAvailability/GetReadingAvailabilityQuery.cs
new file mode 100644
index 00000000..94ab3754
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingAvailability/GetReadingAvailabilityQuery.cs
@@ -0,0 +1,14 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingAvailability;
+
+///
+/// Query for checking the reading availability of a book.
+///
+/// The Id of the book whose reading availability is checked.
+public record GetReadingAvailabilityQuery(
+ Guid BookId
+) : IQuery;
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingAvailability/GetReadingAvailabilityQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingAvailability/GetReadingAvailabilityQueryHandler.cs
new file mode 100644
index 00000000..b1d8b9c4
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingAvailability/GetReadingAvailabilityQueryHandler.cs
@@ -0,0 +1,95 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
+using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Infrastructure.Authentication;
+using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+using Lumina.Domain.Common.Primitives;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingAvailability;
+
+///
+/// Handler for the query to check the reading availability of a book.
+///
+public class GetReadingAvailabilityQueryHandler : IQueryHandler>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IAuthorizationService _authorizationService;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IBookReadingService _bookReadingService;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected service for authorization related functionality.
+ /// Injected service to retrieve the current user information.
+ /// Injected service for reading books using the book reader plugins.
+ /// Injected validator for application validation rules.
+ public GetReadingAvailabilityQueryHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IBookReadingService bookReadingService, IValidator validator)
+ {
+ _unitOfWork = unitOfWork;
+ _authorizationService = authorizationService;
+ _currentUserService = currentUserService;
+ _bookReadingService = bookReadingService;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the query to check the reading availability of a book.
+ ///
+ /// The query to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either the reading availability of the book, or an error.
+ ///
+ public async Task> HandleAsync(GetReadingAvailabilityQuery query, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ // An authenticated request must always carry a user identity.
+ Guid? currentUserId = _currentUserService.UserId;
+ if (currentUserId is null)
+ return ApplicationErrors.Authorization.NotAuthorized;
+ Guid userId = currentUserId.Value;
+
+ // The authorization policy works on the media library, so the book is fetched first to learn its LibraryId, and
+ // the library is fetched afterwards for its type, which the reader plugins match against when resolving the format.
+ Result getBookResult = await _unitOfWork.BookRepository.GetByIdAsync(query.BookId, cancellationToken).ConfigureAwait(false);
+ if (getBookResult.IsFailure)
+ return getBookResult.Errors;
+ if (getBookResult.Value is null)
+ return DomainErrors.Reading.BookNotFound;
+ BookEntity book = getBookResult.Value;
+
+ // Admins can read the books of any library; for everyone else, only their own libraries.
+ bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync(
+ userId, new LibraryOwnershipPolicyContext(book.LibraryId), cancellationToken).ConfigureAwait(false);
+ if (!canAccessLibrary)
+ return ApplicationErrors.Authorization.NotAuthorized;
+
+ Result getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(book.LibraryId, cancellationToken).ConfigureAwait(false);
+ if (getLibraryResult.IsFailure)
+ return getLibraryResult.Errors;
+ if (getLibraryResult.Value is null)
+ return DomainErrors.Library.LibraryNotFound;
+ LibraryEntity library = getLibraryResult.Value;
+
+ return await _bookReadingService.GetAvailabilityAsync(book.Id, book.LibraryId, book.Path, library.LibraryType, cancellationToken).ConfigureAwait(false);
+ }
+}
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingAvailability/GetReadingAvailabilityQueryValidator.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingAvailability/GetReadingAvailabilityQueryValidator.cs
new file mode 100644
index 00000000..8207145e
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingAvailability/GetReadingAvailabilityQueryValidator.cs
@@ -0,0 +1,24 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Domain.Common.Errors;
+using System;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingAvailability;
+
+///
+/// Validates the needed validation rules for .
+///
+public class GetReadingAvailabilityQueryValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetReadingAvailabilityQueryValidator()
+ {
+ RuleFor(query => query.BookId)
+ .NotEmpty()
+ .WithError(Errors.Reading.BookIdCannotBeEmpty);
+ }
+}
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingManifest/GetReadingManifestQuery.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingManifest/GetReadingManifestQuery.cs
new file mode 100644
index 00000000..ebae8e5b
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingManifest/GetReadingManifestQuery.cs
@@ -0,0 +1,14 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingManifest;
+
+///
+/// Query for getting the reading manifest of a book.
+///
+/// The Id of the book whose reading manifest is retrieved.
+public record GetReadingManifestQuery(
+ Guid BookId
+) : IQuery;
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingManifest/GetReadingManifestQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingManifest/GetReadingManifestQueryHandler.cs
new file mode 100644
index 00000000..302c74f3
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingManifest/GetReadingManifestQueryHandler.cs
@@ -0,0 +1,103 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
+using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
+using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Infrastructure.Authentication;
+using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+using Lumina.Domain.Common.Primitives;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingManifest;
+
+///
+/// Handler for the query to get the reading manifest of a book.
+///
+public class GetReadingManifestQueryHandler : IQueryHandler>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IAuthorizationService _authorizationService;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IBookReadingService _bookReadingService;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected service for authorization related functionality.
+ /// Injected service to retrieve the current user information.
+ /// Injected service for reading books using the book reader plugins.
+ /// Injected validator for application validation rules.
+ public GetReadingManifestQueryHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IBookReadingService bookReadingService, IValidator validator)
+ {
+ _unitOfWork = unitOfWork;
+ _authorizationService = authorizationService;
+ _currentUserService = currentUserService;
+ _bookReadingService = bookReadingService;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the query to get the reading manifest of a book.
+ ///
+ /// The query to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either the reading manifest of the book, or an error.
+ ///
+ public async Task> HandleAsync(GetReadingManifestQuery query, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ // An authenticated request must always carry a user identity.
+ Guid? currentUserId = _currentUserService.UserId;
+ if (currentUserId is null)
+ return ApplicationErrors.Authorization.NotAuthorized;
+ Guid userId = currentUserId.Value;
+
+ // The authorization policy works on the media library, so the book is fetched first to learn its LibraryId, and
+ // the library is fetched afterwards for its type, which the reader plugins match against when resolving the format.
+ Result getBookResult = await _unitOfWork.BookRepository.GetByIdAsync(query.BookId, cancellationToken).ConfigureAwait(false);
+ if (getBookResult.IsFailure)
+ return getBookResult.Errors;
+ if (getBookResult.Value is null)
+ return DomainErrors.Reading.BookNotFound;
+ BookEntity book = getBookResult.Value;
+
+ // Admins can read the books of any library; for everyone else, only their own libraries.
+ bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync(
+ userId, new LibraryOwnershipPolicyContext(book.LibraryId), cancellationToken).ConfigureAwait(false);
+ if (!canAccessLibrary)
+ return ApplicationErrors.Authorization.NotAuthorized;
+
+ Result getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(book.LibraryId, cancellationToken).ConfigureAwait(false);
+ if (getLibraryResult.IsFailure)
+ return getLibraryResult.Errors;
+ if (getLibraryResult.Value is null)
+ return DomainErrors.Library.LibraryNotFound;
+ LibraryEntity library = getLibraryResult.Value;
+
+ // The per-user reading preference decides whether a PDF is rendered as page images or has its text layer extracted; a
+ // missing settings row falls back to the default, which is to extract the text layer.
+ Result getSettingsResult = await _unitOfWork.UserSettingsRepository.GetByUserIdAsync(userId, cancellationToken).ConfigureAwait(false);
+ if (getSettingsResult.IsFailure)
+ return getSettingsResult.Errors;
+ bool shouldRenderPdfAsImages = getSettingsResult.Value is not null && getSettingsResult.Value.ShouldRenderPdfAsImages;
+
+ return await _bookReadingService.GetManifestAsync(book.Id, book.LibraryId, book.Path, library.LibraryType, shouldRenderPdfAsImages, cancellationToken).ConfigureAwait(false);
+ }
+}
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingManifest/GetReadingManifestQueryValidator.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingManifest/GetReadingManifestQueryValidator.cs
new file mode 100644
index 00000000..27e12875
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingManifest/GetReadingManifestQueryValidator.cs
@@ -0,0 +1,24 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Domain.Common.Errors;
+using System;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingManifest;
+
+///
+/// Validates the needed validation rules for .
+///
+public class GetReadingManifestQueryValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetReadingManifestQueryValidator()
+ {
+ RuleFor(query => query.BookId)
+ .NotEmpty()
+ .WithError(Errors.Reading.BookIdCannotBeEmpty);
+ }
+}
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingResource/GetReadingResourceQuery.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingResource/GetReadingResourceQuery.cs
new file mode 100644
index 00000000..1de80056
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingResource/GetReadingResourceQuery.cs
@@ -0,0 +1,16 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingResource;
+
+///
+/// Query for getting a resource of a book, for reading.
+///
+/// The Id of the book whose resource is retrieved.
+/// The opaque resource key of the resource.
+public record GetReadingResourceQuery(
+ Guid BookId,
+ string ResourceKey
+) : IQuery;
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingResource/GetReadingResourceQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingResource/GetReadingResourceQueryHandler.cs
new file mode 100644
index 00000000..83f9c772
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingResource/GetReadingResourceQueryHandler.cs
@@ -0,0 +1,102 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
+using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
+using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Infrastructure.Authentication;
+using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+using Lumina.Domain.Common.Primitives;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingResource;
+
+///
+/// Handler for the query to get a resource of a book, for reading.
+///
+public class GetReadingResourceQueryHandler : IQueryHandler>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IAuthorizationService _authorizationService;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IBookReadingService _bookReadingService;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected service for authorization related functionality.
+ /// Injected service to retrieve the current user information.
+ /// Injected service for reading books using the book reader plugins.
+ /// Injected validator for application validation rules.
+ public GetReadingResourceQueryHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IBookReadingService bookReadingService, IValidator validator)
+ {
+ _unitOfWork = unitOfWork;
+ _authorizationService = authorizationService;
+ _currentUserService = currentUserService;
+ _bookReadingService = bookReadingService;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the query to get a resource of a book, for reading.
+ ///
+ /// The query to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either the resource of the book, or an error.
+ ///
+ public async Task> HandleAsync(GetReadingResourceQuery query, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ // An authenticated request must always carry a user identity.
+ Guid? currentUserId = _currentUserService.UserId;
+ if (currentUserId is null)
+ return ApplicationErrors.Authorization.NotAuthorized;
+ Guid userId = currentUserId.Value;
+
+ // The authorization policy works on the media library, so the book is fetched first to learn its LibraryId, and
+ // the library is fetched afterwards for its type, which the reader plugins match against when resolving the format.
+ Result getBookResult = await _unitOfWork.BookRepository.GetByIdAsync(query.BookId, cancellationToken).ConfigureAwait(false);
+ if (getBookResult.IsFailure)
+ return getBookResult.Errors;
+ if (getBookResult.Value is null)
+ return DomainErrors.Reading.BookNotFound;
+ BookEntity book = getBookResult.Value;
+
+ // Admins can read the books of any library; for everyone else, only their own libraries.
+ bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync(userId, new LibraryOwnershipPolicyContext(book.LibraryId), cancellationToken).ConfigureAwait(false);
+ if (!canAccessLibrary)
+ return ApplicationErrors.Authorization.NotAuthorized;
+
+ Result getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(book.LibraryId, cancellationToken).ConfigureAwait(false);
+ if (getLibraryResult.IsFailure)
+ return getLibraryResult.Errors;
+ if (getLibraryResult.Value is null)
+ return DomainErrors.Library.LibraryNotFound;
+ LibraryEntity library = getLibraryResult.Value;
+
+ // The per-user reading preference decides whether a PDF is rendered as page images or has its text layer extracted; a
+ // missing settings row falls back to the default, which is to extract the text layer.
+ Result getSettingsResult = await _unitOfWork.UserSettingsRepository.GetByUserIdAsync(userId, cancellationToken).ConfigureAwait(false);
+ if (getSettingsResult.IsFailure)
+ return getSettingsResult.Errors;
+ bool shouldRenderPdfAsImages = getSettingsResult.Value is not null && getSettingsResult.Value.ShouldRenderPdfAsImages;
+
+ return await _bookReadingService.GetResourceAsync(book.Id, book.LibraryId, book.Path, library.LibraryType, query.ResourceKey, shouldRenderPdfAsImages, cancellationToken).ConfigureAwait(false);
+ }
+}
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingResource/GetReadingResourceQueryValidator.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingResource/GetReadingResourceQueryValidator.cs
new file mode 100644
index 00000000..20c07c15
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingResource/GetReadingResourceQueryValidator.cs
@@ -0,0 +1,28 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Domain.Common.Errors;
+using System;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingResource;
+
+///
+/// Validates the needed validation rules for .
+///
+public class GetReadingResourceQueryValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetReadingResourceQueryValidator()
+ {
+ RuleFor(query => query.BookId)
+ .NotEmpty()
+ .WithError(Errors.Reading.BookIdCannotBeEmpty);
+
+ RuleFor(query => query.ResourceKey)
+ .NotEmpty()
+ .WithError(Errors.Reading.ResourceKeyCannotBeEmpty);
+ }
+}
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingSection/GetReadingSectionQuery.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingSection/GetReadingSectionQuery.cs
new file mode 100644
index 00000000..62b4e2b9
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingSection/GetReadingSectionQuery.cs
@@ -0,0 +1,16 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingSection;
+
+///
+/// Query for getting the content of a reading section of a book.
+///
+/// The Id of the book whose reading section is retrieved.
+/// The opaque location reference of the reading section.
+public record GetReadingSectionQuery(
+ Guid BookId,
+ string LocationRef
+) : IQuery;
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingSection/GetReadingSectionQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingSection/GetReadingSectionQueryHandler.cs
new file mode 100644
index 00000000..fb1ca0c5
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingSection/GetReadingSectionQueryHandler.cs
@@ -0,0 +1,105 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
+using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
+using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Infrastructure.Authentication;
+using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+using Lumina.Domain.Common.Primitives;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingSection;
+
+///
+/// Handler for the query to get the content of a reading section of a book.
+///
+public class GetReadingSectionQueryHandler : IQueryHandler>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IAuthorizationService _authorizationService;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IBookReadingService _bookReadingService;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected service for authorization related functionality.
+ /// Injected service to retrieve the current user information.
+ /// Injected service for reading books using the book reader plugins.
+ /// Injected validator for application validation rules.
+ public GetReadingSectionQueryHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IBookReadingService bookReadingService, IValidator validator)
+ {
+ _unitOfWork = unitOfWork;
+ _authorizationService = authorizationService;
+ _currentUserService = currentUserService;
+ _bookReadingService = bookReadingService;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the query to get the content of a reading section of a book.
+ ///
+ /// The query to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either the content of the reading section, or an error.
+ ///
+ public async Task> HandleAsync(GetReadingSectionQuery query, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ // An authenticated request must always carry a user identity.
+ Guid? currentUserId = _currentUserService.UserId;
+ if (currentUserId is null)
+ return ApplicationErrors.Authorization.NotAuthorized;
+ Guid userId = currentUserId.Value;
+
+ // The authorization policy works on the media library, so the book is fetched first to learn its LibraryId, and
+ // the library is fetched afterwards for its type, which the reader plugins match against when resolving the format.
+ Result getBookResult = await _unitOfWork.BookRepository.GetByIdAsync(query.BookId, cancellationToken).ConfigureAwait(false);
+ if (getBookResult.IsFailure)
+ return getBookResult.Errors;
+ if (getBookResult.Value is null)
+ return DomainErrors.Reading.BookNotFound;
+ BookEntity book = getBookResult.Value;
+
+ // Admins can read the books of any library; for everyone else, only their own libraries.
+ bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync(
+ userId, new LibraryOwnershipPolicyContext(book.LibraryId), cancellationToken).ConfigureAwait(false);
+ if (!canAccessLibrary)
+ return ApplicationErrors.Authorization.NotAuthorized;
+
+ Result getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(book.LibraryId, cancellationToken).ConfigureAwait(false);
+ if (getLibraryResult.IsFailure)
+ return getLibraryResult.Errors;
+ if (getLibraryResult.Value is null)
+ return DomainErrors.Library.LibraryNotFound;
+ LibraryEntity library = getLibraryResult.Value;
+
+ // The per-user reading preferences decide how the book is rendered: whether a PDF is rendered as page images or has its text
+ // layer extracted, and whether the styles of the section content are preserved; a missing settings row falls back to the
+ // defaults, which are to extract the text layer and to preserve the styles.
+ Result getSettingsResult = await _unitOfWork.UserSettingsRepository.GetByUserIdAsync(userId, cancellationToken).ConfigureAwait(false);
+ if (getSettingsResult.IsFailure)
+ return getSettingsResult.Errors;
+ bool shouldRenderPdfAsImages = getSettingsResult.Value is not null && getSettingsResult.Value.ShouldRenderPdfAsImages;
+ bool shouldPreserveStyles = getSettingsResult.Value is null || getSettingsResult.Value.ShouldPreserveBookStyles;
+
+ return await _bookReadingService.GetSectionAsync(book.Id, book.LibraryId, book.Path, library.LibraryType, query.LocationRef, shouldRenderPdfAsImages, shouldPreserveStyles, cancellationToken).ConfigureAwait(false);
+ }
+}
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingSection/GetReadingSectionQueryValidator.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingSection/GetReadingSectionQueryValidator.cs
new file mode 100644
index 00000000..0d7dab90
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/Queries/GetReadingSection/GetReadingSectionQueryValidator.cs
@@ -0,0 +1,28 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Domain.Common.Errors;
+using System;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingSection;
+
+///
+/// Validates the needed validation rules for .
+///
+public class GetReadingSectionQueryValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetReadingSectionQueryValidator()
+ {
+ RuleFor(query => query.BookId)
+ .NotEmpty()
+ .WithError(Errors.Reading.BookIdCannotBeEmpty);
+
+ RuleFor(query => query.LocationRef)
+ .NotEmpty()
+ .WithError(Errors.Reading.LocationRefCannotBeEmpty);
+ }
+}
diff --git a/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/IBookReadingService.cs b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/IBookReadingService.cs
new file mode 100644
index 00000000..a47d1748
--- /dev/null
+++ b/src/Lumina.Application/Core/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/IBookReadingService.cs
@@ -0,0 +1,68 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+using Lumina.Domain.Common.Primitives;
+using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+#endregion
+
+namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+
+///
+/// Interface for the service for reading books, using the book reader plugins configured for their media library.
+///
+public interface IBookReadingService
+{
+ ///
+ /// Gets the reading manifest of the book stored at .
+ ///
+ /// The Id of the book.
+ /// The Id of the media library the book belongs to.
+ /// The file system path of the book.
+ /// The type of the media library the book belongs to.
+ /// Whether the book, when it is a PDF, is rendered as page images instead of extracting its text layer.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the reading manifest of the book, or an error.
+ Task> GetManifestAsync(Guid bookId, Guid libraryId, string path, LibraryType libraryType, bool shouldRenderPdfAsImages, CancellationToken cancellationToken);
+
+ ///
+ /// Gets the content of the reading section identified by of the book stored at .
+ ///
+ /// The Id of the book.
+ /// The Id of the media library the book belongs to.
+ /// The file system path of the book.
+ /// The type of the media library the book belongs to.
+ /// The opaque location reference of the reading section.
+ /// Whether the book, when it is a PDF, is rendered as page images instead of extracting its text layer.
+ /// Whether the styles of the section content are preserved when it is sanitized, or stripped.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the content of the reading section, or an error.
+ Task> GetSectionAsync(Guid bookId, Guid libraryId, string path, LibraryType libraryType, string locationRef, bool shouldRenderPdfAsImages, bool shouldPreserveStyles, CancellationToken cancellationToken);
+
+ ///
+ /// Gets the resource identified by of the book stored at .
+ ///
+ /// The Id of the book.
+ /// The Id of the media library the book belongs to.
+ /// The file system path of the book.
+ /// The type of the media library the book belongs to.
+ /// The opaque resource key of the resource.
+ /// Whether the book, when it is a PDF, is rendered as page images instead of extracting its text layer.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the resource, or an error.
+ Task> GetResourceAsync(Guid bookId, Guid libraryId, string path, LibraryType libraryType, string resourceKey, bool shouldRenderPdfAsImages, CancellationToken cancellationToken);
+
+ ///
+ /// Checks whether the book stored at can be opened for reading, resolving the book reader configured
+ /// for its media library and verifying that the reader is enabled, without extracting the book.
+ ///
+ /// The Id of the book.
+ /// The Id of the media library the book belongs to.
+ /// The file system path of the book.
+ /// The type of the media library the book belongs to.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the reading availability of the book, or an error.
+ Task> GetAvailabilityAsync(Guid bookId, Guid libraryId, string path, LibraryType libraryType, CancellationToken cancellationToken);
+}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommand.cs b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommand.cs
new file mode 100644
index 00000000..a40b4e93
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommand.cs
@@ -0,0 +1,18 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+#endregion
+
+namespace Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
+
+///
+/// Command for enabling or disabling a book reader for a media library.
+///
+/// The Id of the media library whose book reader is enabled or disabled.
+/// The unique identifier of the plugin providing the book reader.
+/// Whether the book reader should be enabled for the media library.
+public record SetLibraryBookReaderEnabledCommand(
+ Guid LibraryId,
+ Guid PluginId,
+ bool IsEnabled
+) : ICommand;
diff --git a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommandHandler.cs b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommandHandler.cs
new file mode 100644
index 00000000..aa8c8749
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommandHandler.cs
@@ -0,0 +1,106 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.Plugins;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Infrastructure.Authentication;
+using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
+using Lumina.Application.Common.Infrastructure.Reading;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Domain.Common.Primitives;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
+
+///
+/// Handler for the command to enable or disable a book reader for a media library.
+///
+public class SetLibraryBookReaderEnabledCommandHandler : ICommandHandler>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IAuthorizationService _authorizationService;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IBookReaderEnablementCache _enablementCache;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected service for authorization related functionality.
+ /// Injected service to retrieve the current user information.
+ /// Injected cache of whether the book reader of a plugin is enabled for a media library.
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected validator for application validation rules.
+ public SetLibraryBookReaderEnabledCommandHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IBookReaderEnablementCache enablementCache, IUnitOfWork unitOfWork, IValidator validator)
+ {
+ _authorizationService = authorizationService;
+ _currentUserService = currentUserService;
+ _enablementCache = enablementCache;
+ _unitOfWork = unitOfWork;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the command to enable or disable a book reader for a media library.
+ ///
+ /// The request to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An representing either a successful operation, or an error.
+ ///
+ public async Task> HandleAsync(SetLibraryBookReaderEnabledCommand command, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(command);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ // An authenticated request must always carry a user identity.
+ Guid? currentUserId = _currentUserService.UserId;
+ if (currentUserId is null)
+ return ApplicationErrors.Authorization.NotAuthorized;
+ Guid userId = currentUserId.Value;
+
+ // Admins can configure the book readers of any library; for everyone else, only their own libraries.
+ bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync(userId, new LibraryOwnershipPolicyContext(command.LibraryId), cancellationToken).ConfigureAwait(false);
+ if (!canAccessLibrary)
+ return ApplicationErrors.Authorization.NotAuthorized;
+
+ Result getConfigurationResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.GetByLibraryAndPluginIdAsync(command.LibraryId, command.PluginId, cancellationToken).ConfigureAwait(false);
+ if (getConfigurationResult.IsFailure)
+ return getConfigurationResult.Errors;
+
+ LibraryBookReaderConfigurationEntity configuration;
+ if (getConfigurationResult.Value is not null)
+ {
+ configuration = getConfigurationResult.Value;
+ configuration.IsEnabled = command.IsEnabled;
+ }
+ else
+ {
+ configuration = new LibraryBookReaderConfigurationEntity
+ {
+ Id = Guid.NewGuid(),
+ LibraryId = command.LibraryId,
+ PluginId = command.PluginId,
+ IsEnabled = command.IsEnabled,
+ CreatedOnUtc = default,
+ CreatedBy = default,
+ UpdatedBy = default
+ };
+ }
+
+ Result upsertResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
+ if (upsertResult.IsFailure)
+ return upsertResult.Errors;
+ await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
+ // The reading service caches the enablement of a reader, because it consults it on every request; the cache is invalidated here,
+ // so that disabling a reader cuts access to its books immediately, without waiting for the cache to expire.
+ _enablementCache.Invalidate(command.LibraryId, command.PluginId);
+ return Result.Success;
+ }
+}
diff --git a/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommandValidator.cs b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommandValidator.cs
new file mode 100644
index 00000000..1178b5f9
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Commands/SetLibraryBookReaderEnabled/SetLibraryBookReaderEnabledCommandValidator.cs
@@ -0,0 +1,28 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Domain.Common.Errors;
+using System;
+#endregion
+
+namespace Lumina.Application.Core.Plugins.Commands.SetLibraryBookReaderEnabled;
+
+///
+/// Validates the needed validation rules for .
+///
+public class SetLibraryBookReaderEnabledCommandValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public SetLibraryBookReaderEnabledCommandValidator()
+ {
+ RuleFor(command => command.LibraryId)
+ .NotEmpty()
+ .WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
+
+ RuleFor(command => command.PluginId)
+ .NotEmpty()
+ .WithError(Errors.Plugins.PluginIdCannotBeEmpty);
+ }
+}
diff --git a/src/Lumina.Application/Core/Plugins/Queries/GetLibraryBookReaders/GetLibraryBookReadersQuery.cs b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryBookReaders/GetLibraryBookReadersQuery.cs
new file mode 100644
index 00000000..c2800541
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryBookReaders/GetLibraryBookReadersQuery.cs
@@ -0,0 +1,14 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using System;
+#endregion
+
+namespace Lumina.Application.Core.Plugins.Queries.GetLibraryBookReaders;
+
+///
+/// Query for getting the book readers configured for a media library.
+///
+/// The Id of the media library whose book readers are retrieved.
+public record GetLibraryBookReadersQuery(
+ Guid LibraryId
+) : IQuery;
diff --git a/src/Lumina.Application/Core/Plugins/Queries/GetLibraryBookReaders/GetLibraryBookReadersQueryHandler.cs b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryBookReaders/GetLibraryBookReadersQueryHandler.cs
new file mode 100644
index 00000000..d379ee7f
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryBookReaders/GetLibraryBookReadersQueryHandler.cs
@@ -0,0 +1,97 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.CQRS;
+using Lumina.Application.Common.DataAccess.Entities.Plugins;
+using Lumina.Application.Common.DataAccess.UoW;
+using Lumina.Application.Common.Infrastructure.Authentication;
+using Lumina.Application.Common.Infrastructure.Authorization;
+using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
+using Lumina.Application.Common.Infrastructure.Reading;
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Mapping.Plugins;
+using Lumina.Contracts.Responses.Plugins;
+using Lumina.Domain.Common.Primitives;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Core.Plugins.Queries.GetLibraryBookReaders;
+
+///
+/// Handler for the query to get the book readers configured for a media library.
+///
+public class GetLibraryBookReadersQueryHandler : IQueryHandler>>
+{
+ private readonly IUnitOfWork _unitOfWork;
+ private readonly IAuthorizationService _authorizationService;
+ private readonly ICurrentUserService _currentUserService;
+ private readonly IBookReaderRegistry _bookReaderRegistry;
+ private readonly IValidator _validator;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Injected service for authorization related functionality.
+ /// Injected service to retrieve the current user information.
+ /// Injected registry of the book readers provided by the loaded plugins.
+ /// Injected unit of work for interacting with the data access layer repositories.
+ /// Injected validator for application validation rules.
+ public GetLibraryBookReadersQueryHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IBookReaderRegistry bookReaderRegistry, IUnitOfWork unitOfWork, IValidator validator)
+ {
+ _authorizationService = authorizationService;
+ _currentUserService = currentUserService;
+ _bookReaderRegistry = bookReaderRegistry;
+ _unitOfWork = unitOfWork;
+ _validator = validator;
+ }
+
+ ///
+ /// Handles the query to get the book readers configured for a media library.
+ ///
+ /// The request to be handled.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either a collection of , or an error.
+ ///
+ public async Task>> HandleAsync(GetLibraryBookReadersQuery query, CancellationToken cancellationToken)
+ {
+ List validationResult = _validator.Validate(query);
+ if (validationResult.Count > 0)
+ return validationResult;
+
+ // An authenticated request must always carry a user identity.
+ Guid? currentUserId = _currentUserService.UserId;
+ if (currentUserId is null)
+ return ApplicationErrors.Authorization.NotAuthorized;
+ Guid userId = currentUserId.Value;
+
+ // Admins can read the book readers of any library; for everyone else, only their own libraries.
+ bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync(
+ userId, new LibraryOwnershipPolicyContext(query.LibraryId), cancellationToken).ConfigureAwait(false);
+ if (!canAccessLibrary)
+ return ApplicationErrors.Authorization.NotAuthorized;
+
+ Result> getConfigurationsResult = await _unitOfWork.LibraryBookReaderConfigurationRepository.GetByLibraryIdAsync(query.LibraryId, cancellationToken).ConfigureAwait(false);
+ if (getConfigurationsResult.IsFailure)
+ return getConfigurationsResult.Errors;
+
+ // Build a plugin name lookup from the detected plugins.
+ Result> getPluginsResult = await _unitOfWork.PluginRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
+ if (getPluginsResult.IsFailure)
+ return getPluginsResult.Errors;
+ Dictionary pluginNames = getPluginsResult.Value.ToDictionary(plugin => plugin.Id, plugin => plugin.Name);
+
+ IReadOnlyDictionary> supportedExtensionsByPluginId = _bookReaderRegistry.GetSupportedExtensionsByPluginId();
+
+ return getConfigurationsResult.Value
+ .OrderBy(configuration => configuration.IsEnabled ? 0 : 1)
+ .ThenBy(configuration => pluginNames.GetValueOrDefault(configuration.PluginId) ?? string.Empty, StringComparer.OrdinalIgnoreCase)
+ .Select(configuration => configuration.ToResponse(
+ pluginNames.GetValueOrDefault(configuration.PluginId) ?? string.Empty,
+ supportedExtensionsByPluginId.GetValueOrDefault(configuration.PluginId) ?? []))
+ .ToList();
+ }
+}
diff --git a/src/Lumina.Application/Core/Plugins/Queries/GetLibraryBookReaders/GetLibraryBookReadersQueryValidator.cs b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryBookReaders/GetLibraryBookReadersQueryValidator.cs
new file mode 100644
index 00000000..b47734a3
--- /dev/null
+++ b/src/Lumina.Application/Core/Plugins/Queries/GetLibraryBookReaders/GetLibraryBookReadersQueryValidator.cs
@@ -0,0 +1,24 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.Infrastructure.Validation;
+using Lumina.Application.Common.Utilities;
+using Lumina.Domain.Common.Errors;
+using System;
+#endregion
+
+namespace Lumina.Application.Core.Plugins.Queries.GetLibraryBookReaders;
+
+///
+/// Validates the needed validation rules for .
+///
+public class GetLibraryBookReadersQueryValidator : AbstractValidator
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public GetLibraryBookReadersQueryValidator()
+ {
+ RuleFor(query => query.LibraryId)
+ .NotEmpty()
+ .WithError(Errors.Plugins.LibraryIdCannotBeEmpty);
+ }
+}
diff --git a/src/Lumina.Application/Core/UsersManagement/Settings/Commands/UpdateUserSettings/UpdateUserSettingsCommand.cs b/src/Lumina.Application/Core/UsersManagement/Settings/Commands/UpdateUserSettings/UpdateUserSettingsCommand.cs
index e29088bf..44a547f4 100644
--- a/src/Lumina.Application/Core/UsersManagement/Settings/Commands/UpdateUserSettings/UpdateUserSettingsCommand.cs
+++ b/src/Lumina.Application/Core/UsersManagement/Settings/Commands/UpdateUserSettings/UpdateUserSettingsCommand.cs
@@ -12,10 +12,14 @@ namespace Lumina.Application.Core.UsersManagement.Settings.Commands.UpdateUserSe
/// Whether the "The" prefix of library item titles is ignored by the alpha picker, or not.
/// Whether the theme data served to this user is cached, or not.
/// Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing, or not.
+/// Whether PDF books are rendered as page images for the user, or not.
+/// Whether the styles of the book content are preserved when it is rendered for the user, or not.
public record UpdateUserSettingsCommand(
bool IsPaginationEnabled,
int ItemsPerPage,
bool ShouldIgnoreThePrefixForAlphaPicker,
bool IsThemeCachingEnabled,
- bool ShouldAggregateMetadataWhenMissing
+ bool ShouldAggregateMetadataWhenMissing,
+ bool ShouldRenderPdfAsImages,
+ bool ShouldPreserveBookStyles
) : ICommand;
diff --git a/src/Lumina.Application/Core/UsersManagement/Settings/Commands/UpdateUserSettings/UpdateUserSettingsCommandHandler.cs b/src/Lumina.Application/Core/UsersManagement/Settings/Commands/UpdateUserSettings/UpdateUserSettingsCommandHandler.cs
index 9af3a222..8b7bf775 100644
--- a/src/Lumina.Application/Core/UsersManagement/Settings/Commands/UpdateUserSettings/UpdateUserSettingsCommandHandler.cs
+++ b/src/Lumina.Application/Core/UsersManagement/Settings/Commands/UpdateUserSettings/UpdateUserSettingsCommandHandler.cs
@@ -53,27 +53,29 @@ public class UpdateUserSettingsCommandHandler : ICommandHandler 0)
return validationResult;
- // an authenticated request must always carry a user identity
+ // An authenticated request must always carry a user identity.
Guid? currentUserId = _currentUserService.UserId;
if (currentUserId is null)
return Errors.Authorization.NotAuthorized;
Guid userId = currentUserId.Value;
- // get the existing settings of the current user, if any
+ // Get the existing settings of the current user, if any.
Result getSettingsResult = await _unitOfWork.UserSettingsRepository.GetByUserIdAsync(userId, cancellationToken).ConfigureAwait(false);
if (getSettingsResult.IsFailure)
return getSettingsResult.Errors;
if (getSettingsResult.Value is null)
{
- // create the settings of the current user, since they are not stored yet
+ // Create the settings of the current user, since they are not stored yet.
Result createSettingsResult = UserSettings.Create(
UserId.Create(userId),
command.IsPaginationEnabled,
command.ItemsPerPage,
command.ShouldIgnoreThePrefixForAlphaPicker,
command.IsThemeCachingEnabled,
- command.ShouldAggregateMetadataWhenMissing);
+ command.ShouldAggregateMetadataWhenMissing,
+ command.ShouldRenderPdfAsImages,
+ command.ShouldPreserveBookStyles);
if (createSettingsResult.IsFailure)
return createSettingsResult.Errors;
@@ -83,7 +85,7 @@ public class UpdateUserSettingsCommandHandler : ICommandHandler toDomainEntityResult = getSettingsResult.Value.ToDomainEntity();
if (toDomainEntityResult.IsFailure)
return toDomainEntityResult.Errors;
@@ -93,7 +95,9 @@ public class UpdateUserSettingsCommandHandler : ICommandHandler
+/// Data transfer object for the normalized document model of a book, produced by a reader plugin.
+///
+/// The title of the book.
+/// The author of the book, if known.
+/// The resource key of the cover image of the book, if applicable.
+/// The hierarchical table of contents of the book.
+/// The ordered spine of the reading sections of the book.
+/// The resources of the book, keyed by their resource key.
+/// Whether the book has extractable text content. A scanned book, whose pages are only images, has no text content.
+[DebuggerDisplay("Title: {Title}")]
+public sealed record ReadingDocumentDto(
+ string Title,
+ string? Author,
+ string? CoverResourceKey,
+ IReadOnlyList TableOfContents,
+ IReadOnlyList Spine,
+ IReadOnlyDictionary Resources,
+ bool HasTextContent
+);
diff --git a/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingResourceDataDto.cs b/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingResourceDataDto.cs
new file mode 100644
index 00000000..d26bd727
--- /dev/null
+++ b/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingResourceDataDto.cs
@@ -0,0 +1,16 @@
+#region ========================================================================= USING =====================================================================================
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+
+///
+/// Data transfer object for the binary data of a reading resource.
+///
+/// The binary data of the resource.
+/// The MIME type of the resource.
+[DebuggerDisplay("MimeType: {MimeType}")]
+public sealed record ReadingResourceDataDto(
+ byte[] Data,
+ string MimeType
+);
diff --git a/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingResourceInfoDto.cs b/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingResourceInfoDto.cs
new file mode 100644
index 00000000..3d819cc3
--- /dev/null
+++ b/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingResourceInfoDto.cs
@@ -0,0 +1,16 @@
+#region ========================================================================= USING =====================================================================================
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+
+///
+/// Data transfer object for the file information of a resource of a reading document.
+///
+/// The path of the resource file, relative to the extraction directory of the book.
+/// The MIME type of the resource.
+[DebuggerDisplay("RelativeFilePath: {RelativeFilePath}")]
+public sealed record ReadingResourceInfoDto(
+ string RelativeFilePath,
+ string MimeType
+);
diff --git a/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingSectionDto.cs b/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingSectionDto.cs
new file mode 100644
index 00000000..e90c65af
--- /dev/null
+++ b/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingSectionDto.cs
@@ -0,0 +1,18 @@
+#region ========================================================================= USING =====================================================================================
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+
+///
+/// Data transfer object for the content of a reading section.
+///
+/// The opaque location reference of the reading section.
+/// The title of the reading section, if known.
+/// The sanitized HTML content of the reading section, ready to be rendered by the client.
+[DebuggerDisplay("LocationRef: {LocationRef}")]
+public sealed record ReadingSectionDto(
+ string LocationRef,
+ string? Title,
+ string ContentHtml
+);
diff --git a/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingSpineItemDto.cs b/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingSpineItemDto.cs
new file mode 100644
index 00000000..0f1f0f9c
--- /dev/null
+++ b/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingSpineItemDto.cs
@@ -0,0 +1,18 @@
+#region ========================================================================= USING =====================================================================================
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+
+///
+/// Data transfer object for an item of the spine of a reading document.
+///
+/// The opaque location reference of the reading section.
+/// The title of the reading section, if known.
+/// The path of the section content file, relative to the extraction directory of the book.
+[DebuggerDisplay("LocationRef: {LocationRef}")]
+public sealed record ReadingSpineItemDto(
+ string LocationRef,
+ string? Title,
+ string RelativeSectionFilePath
+);
diff --git a/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingTocEntryDto.cs b/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingTocEntryDto.cs
new file mode 100644
index 00000000..6301f6d2
--- /dev/null
+++ b/src/Lumina.Contracts/DTO/MediaLibrary/WrittenContentLibrary/BookLibrary/Reading/ReadingTocEntryDto.cs
@@ -0,0 +1,19 @@
+#region ========================================================================= USING =====================================================================================
+using System.Collections.Generic;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
+
+///
+/// Data transfer object for an entry of the table of contents of a reading document.
+///
+/// The label of the table of contents entry.
+/// The opaque location reference of the reading section the entry points to.
+/// The child entries of the table of contents entry.
+[DebuggerDisplay("Label: {Label}")]
+public sealed record ReadingTocEntryDto(
+ string Label,
+ string LocationRef,
+ IReadOnlyList Children
+);
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/GetReadingAvailabilityRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/GetReadingAvailabilityRequest.cs
new file mode 100644
index 00000000..9dff87d4
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/GetReadingAvailabilityRequest.cs
@@ -0,0 +1,15 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+
+///
+/// Represents a request to check the reading availability of a book.
+///
+/// The Id of the book whose reading availability is checked. Required.
+[DebuggerDisplay("BookId: {BookId}")]
+public sealed record GetReadingAvailabilityRequest(
+ Guid BookId
+);
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/GetReadingManifestRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/GetReadingManifestRequest.cs
new file mode 100644
index 00000000..abcf6fd3
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/GetReadingManifestRequest.cs
@@ -0,0 +1,15 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+
+///
+/// Represents a request to get the reading manifest of a book.
+///
+/// The Id of the book whose reading manifest is retrieved. Required.
+[DebuggerDisplay("BookId: {BookId}")]
+public sealed record GetReadingManifestRequest(
+ Guid BookId
+);
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/GetReadingResourceRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/GetReadingResourceRequest.cs
new file mode 100644
index 00000000..6d82017d
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/GetReadingResourceRequest.cs
@@ -0,0 +1,17 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+
+///
+/// Represents a request to get a resource of a book, for reading.
+///
+/// The Id of the book whose resource is retrieved. Required.
+/// The opaque resource key of the resource. Required.
+[DebuggerDisplay("BookId: {BookId}, ResourceKey: {ResourceKey}")]
+public sealed record GetReadingResourceRequest(
+ Guid BookId,
+ string ResourceKey
+);
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/GetReadingSectionRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/GetReadingSectionRequest.cs
new file mode 100644
index 00000000..aef859de
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/GetReadingSectionRequest.cs
@@ -0,0 +1,17 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+
+///
+/// Represents a request to get the content of a reading section of a book.
+///
+/// The Id of the book whose reading section is retrieved. Required.
+/// The opaque location reference of the reading section. Required.
+[DebuggerDisplay("BookId: {BookId}, LocationRef: {LocationRef}")]
+public sealed record GetReadingSectionRequest(
+ Guid BookId,
+ string LocationRef
+);
diff --git a/src/Lumina.Contracts/Requests/Plugins/GetLibraryBookReadersRequest.cs b/src/Lumina.Contracts/Requests/Plugins/GetLibraryBookReadersRequest.cs
new file mode 100644
index 00000000..b3d9d026
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/Plugins/GetLibraryBookReadersRequest.cs
@@ -0,0 +1,15 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.Plugins;
+
+///
+/// Represents a request to get the book readers configured for a media library.
+///
+/// The Id of the media library whose book readers are retrieved. Required.
+[DebuggerDisplay("LibraryId: {LibraryId}")]
+public sealed record GetLibraryBookReadersRequest(
+ Guid LibraryId
+);
diff --git a/src/Lumina.Contracts/Requests/Plugins/SetLibraryBookReaderEnabledRequest.cs b/src/Lumina.Contracts/Requests/Plugins/SetLibraryBookReaderEnabledRequest.cs
new file mode 100644
index 00000000..3392ae17
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/Plugins/SetLibraryBookReaderEnabledRequest.cs
@@ -0,0 +1,19 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.Plugins;
+
+///
+/// Represents a request to enable or disable a book reader for a media library.
+///
+/// The Id of the media library whose book reader is enabled or disabled. Required.
+/// The unique identifier of the plugin providing the book reader. Required.
+/// Whether the book reader should be enabled for the media library. Required.
+[DebuggerDisplay("LibraryId: {LibraryId}, PluginId: {PluginId}")]
+public sealed record SetLibraryBookReaderEnabledRequest(
+ Guid LibraryId,
+ Guid PluginId,
+ bool IsEnabled
+);
diff --git a/src/Lumina.Contracts/Requests/UsersManagement/Settings/UpdateUserSettingsRequest.cs b/src/Lumina.Contracts/Requests/UsersManagement/Settings/UpdateUserSettingsRequest.cs
index b37216ac..34c12869 100644
--- a/src/Lumina.Contracts/Requests/UsersManagement/Settings/UpdateUserSettingsRequest.cs
+++ b/src/Lumina.Contracts/Requests/UsersManagement/Settings/UpdateUserSettingsRequest.cs
@@ -12,11 +12,15 @@ namespace Lumina.Contracts.Requests.UsersManagement.Settings;
/// Whether the "The" prefix of library item titles is ignored by the alpha picker, or not. Required.
/// Whether the theme data served to this user is cached, or not. Required.
/// Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing, or not. Required.
+/// Whether PDF books are rendered as page images for the user, or not. Required.
+/// Whether the styles of the book content are preserved when it is rendered for the user, or not. Required.
[DebuggerDisplay("IsPaginationEnabled: {IsPaginationEnabled}; ItemsPerPage: {ItemsPerPage}")]
public sealed record UpdateUserSettingsRequest(
bool IsPaginationEnabled,
int ItemsPerPage,
bool ShouldIgnoreThePrefixForAlphaPicker,
bool IsThemeCachingEnabled,
- bool ShouldAggregateMetadataWhenMissing
+ bool ShouldAggregateMetadataWhenMissing,
+ bool ShouldRenderPdfAsImages,
+ bool ShouldPreserveBookStyles
);
diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/ReadingAvailabilityResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/ReadingAvailabilityResponse.cs
new file mode 100644
index 00000000..dc3210e0
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/ReadingAvailabilityResponse.cs
@@ -0,0 +1,21 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+
+///
+/// Represents the reading availability of a book.
+///
+/// The Id of the book whose reading availability is reported.
+/// The Id of the media library the book belongs to.
+/// Whether the book can be opened for reading.
+/// The code of the error preventing the book from being read, when it cannot be read. Can be when the book is available.
+[DebuggerDisplay("BookId: {BookId}, IsAvailable: {IsAvailable}")]
+public sealed record ReadingAvailabilityResponse(
+ Guid BookId,
+ Guid LibraryId,
+ bool IsAvailable,
+ string? ErrorCode
+);
diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/ReadingManifestResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/ReadingManifestResponse.cs
new file mode 100644
index 00000000..6e6cb72a
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/ReadingManifestResponse.cs
@@ -0,0 +1,27 @@
+#region ========================================================================= USING =====================================================================================
+using System.Collections.Generic;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+
+///
+/// Represents the reading manifest of a book, containing everything the client needs to render the reader.
+///
+/// The title of the book.
+/// The author of the book, if known.
+/// The resource key of the cover image of the book, if applicable.
+/// The hierarchical table of contents of the book.
+/// The ordered spine of the reading sections of the book.
+/// The resource keys of the resources of the book.
+/// Whether the book has extractable text content. A scanned book, whose pages are only images, has no text content.
+[DebuggerDisplay("Title: {Title}")]
+public sealed record ReadingManifestResponse(
+ string Title,
+ string? Author,
+ string? CoverResourceKey,
+ IReadOnlyList TableOfContents,
+ IReadOnlyList Spine,
+ IReadOnlyList ResourceKeys,
+ bool HasTextContent
+);
diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/ReadingSpineItemResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/ReadingSpineItemResponse.cs
new file mode 100644
index 00000000..e7fb54bd
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/ReadingSpineItemResponse.cs
@@ -0,0 +1,16 @@
+#region ========================================================================= USING =====================================================================================
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+
+///
+/// Represents an item of the spine of the reading manifest of a book.
+///
+/// The opaque location reference of the reading section.
+/// The title of the reading section, if known.
+[DebuggerDisplay("LocationRef: {LocationRef}")]
+public sealed record ReadingSpineItemResponse(
+ string LocationRef,
+ string? Title
+);
diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/ReadingTocEntryResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/ReadingTocEntryResponse.cs
new file mode 100644
index 00000000..a2254eb8
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/MediaLibrary/WrittenContentLibrary/BookLibrary/Books/Reading/ReadingTocEntryResponse.cs
@@ -0,0 +1,19 @@
+#region ========================================================================= USING =====================================================================================
+using System.Collections.Generic;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
+
+///
+/// Represents an entry of the table of contents of the reading manifest of a book.
+///
+/// The label of the table of contents entry.
+/// The opaque location reference of the reading section the entry points to.
+/// The child entries of the table of contents entry.
+[DebuggerDisplay("Label: {Label}")]
+public sealed record ReadingTocEntryResponse(
+ string Label,
+ string LocationRef,
+ IReadOnlyList Children
+);
diff --git a/src/Lumina.Contracts/Responses/Plugins/LibraryBookReaderResponse.cs b/src/Lumina.Contracts/Responses/Plugins/LibraryBookReaderResponse.cs
new file mode 100644
index 00000000..bb095299
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/Plugins/LibraryBookReaderResponse.cs
@@ -0,0 +1,22 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.Plugins;
+
+///
+/// Represents a book reader configured for a media library.
+///
+/// The unique identifier of the plugin providing the book reader.
+/// The display name of the book reader.
+/// The file extensions supported by the book reader.
+/// Whether the book reader is enabled for the media library.
+[DebuggerDisplay("Name: {Name}")]
+public sealed record LibraryBookReaderResponse(
+ Guid PluginId,
+ string Name,
+ IReadOnlyList SupportedExtensions,
+ bool IsEnabled
+);
diff --git a/src/Lumina.Contracts/Responses/UsersManagement/Settings/UserSettingsResponse.cs b/src/Lumina.Contracts/Responses/UsersManagement/Settings/UserSettingsResponse.cs
index 3f5c59e3..0db9b39e 100644
--- a/src/Lumina.Contracts/Responses/UsersManagement/Settings/UserSettingsResponse.cs
+++ b/src/Lumina.Contracts/Responses/UsersManagement/Settings/UserSettingsResponse.cs
@@ -14,6 +14,8 @@ namespace Lumina.Contracts.Responses.UsersManagement.Settings;
/// Whether the "The" prefix of library item titles is ignored by the alpha picker, or not.
/// Whether the theme data served to this user is cached, or not.
/// Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing, or not.
+/// Whether PDF books are rendered as page images for the user, or not.
+/// Whether the styles of the book content are preserved when it is rendered for the user, or not.
[DebuggerDisplay("UserId: {UserId}")]
public sealed record UserSettingsResponse(
Guid UserId,
@@ -21,5 +23,7 @@ public sealed record UserSettingsResponse(
int ItemsPerPage,
bool ShouldIgnoreThePrefixForAlphaPicker,
bool IsThemeCachingEnabled,
- bool ShouldAggregateMetadataWhenMissing
+ bool ShouldAggregateMetadataWhenMissing,
+ bool ShouldRenderPdfAsImages,
+ bool ShouldPreserveBookStyles
);
diff --git a/src/Lumina.DataAccess/Common/Configuration/LibraryBookReaderConfigurationConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/LibraryBookReaderConfigurationConfiguration.cs
new file mode 100644
index 00000000..81a5b821
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/Configuration/LibraryBookReaderConfigurationConfiguration.cs
@@ -0,0 +1,57 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Entities.Plugins;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata.Builders;
+#endregion
+
+namespace Lumina.DataAccess.Common.Configuration;
+
+///
+/// Configures the entity mapping for the entity.
+///
+public class LibraryBookReaderConfigurationConfiguration : IEntityTypeConfiguration
+{
+ ///
+ /// Configures the entity.
+ ///
+ /// The builder to be used to configure the entity.
+ public void Configure(EntityTypeBuilder builder)
+ {
+ builder.ToTable("LibraryBookReaderConfigurations");
+ builder.HasKey(configuration => configuration.Id);
+ builder.Property(configuration => configuration.Id)
+ .ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
+ .HasColumnOrder(0);
+ builder.Property(configuration => configuration.LibraryId)
+ .IsRequired()
+ .HasColumnOrder(1);
+ builder.Property(configuration => configuration.PluginId)
+ .IsRequired()
+ .HasColumnOrder(2);
+ builder.Property(configuration => configuration.IsEnabled)
+ .IsRequired()
+ .HasColumnOrder(3);
+
+ // audit
+ builder.Property(configuration => configuration.CreatedOnUtc)
+ .IsRequired()
+ .HasColumnOrder(4);
+
+ builder.Property(configuration => configuration.CreatedBy)
+ .IsRequired()
+ .HasColumnOrder(5);
+
+ builder.Property(configuration => configuration.UpdatedOnUtc)
+ .HasDefaultValue(null)
+ .HasColumnOrder(6);
+
+ builder.Property(configuration => configuration.UpdatedBy)
+ .HasDefaultValue(null)
+ .HasColumnOrder(7);
+
+ // A media library has at most one book reader configuration per plugin, so the pair is unique; the repository upserts on it, and
+ // the constraint guarantees that two concurrent upserts cannot insert duplicate rows.
+ builder.HasIndex(configuration => new { configuration.LibraryId, configuration.PluginId })
+ .IsUnique();
+ }
+}
diff --git a/src/Lumina.DataAccess/Common/Configuration/UserSettingsConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/UserSettingsConfiguration.cs
index 84a4f221..3e88f89f 100644
--- a/src/Lumina.DataAccess/Common/Configuration/UserSettingsConfiguration.cs
+++ b/src/Lumina.DataAccess/Common/Configuration/UserSettingsConfiguration.cs
@@ -50,6 +50,14 @@ public class UserSettingsConfiguration : IEntityTypeConfiguration settings.ShouldRenderPdfAsImages)
+ .IsRequired()
+ .HasColumnOrder(11);
+
+ builder.Property(settings => settings.ShouldPreserveBookStyles)
+ .IsRequired()
+ .HasColumnOrder(12);
+
builder.Property(settings => settings.IsThemeCachingEnabled)
.IsRequired()
.HasColumnOrder(9);
diff --git a/src/Lumina.DataAccess/Common/DependencyInjection/DataAccessLayerServices.cs b/src/Lumina.DataAccess/Common/DependencyInjection/DataAccessLayerServices.cs
index ea604dbf..8581aeaa 100644
--- a/src/Lumina.DataAccess/Common/DependencyInjection/DataAccessLayerServices.cs
+++ b/src/Lumina.DataAccess/Common/DependencyInjection/DataAccessLayerServices.cs
@@ -7,7 +7,6 @@ using Lumina.DataAccess.Core.Seed;
using Lumina.DataAccess.Core.UoW;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
-using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
@@ -16,13 +15,13 @@ using System.Reflection;
namespace Lumina.DataAccess.Common.DependencyInjection;
///
-/// Contains all services of the DataAccess layer.
+/// Utility class for registering the services of the Data Access layer into the Dependency Injection container..
///
[ExcludeFromCodeCoverage]
public static class DataAccessLayerServices
{
///
- /// Extension method for adding the DataAccess layer services to the DI container.
+ /// Registers the services of the Data Access layer into the Dependency Injection container.
///
/// The service collection to add the services to.
/// The updated .
diff --git a/src/Lumina.DataAccess/Common/Migrations/20260901062343_AddsLibraryBookReaderConfigurationsAndShouldRenderPdfAsImagesToUserSettings.Designer.cs b/src/Lumina.DataAccess/Common/Migrations/20260901062343_AddsLibraryBookReaderConfigurationsAndShouldRenderPdfAsImagesToUserSettings.Designer.cs
new file mode 100644
index 00000000..86ec543b
--- /dev/null
+++ b/src/Lumina.DataAccess/Common/Migrations/20260901062343_AddsLibraryBookReaderConfigurationsAndShouldRenderPdfAsImagesToUserSettings.Designer.cs
@@ -0,0 +1,1615 @@
+//
+using System;
+using Lumina.DataAccess.Core.UoW;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace Lumina.DataAccess.Common.Migrations
+{
+ [DbContext(typeof(LuminaDbContext))]
+ [Migration("20260901062343_AddsLibraryBookReaderConfigurationsAndShouldRenderPdfAsImagesToUserSettings")]
+ partial class AddsLibraryBookReaderConfigurationsAndShouldRenderPdfAsImagesToUserSettings
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder.HasAnnotation("ProductVersion", "10.0.11");
+
+ modelBuilder.Entity("BookGenres", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b.Property("GenreId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("BookId", "GenreId");
+
+ b.HasIndex("GenreId");
+
+ b.ToTable("BookGenres", (string)null);
+ });
+
+ modelBuilder.Entity("BookTags", b =>
+ {
+ b.Property("BookId")
+ .HasColumnType("TEXT");
+
+ b.Property("TagId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("BookId", "TagId");
+
+ b.HasIndex("TagId");
+
+ b.ToTable("BookTags", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("PermissionName")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.HasKey("Id");
+
+ b.ToTable("Permissions", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("RoleName")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.HasKey("Id");
+
+ b.ToTable("Roles", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b =>
+ {
+ b.Property("RoleId")
+ .HasColumnType("TEXT");
+
+ b.Property("PermissionId")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("RoleId", "PermissionId");
+
+ b.HasIndex("PermissionId");
+
+ b.HasIndex("RoleId", "PermissionId")
+ .IsUnique();
+
+ b.ToTable("RolePermissions", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b =>
+ {
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.Property("PermissionId")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("UserId", "PermissionId");
+
+ b.HasIndex("PermissionId");
+
+ b.HasIndex("UserId", "PermissionId")
+ .IsUnique();
+
+ b.ToTable("UserPermissions", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b =>
+ {
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("RoleId")
+ .HasColumnType("TEXT");
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.HasKey("UserId");
+
+ b.HasIndex("RoleId");
+
+ b.HasIndex("UserId", "RoleId")
+ .IsUnique();
+
+ b.ToTable("UserRoles", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Genres", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", b =>
+ {
+ b.Property("Name")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT");
+
+ b.HasKey("Name");
+
+ b.ToTable("Tags", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaContributors.BookContributorEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("BookId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("MediaContributorId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("RoleCategory")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("RoleName")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.HasKey("Id");
+
+ b.HasIndex("MediaContributorId");
+
+ b.HasIndex("BookId", "MediaContributorId");
+
+ b.ToTable("BookContributors", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaContributors.MediaContributorEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("Biography")
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("DateOfBirth")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("DateOfDeath")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("DisplayName")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1)
+ .UseCollation("NOCASE");
+
+ b.Property("LegalName")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.HasKey("Id");
+
+ b.HasIndex("DisplayName")
+ .IsUnique();
+
+ b.ToTable("MediaContributors", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.DirectoryScanFingerprintEntity", b =>
+ {
+ b.Property("LibraryId")
+ .HasColumnType("TEXT");
+
+ b.Property("Path")
+ .HasMaxLength(1024)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("LastWriteTimeUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.HasKey("LibraryId", "Path");
+
+ b.HasIndex("LibraryId");
+
+ b.ToTable("DirectoryScanFingerprints", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("ArtworkProvidersConfigurationFingerprint")
+ .HasMaxLength(64)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(10);
+
+ b.Property("CanDownloadMetadataFromWeb")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER")
+ .HasDefaultValue(true)
+ .HasColumnOrder(6);
+
+ b.Property("CoverImage")
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(12);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(11);
+
+ b.Property("IsEnabled")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("INTEGER")
+ .HasDefaultValue(true)
+ .HasColumnOrder(4);
+
+ b.Property("IsLocked")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(5);
+
+ b.Property("LibraryType")
+ .IsRequired()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("MetadataProvidersConfigurationFingerprint")
+ .HasMaxLength(64)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("ShouldSaveMetadataInMediaDirectories")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(7);
+
+ b.Property("ShouldSkipUnchangedDirectoriesDuringScan")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(8);
+
+ b.Property("Title")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(14);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(13);
+
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("Libraries", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("LibraryId")
+ .HasColumnType("TEXT");
+
+ b.Property("Status")
+ .IsRequired()
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("UserId")
+ .HasColumnType("TEXT");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.HasIndex("LibraryId", "Status", "CreatedOnUtc")
+ .IsDescending(true, false, true);
+
+ b.ToTable("LibraryScans", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanResultEntity", b =>
+ {
+ b.Property("LibraryScanId")
+ .HasColumnType("TEXT");
+
+ b.Property("Path")
+ .HasMaxLength(1024)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("ContentHash")
+ .HasMaxLength(24)
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(2);
+
+ b.Property("FileSize")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(3);
+
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("Status")
+ .IsRequired()
+ .HasMaxLength(10)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("Ticks")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(4);
+
+ b.HasKey("LibraryScanId", "Path");
+
+ b.HasIndex("Path");
+
+ b.HasIndex("ContentHash", "FileSize", "Path");
+
+ b.ToTable("LibraryScanResults", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanSnapshotEntity", b =>
+ {
+ b.Property("LibraryId")
+ .HasColumnType("TEXT");
+
+ b.Property("Path")
+ .HasMaxLength(1024)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("ContentHash")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(2);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(5);
+
+ b.Property("FileSize")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(3);
+
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("Ticks")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(4);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.HasKey("LibraryId", "Path");
+
+ b.HasIndex("LibraryId");
+
+ b.ToTable("LibraryScanSnapshots", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanStagingResultsEntity", b =>
+ {
+ b.Property("LibraryScanId")
+ .HasColumnType("TEXT");
+
+ b.Property("Path")
+ .HasMaxLength(1024)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("ContentHash")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(4);
+
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("IsNew")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(7);
+
+ b.Property("NeedsRehash")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(6);
+
+ b.Property("PreviousContentHash")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(5);
+
+ b.Property("Size")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(2);
+
+ b.Property("Ticks")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(3);
+
+ b.HasKey("LibraryScanId", "Path");
+
+ b.HasIndex("LibraryScanId", "NeedsRehash");
+
+ b.ToTable("LibraryScanStagingResults", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookArtworkEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("ArtworkType")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(2);
+
+ b.Property("BookId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(1);
+
+ b.Property("ContentHash")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(5);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(10);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(9);
+
+ b.Property("FileName")
+ .HasMaxLength(2048)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(4);
+
+ b.Property("LastUpdateUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(8);
+
+ b.Property("Ordinal")
+ .HasColumnType("INTEGER")
+ .HasColumnOrder(3);
+
+ b.Property("Provider")
+ .HasMaxLength(100)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(7);
+
+ b.Property("Status")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(6);
+
+ b.Property("UpdatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(12);
+
+ b.Property("UpdatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(11);
+
+ b.HasKey("Id");
+
+ b.HasIndex("Status");
+
+ b.HasIndex("BookId", "ArtworkType", "Ordinal")
+ .IsUnique();
+
+ b.ToTable("BookArtwork", (string)null);
+ });
+
+ modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b =>
+ {
+ b.Property("Id")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(0);
+
+ b.Property("ASIN")
+ .HasMaxLength(10)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(21);
+
+ b.Property("AppleBooksId")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(29);
+
+ b.Property("BarnesAndNobleId")
+ .HasMaxLength(10)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(28);
+
+ b.Property("CreatedBy")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(33);
+
+ b.Property("CreatedOnUtc")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(32);
+
+ b.Property("Description")
+ .HasMaxLength(2000)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(3);
+
+ b.Property("Edition")
+ .HasMaxLength(50)
+ .HasColumnType("TEXT")
+ .HasColumnOrder(19);
+
+ b.Property("Format")
+ .HasColumnType("TEXT")
+ .HasColumnOrder(18);
+
+ b.Property