diff --git a/docs/technical/architecture/4.2 code-book-reading-diagram.puml b/docs/technical/architecture/4.2 code-book-reading-diagram.puml index 3f319d1d..04df1260 100644 --- a/docs/technical/architecture/4.2 code-book-reading-diagram.puml +++ b/docs/technical/architecture/4.2 code-book-reading-diagram.puml @@ -123,17 +123,35 @@ class GetLibraryBookReadersQueryHandler { + HandleAsync(query: GetLibraryBookReadersQuery, token: CancellationToken): Task>> } -class SetLibraryBookReaderEnabledCommandHandler { +class GetLibraryTypeBookReadersQueryHandler { - _unitOfWork: IUnitOfWork - - _enablementCache: IBookReaderEnablementCache - + HandleAsync(command: SetLibraryBookReaderEnabledCommand, token: CancellationToken): Task> + - _providerConfigurationStore: IMediaLibraryProviderConfigurationStore + - _bookReaderRegistry: IBookReaderRegistry + + HandleAsync(query: GetLibraryTypeBookReadersQuery, token: CancellationToken): Task>> } -note right of SetLibraryBookReaderEnabledCommandHandler - Enables or disables the book reader of a plugin for a media - library by upserting its configuration row, then invalidates - the enablement cache so that a disabled reader stops being - served immediately. +note right of GetLibraryTypeBookReadersQueryHandler + Lists the book readers that support a library type, disabled, + so that they can be chosen before a library is created or + before a change of its type is saved. +end note + +class MediaLibraryProviderConfigurationStore { + - _unitOfWork: IUnitOfWork + - _enablementCache: IBookReaderEnablementCache + + ConfigureProvidersAsync(libraryId: Guid, libraryType: LibraryType, metadataProviders: IReadOnlyList?, artworkProviders: IReadOnlyList?, bookReaders: IReadOnlyList?, shouldReconcileOmittedKinds: bool, token: CancellationToken): Task> + + GetSupportedBookReaderPluginIds(libraryType: LibraryType): IReadOnlyList +} + +note right of MediaLibraryProviderConfigurationStore + Called by the add and update library commands. Applies the + chosen metadata providers, artwork providers and book readers + of a media library by upserting their configuration rows in + the same save as the library. When shouldReconcileOmittedKinds + is set, the kinds without explicit choices are reconciled with + the library type first. Book reader changes invalidate the + enablement cache of the library so that a disabled reader + stops being served immediately. end note ' ============================== BOOK READER PLUGINS ============================== @@ -221,8 +239,10 @@ BookReaderRegistry ..> IBookReader : reads the supported extensions of loaded pl GetLibraryBookReadersQueryHandler --> ILibraryBookReaderConfigurationRepository : reads configurations GetLibraryBookReadersQueryHandler --> IBookReaderRegistry : reads supported extensions -SetLibraryBookReaderEnabledCommandHandler --> ILibraryBookReaderConfigurationRepository : upserts the configuration -SetLibraryBookReaderEnabledCommandHandler --> IBookReaderEnablementCache : invalidates the entry +GetLibraryTypeBookReadersQueryHandler --> MediaLibraryProviderConfigurationStore : reads the supported readers +GetLibraryTypeBookReadersQueryHandler --> IBookReaderRegistry : reads supported extensions +MediaLibraryProviderConfigurationStore --> ILibraryBookReaderConfigurationRepository : upserts the configurations +MediaLibraryProviderConfigurationStore --> IBookReaderEnablementCache : invalidates the library entries ILibraryBookReaderConfigurationRepository --> LibraryBookReaderConfigurationEntity : persists diff --git a/docs/technical/architecture/4.2 code-book-reading-diagram.svg b/docs/technical/architecture/4.2 code-book-reading-diagram.svg index e137e374..71f770f4 100644 --- a/docs/technical/architecture/4.2 code-book-reading-diagram.svg +++ b/docs/technical/architecture/4.2 code-book-reading-diagram.svg @@ -1 +1 @@ -Code diagram for Book Reading 3.2.2 and Book Reader PluginsIBookReadingServiceGetManifestAsync(bookId:Guid, libraryId: Guid, path:string, libraryType: LibraryType,shouldRenderPdfAsImages:bool, token:CancellationToken):Task<Result<ReadingManifestResponse>>GetSectionAsync(bookId: Guid,libraryId: Guid, path: string,libraryType: LibraryType,locationRef: string,shouldRenderPdfAsImages:bool, shouldPreserveStyles:bool, token:CancellationToken):Task<Result<ReadingSectionDto>>GetResourceAsync(bookId:Guid, libraryId: Guid, path:string, libraryType: LibraryType,resourceKey: string,shouldRenderPdfAsImages:bool, token:CancellationToken):Task<Result<ReadingResourceDataDto>>GetAvailabilityAsync(bookId:Guid, libraryId: Guid, path:string, libraryType: LibraryType,token: CancellationToken):Task<Result<ReadingAvailabilityResponse>>IBookReaderRegistryGetSupportedExtensionsByPluginId():IReadOnlyDictionary<Guid,IReadOnlyList<string>>IBookReaderEnablementCacheGet(libraryId: Guid, pluginId:Guid): bool?Set(libraryId: Guid, pluginId:Guid, isEnabled: bool)Invalidate(libraryId: Guid,pluginId: Guid)InvalidateLibrary(libraryId: Guid)InvalidatePlugin(pluginId: Guid)BookReadingService_extractions:ConcurrentDictionary<ReadingCacheKey,BookExtractionEntry>_bookExtractionLocks:ConcurrentDictionary<ReadingCacheKey,SemaphoreSlim>_pluginIdsByReaderKey:IReadOnlyDictionary<ReaderKey,Guid>_enablementCache:IBookReaderEnablementCacheGetManifestAsync(...):Task<Result<ReadingManifestResponse>>GetSectionAsync(...):Task<Result<ReadingSectionDto>>GetResourceAsync(...):Task<Result<ReadingResourceDataDto>>GetAvailabilityAsync(...):Task<Result<ReadingAvailabilityResponse>>Serves the manifest, sections andresources of a book:resolves the reader of the bookformat, checks theper-library enablement through thecache, reuses the alreadyextracted document while thefingerprint of the book file isunchanged, extracts eachrendering preference (text or pageimages) into its own directoryunder the reading cache, andproduces on-demand resources(for example a PDF page render)once per resource file.BookReaderRegistry_pluginManager:IPluginManager_serviceProvider:IServiceProviderGetSupportedExtensionsByPluginId():IReadOnlyDictionary<Guid,IReadOnlyList<string>>Reads the supported extensionslive from the book readersregistered by the loaded plugins,so that a plugin updatethat changes its formats neverleaves stale configurations.BookReaderEnablementCache_enablements:ConcurrentDictionary<(GuidLibraryId, Guid PluginId), bool>Get(libraryId: Guid, pluginId:Guid): bool?Set(libraryId: Guid, pluginId:Guid, isEnabled: bool)Invalidate(libraryId: Guid,pluginId: Guid)InvalidateLibrary(libraryId: Guid)InvalidatePlugin(pluginId: Guid)ReadingCachePathsDIRECTORY_NAME: string =reading-cacheGetRootDirectory(): stringThe reading cache is a temporarydirectory in the API output,wiped at startup, under whichevery book keeps one directoryper rendering preference (text andimages).ReadingContentSanitizerRESOURCE_ATTRIBUTE:string = data-lumina-resourceSanitize(html: string,shouldPreserveStyles: bool):stringSanitizes every reading sectionwith an explicit allowlist ofinert markup, regardless of whatthe reader plugin produced;whether the style attributesurvives is the per-user choice.LibraryBookReaderConfigurationEntityId: GuidLibraryId: GuidPluginId: GuidIsEnabled: boolILibraryBookReaderConfigurationRepositoryGetByLibraryIdAsync(libraryId:Guid, token:CancellationToken):Task<Result<IReadOnlyList<LibraryBookReaderConfigurationEntity>>>GetByLibraryAndPluginIdAsync(libraryId:Guid, pluginId: Guid, token:CancellationToken):Task<Result<LibraryBookReaderConfigurationEntity?>>UpsertAsync(configuration:LibraryBookReaderConfigurationEntity,token: CancellationToken):Task<Result<Updated>>DeleteByLibraryIdAsync(libraryId:Guid, token:CancellationToken):Task<Result<Deleted>>DeleteByPluginIdAsync(pluginId:Guid, token:CancellationToken):Task<Result<Deleted>>DeleteByLibraryIdAndPluginIdsAsync(libraryId:Guid, pluginIds:IEnumerable<Guid>, token:CancellationToken):Task<Result<Deleted>>LibraryBookReaderConfigurationRepositoryGetLibraryBookReadersQueryHandler_unitOfWork: IUnitOfWork_bookReaderRegistry:IBookReaderRegistryHandleAsync(query:GetLibraryBookReadersQuery,token: CancellationToken):Task<Result<IReadOnlyList<LibraryBookReaderResponse>>>SetLibraryBookReaderEnabledCommandHandler_unitOfWork: IUnitOfWork_enablementCache:IBookReaderEnablementCacheHandleAsync(command:SetLibraryBookReaderEnabledCommand,token: CancellationToken):Task<Result<Success>>Enables or disables the bookreader of a plugin for a medialibrary by upserting itsconfiguration row, then invalidatesthe enablement cache so that adisabled reader stops beingserved immediately.IBookReaderSupportedExtensions:IReadOnlyList<string>SupportedLibraryTypes:IReadOnlyList<LibraryType>OpenAsync(path: string,workingDirectory: string,shouldRenderPdfAsImages:bool, token:CancellationToken):Task<ReadingDocumentDto>GetResourceAsync(path: string,workingDirectory: string,resourceKey: string, token:CancellationToken):Task<byte[]>Contract of a reader plugin,implemented inLumina.Plugins.Contracts.The plugins are host-trusted: theyreceive the absolute path of thebook and a working directory toextract into, while the hostsanitizes and contained-checkseverything they produce beforeserving it to the client.EpubReaderReads .epub books of the EBookand Book library types.EPUB is a ZIP archive, decodedentry by entry with boundedsizes and archive-containedpaths.EpubDocumentParserParse(epubPath: string,workingDirectory: string, token:CancellationToken):ReadingDocumentDtoPdfReaderReads .pdf books of the EBookand Book library types.Each page is a reading section;the table of contents comesfrom the PDF bookmarks.PdfDocumentParserParse(pdfPath: string,workingDirectory: string,shouldRenderPdfAsImages:bool, token:CancellationToken):ReadingDocumentDtoRenderResource(pdfPath:string, resourceKey: string,token: CancellationToken):byte[]Extracts the text layer of thepages with PdfPig, and rendersthe pages as images withPDFtoImage on demand when therender-as-images user setting isenabled; file size, page countand rendered page area arebounded.EpubPluginId: GuidName: string = EPUB ReaderRegisterServices(services:IServiceCollection)PdfPluginId: GuidName: string = PDF ReaderRegisterServices(services:IServiceCollection)implementsimplementsimplementsimplementsfinds the plugin of the book formatchecks the per-library enablementfills the cache on a missopens and produces resourcessanitizes section contentextracts into and serves fromreads the supported extensions ofloaded pluginsreads configurationsreads supported extensionsupserts the configurationinvalidates the entrypersistsimplementsimplementsparsesparses and renders pagesregisters as a keyed IBookReaderregisters as a keyed IBookReaderLegend personsystemcontainercomponentexternal personexternal systemexternal containerexternal component[Code] Lumina - Book Reading 3.2.2 and Book Reader PluginsThe code diagram for the Book Reading 3.2.2 and the Book Reader Plugins - created with PlantUML \ No newline at end of file +Code diagram for Book Reading 3.2.2 and Book Reader PluginsIBookReadingServiceGetManifestAsync(bookId:Guid, libraryId: Guid, path:string, libraryType: LibraryType,shouldRenderPdfAsImages:bool, token:CancellationToken):Task<Result<ReadingManifestResponse>>GetSectionAsync(bookId: Guid,libraryId: Guid, path: string,libraryType: LibraryType,locationRef: string,shouldRenderPdfAsImages:bool, shouldPreserveStyles:bool, token:CancellationToken):Task<Result<ReadingSectionDto>>GetResourceAsync(bookId:Guid, libraryId: Guid, path:string, libraryType: LibraryType,resourceKey: string,shouldRenderPdfAsImages:bool, token:CancellationToken):Task<Result<ReadingResourceDataDto>>GetAvailabilityAsync(bookId:Guid, libraryId: Guid, path:string, libraryType: LibraryType,token: CancellationToken):Task<Result<ReadingAvailabilityResponse>>IBookReaderRegistryGetSupportedExtensionsByPluginId():IReadOnlyDictionary<Guid,IReadOnlyList<string>>IBookReaderEnablementCacheGet(libraryId: Guid, pluginId:Guid): bool?Set(libraryId: Guid, pluginId:Guid, isEnabled: bool)Invalidate(libraryId: Guid,pluginId: Guid)InvalidateLibrary(libraryId: Guid)InvalidatePlugin(pluginId: Guid)BookReadingService_extractions:ConcurrentDictionary<ReadingCacheKey,BookExtractionEntry>_bookExtractionLocks:ConcurrentDictionary<ReadingCacheKey,SemaphoreSlim>_pluginIdsByReaderKey:IReadOnlyDictionary<ReaderKey,Guid>_enablementCache:IBookReaderEnablementCacheGetManifestAsync(...):Task<Result<ReadingManifestResponse>>GetSectionAsync(...):Task<Result<ReadingSectionDto>>GetResourceAsync(...):Task<Result<ReadingResourceDataDto>>GetAvailabilityAsync(...):Task<Result<ReadingAvailabilityResponse>>Serves the manifest, sections andresources of a book:resolves the reader of the bookformat, checks theper-library enablement through thecache, reuses the alreadyextracted document while thefingerprint of the book file isunchanged, extracts eachrendering preference (text or pageimages) into its own directoryunder the reading cache, andproduces on-demand resources(for example a PDF page render)once per resource file.BookReaderRegistry_pluginManager:IPluginManager_serviceProvider:IServiceProviderGetSupportedExtensionsByPluginId():IReadOnlyDictionary<Guid,IReadOnlyList<string>>Reads the supported extensionslive from the book readersregistered by the loaded plugins,so that a plugin updatethat changes its formats neverleaves stale configurations.BookReaderEnablementCache_enablements:ConcurrentDictionary<(GuidLibraryId, Guid PluginId), bool>Get(libraryId: Guid, pluginId:Guid): bool?Set(libraryId: Guid, pluginId:Guid, isEnabled: bool)Invalidate(libraryId: Guid,pluginId: Guid)InvalidateLibrary(libraryId: Guid)InvalidatePlugin(pluginId: Guid)ReadingCachePathsDIRECTORY_NAME: string =reading-cacheGetRootDirectory(): stringThe reading cache is a temporarydirectory in the API output,wiped at startup, under whichevery book keeps one directoryper rendering preference (text andimages).ReadingContentSanitizerRESOURCE_ATTRIBUTE:string = data-lumina-resourceSanitize(html: string,shouldPreserveStyles: bool):stringSanitizes every reading sectionwith an explicit allowlist ofinert markup, regardless of whatthe reader plugin produced;whether the style attributesurvives is the per-user choice.LibraryBookReaderConfigurationEntityId: GuidLibraryId: GuidPluginId: GuidIsEnabled: boolILibraryBookReaderConfigurationRepositoryGetByLibraryIdAsync(libraryId:Guid, token:CancellationToken):Task<Result<IReadOnlyList<LibraryBookReaderConfigurationEntity>>>GetByLibraryAndPluginIdAsync(libraryId:Guid, pluginId: Guid, token:CancellationToken):Task<Result<LibraryBookReaderConfigurationEntity?>>UpsertAsync(configuration:LibraryBookReaderConfigurationEntity,token: CancellationToken):Task<Result<Updated>>DeleteByLibraryIdAsync(libraryId:Guid, token:CancellationToken):Task<Result<Deleted>>DeleteByPluginIdAsync(pluginId:Guid, token:CancellationToken):Task<Result<Deleted>>DeleteByLibraryIdAndPluginIdsAsync(libraryId:Guid, pluginIds:IEnumerable<Guid>, token:CancellationToken):Task<Result<Deleted>>LibraryBookReaderConfigurationRepositoryGetLibraryBookReadersQueryHandler_unitOfWork: IUnitOfWork_bookReaderRegistry:IBookReaderRegistryHandleAsync(query:GetLibraryBookReadersQuery,token: CancellationToken):Task<Result<IReadOnlyList<LibraryBookReaderResponse>>>GetLibraryTypeBookReadersQueryHandler_unitOfWork: IUnitOfWork_providerConfigurationStore:IMediaLibraryProviderConfigurationStore_bookReaderRegistry:IBookReaderRegistryHandleAsync(query:GetLibraryTypeBookReadersQuery,token: CancellationToken):Task<Result<IReadOnlyList<LibraryBookReaderResponse>>>Lists the book readers thatsupport a library type, disabled,so that they can be chosen beforea library is created orbefore a change of its type issaved.MediaLibraryProviderConfigurationStore_unitOfWork: IUnitOfWork_enablementCache:IBookReaderEnablementCacheConfigureProvidersAsync(libraryId:Guid, libraryType: LibraryType,metadataProviders:IReadOnlyList<LibraryProviderSelectionDto>?,artworkProviders:IReadOnlyList<LibraryProviderSelectionDto>?,bookReaders:IReadOnlyList<LibraryProviderSelectionDto>?,shouldReconcileOmittedKinds:bool, token:CancellationToken):Task<Result<Success>>GetSupportedBookReaderPluginIds(libraryType:LibraryType):IReadOnlyList<Guid>Called by the add and updatelibrary commands. Applies thechosen metadata providers,artwork providers and bookreadersof a media library by upsertingtheir configuration rows inthe same save as the library.WhenshouldReconcileOmittedKindsis set, the kinds without explicitchoices are reconciled withthe library type first. Book readerchanges invalidate theenablement cache of the library sothat a disabled readerstops being served immediately.IBookReaderSupportedExtensions:IReadOnlyList<string>SupportedLibraryTypes:IReadOnlyList<LibraryType>OpenAsync(path: string,workingDirectory: string,shouldRenderPdfAsImages:bool, token:CancellationToken):Task<ReadingDocumentDto>GetResourceAsync(path: string,workingDirectory: string,resourceKey: string, token:CancellationToken):Task<byte[]>Contract of a reader plugin,implemented inLumina.Plugins.Contracts.The plugins are host-trusted: theyreceive the absolute path of thebook and a working directory toextract into, while the hostsanitizes and contained-checkseverything they produce beforeserving it to the client.EpubReaderReads .epub books of the EBookand Book library types.EPUB is a ZIP archive, decodedentry by entry with boundedsizes and archive-containedpaths.EpubDocumentParserParse(epubPath: string,workingDirectory: string, token:CancellationToken):ReadingDocumentDtoPdfReaderReads .pdf books of the EBookand Book library types.Each page is a reading section;the table of contents comesfrom the PDF bookmarks.PdfDocumentParserParse(pdfPath: string,workingDirectory: string,shouldRenderPdfAsImages:bool, token:CancellationToken):ReadingDocumentDtoRenderResource(pdfPath:string, resourceKey: string,token: CancellationToken):byte[]Extracts the text layer of thepages with PdfPig, and rendersthe pages as images withPDFtoImage on demand when therender-as-images user setting isenabled; file size, page countand rendered page area arebounded.EpubPluginId: GuidName: string = EPUB ReaderRegisterServices(services:IServiceCollection)PdfPluginId: GuidName: string = PDF ReaderRegisterServices(services:IServiceCollection)implementsimplementsimplementsimplementsfinds the plugin of the book formatchecks the per-library enablementfills the cache on a missopens and produces resourcessanitizes section contentextracts into and serves fromreads the supported extensions ofloaded pluginsreads configurationsreads supported extensionsreads the supported readersreads supported extensionsupserts the configurationsinvalidates the library entriespersistsimplementsimplementsparsesparses and renders pagesregisters as a keyed IBookReaderregisters as a keyed IBookReaderLegend personsystemcontainercomponentexternal personexternal systemexternal containerexternal component[Code] Lumina - Book Reading 3.2.2 and Book Reader PluginsThe code diagram for the Book Reading 3.2.2 and the Book Reader Plugins - created with PlantUML \ No newline at end of file