Adds book reading support with EPUB and PDF reader plugins

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

No files matched your search

@@ -16,13 +16,13 @@ using System.IO.Abstractions;
namespace Lumina.Domain.Common.DependencyInjection;
/// <summary>
/// Contains all services of the Domain layer.
/// Utility class for registering the services of the Domain layer into the Dependency Injection container.
/// </summary>
[ExcludeFromCodeCoverage]
public static class DomainLayerServices
{
/// <summary>
/// Registers the services of the Domain layer into the dependency injection container.
/// Registers the services of the Domain layer into the Dependency Injection container.
/// </summary>
/// <param name="services">The service collection to add the services to.</param>
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Domain.Common.Errors;
/// <summary>
/// Domain reading related error types.
/// </summary>
public static partial class Errors
{
public static class Reading
{
public static Error BookIdCannotBeEmpty => Error.Validation(description: nameof(BookIdCannotBeEmpty));
public static Error LocationRefCannotBeEmpty => Error.Validation(description: nameof(LocationRefCannotBeEmpty));
public static Error ResourceKeyCannotBeEmpty => Error.Validation(description: nameof(ResourceKeyCannotBeEmpty));
public static Error BookNotFound => Error.NotFound(description: nameof(BookNotFound));
public static Error NoReaderAvailable => Error.NotFound(description: nameof(NoReaderAvailable));
public static Error ReaderDisabled => Error.NotFound(description: nameof(ReaderDisabled));
public static Error BookFileNotFound => Error.NotFound(description: nameof(BookFileNotFound));
public static Error SectionNotFound => Error.NotFound(description: nameof(SectionNotFound));
public static Error ResourceNotFound => Error.NotFound(description: nameof(ResourceNotFound));
}
}
@@ -20,6 +20,8 @@ public class UserSettings : AggregateRoot<UserSettingsId>
private const bool DEFAULT_IGNORE_THE_PREFIX_FOR_ALPHA_PICKER = false;
private const bool DEFAULT_IS_THEME_CACHING_ENABLED = true;
private const bool DEFAULT_AGGREGATE_METADATA_WHEN_MISSING = false;
private const bool DEFAULT_SHOULD_RENDER_PDF_AS_IMAGES = false;
private const bool DEFAULT_SHOULD_PRESERVE_BOOK_STYLES = true;
/// <summary>
/// Gets the object representing the unique identifier of the user that owns these settings.
@@ -51,6 +53,19 @@ public class UserSettings : AggregateRoot<UserSettingsId>
/// </summary>
public bool ShouldAggregateMetadataWhenMissing { get; private set; }
/// <summary>
/// Gets 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.
/// </summary>
public bool ShouldRenderPdfAsImages { get; private set; }
/// <summary>
/// Gets 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.
/// </summary>
public bool ShouldPreserveBookStyles { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="UserSettings"/> class.
/// </summary>
@@ -61,6 +76,8 @@ public class UserSettings : AggregateRoot<UserSettingsId>
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether the "The" prefix of library item titles is ignored by the alpha picker, or not.</param>
/// <param name="isThemeCachingEnabled">Whether the theme data served to this user is cached, or not.</param>
/// <param name="shouldAggregateMetadataWhenMissing">Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing, or not.</param>
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user, or not.</param>
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user, or not.</param>
private UserSettings(
UserSettingsId id,
UserId userId,
@@ -68,7 +85,9 @@ public class UserSettings : AggregateRoot<UserSettingsId>
int itemsPerPage,
bool shouldIgnoreThePrefixForAlphaPicker,
bool isThemeCachingEnabled,
bool shouldAggregateMetadataWhenMissing) : base(id)
bool shouldAggregateMetadataWhenMissing,
bool shouldRenderPdfAsImages,
bool shouldPreserveBookStyles) : base(id)
{
UserId = userId;
IsPaginationEnabled = isPaginationEnabled;
@@ -76,6 +95,8 @@ public class UserSettings : AggregateRoot<UserSettingsId>
ShouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker;
IsThemeCachingEnabled = isThemeCachingEnabled;
ShouldAggregateMetadataWhenMissing = shouldAggregateMetadataWhenMissing;
ShouldRenderPdfAsImages = shouldRenderPdfAsImages;
ShouldPreserveBookStyles = shouldPreserveBookStyles;
}
/// <summary>
@@ -86,7 +107,16 @@ public class UserSettings : AggregateRoot<UserSettingsId>
/// </returns>
public static Result<UserSettings> Create()
{
return Create(UserId.CreateUnique(), DEFAULT_IS_PAGINATION_ENABLED, DEFAULT_ITEMS_PER_PAGE, DEFAULT_IGNORE_THE_PREFIX_FOR_ALPHA_PICKER, DEFAULT_IS_THEME_CACHING_ENABLED, DEFAULT_AGGREGATE_METADATA_WHEN_MISSING);
return Create(
UserId.CreateUnique(),
DEFAULT_IS_PAGINATION_ENABLED,
DEFAULT_ITEMS_PER_PAGE,
DEFAULT_IGNORE_THE_PREFIX_FOR_ALPHA_PICKER,
DEFAULT_IS_THEME_CACHING_ENABLED,
DEFAULT_AGGREGATE_METADATA_WHEN_MISSING,
DEFAULT_SHOULD_RENDER_PDF_AS_IMAGES,
DEFAULT_SHOULD_PRESERVE_BOOK_STYLES
);
}
/// <summary>
@@ -98,7 +128,16 @@ public class UserSettings : AggregateRoot<UserSettingsId>
/// </returns>
public static Result<UserSettings> Create(UserId userId)
{
return Create(userId, DEFAULT_IS_PAGINATION_ENABLED, DEFAULT_ITEMS_PER_PAGE, DEFAULT_IGNORE_THE_PREFIX_FOR_ALPHA_PICKER, DEFAULT_IS_THEME_CACHING_ENABLED, DEFAULT_AGGREGATE_METADATA_WHEN_MISSING);
return Create(
userId,
DEFAULT_IS_PAGINATION_ENABLED,
DEFAULT_ITEMS_PER_PAGE,
DEFAULT_IGNORE_THE_PREFIX_FOR_ALPHA_PICKER,
DEFAULT_IS_THEME_CACHING_ENABLED,
DEFAULT_AGGREGATE_METADATA_WHEN_MISSING,
DEFAULT_SHOULD_RENDER_PDF_AS_IMAGES,
DEFAULT_SHOULD_PRESERVE_BOOK_STYLES
);
}
/// <summary>
@@ -110,6 +149,8 @@ public class UserSettings : AggregateRoot<UserSettingsId>
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether the "The" prefix of library item titles is ignored by the alpha picker, or not.</param>
/// <param name="isThemeCachingEnabled">Whether the theme data served to this user is cached, or not.</param>
/// <param name="shouldAggregateMetadataWhenMissing">Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing, or not.</param>
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user, or not.</param>
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user, or not.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="UserSettings"/>, or an error message.
/// </returns>
@@ -119,7 +160,9 @@ public class UserSettings : AggregateRoot<UserSettingsId>
int itemsPerPage,
bool shouldIgnoreThePrefixForAlphaPicker,
bool isThemeCachingEnabled,
bool shouldAggregateMetadataWhenMissing)
bool shouldAggregateMetadataWhenMissing,
bool shouldRenderPdfAsImages,
bool shouldPreserveBookStyles)
{
if (itemsPerPage <= 0)
return Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero;
@@ -131,7 +174,9 @@ public class UserSettings : AggregateRoot<UserSettingsId>
itemsPerPage,
shouldIgnoreThePrefixForAlphaPicker,
isThemeCachingEnabled,
shouldAggregateMetadataWhenMissing);
shouldAggregateMetadataWhenMissing,
shouldRenderPdfAsImages,
shouldPreserveBookStyles);
}
/// <summary>
@@ -144,6 +189,8 @@ public class UserSettings : AggregateRoot<UserSettingsId>
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether the "The" prefix of library item titles is ignored by the alpha picker, or not.</param>
/// <param name="isThemeCachingEnabled">Whether the theme data served to this user is cached, or not.</param>
/// <param name="shouldAggregateMetadataWhenMissing">Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing, or not.</param>
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user, or not.</param>
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user, or not.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="UserSettings"/>, or an error message.
/// </returns>
@@ -154,12 +201,14 @@ public class UserSettings : AggregateRoot<UserSettingsId>
int itemsPerPage,
bool shouldIgnoreThePrefixForAlphaPicker,
bool isThemeCachingEnabled,
bool shouldAggregateMetadataWhenMissing)
bool shouldAggregateMetadataWhenMissing,
bool shouldRenderPdfAsImages,
bool shouldPreserveBookStyles)
{
if (itemsPerPage <= 0)
return Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero;
return new UserSettings(id, userId, isPaginationEnabled, itemsPerPage, shouldIgnoreThePrefixForAlphaPicker, isThemeCachingEnabled, shouldAggregateMetadataWhenMissing);
return new UserSettings(id, userId, isPaginationEnabled, itemsPerPage, shouldIgnoreThePrefixForAlphaPicker, isThemeCachingEnabled, shouldAggregateMetadataWhenMissing, shouldRenderPdfAsImages, shouldPreserveBookStyles);
}
/// <summary>
@@ -170,13 +219,17 @@ public class UserSettings : AggregateRoot<UserSettingsId>
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether the "The" prefix of library item titles is ignored by the alpha picker, or not.</param>
/// <param name="isThemeCachingEnabled">Whether the theme data served to this user is cached, or not.</param>
/// <param name="shouldAggregateMetadataWhenMissing">Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing, or not.</param>
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user, or not.</param>
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user, or not.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful update, or an error.</returns>
public Result<Updated> UpdateSettings(
bool isPaginationEnabled,
int itemsPerPage,
bool shouldIgnoreThePrefixForAlphaPicker,
bool isThemeCachingEnabled,
bool shouldAggregateMetadataWhenMissing)
bool shouldAggregateMetadataWhenMissing,
bool shouldRenderPdfAsImages,
bool shouldPreserveBookStyles)
{
if (itemsPerPage <= 0)
return Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero;
@@ -186,6 +239,8 @@ public class UserSettings : AggregateRoot<UserSettingsId>
ShouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker;
IsThemeCachingEnabled = isThemeCachingEnabled;
ShouldAggregateMetadataWhenMissing = shouldAggregateMetadataWhenMissing;
ShouldRenderPdfAsImages = shouldRenderPdfAsImages;
ShouldPreserveBookStyles = shouldPreserveBookStyles;
return Result.Updated;
}
}