Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
C# annotationscbzcomicinfocomicscomics-readercross-platformcsharpepubepub-readerfreelinuxmangamedia-servermetadataopdsopds-feedpdfself-hostedubooquitywindows
Hooked up the API layer to be able to extract images from PDF again for Tachiyomi explicitly (#1686)
Joe Milazzo018c0ab15ca3
diff --git a/API/Controllers/ReaderController.cs b/API/Controllers/ReaderController.csindex cff8c24d4..c92f4398d 100644--- a/API/Controllers/ReaderController.cs+++ b/API/Controllers/ReaderController.cs@@ -87,16 +87,17 @@ public class ReaderController : BaseApiController/// Returns an image for a given chapter. Will perform bounding checks/// </summary>/// <remarks>This will cache the chapter images for reading</remarks>- /// <param name="chapterId"></param>- /// <param name="page"></param>+ /// <param name="chapterId">Chapter Id</param>+ /// <param name="page">Page in question</param>+ /// <param name="extractPdf">Should Kavita extract pdf into images. Defaults to false.</param>/// <returns></returns>[HttpGet("image")][ResponseCache(CacheProfileName = ResponseCacheProfiles.Hour)][AllowAnonymous]- public async Task<ActionResult> GetImage(int chapterId, int page)+ public async Task<ActionResult> GetImage(int chapterId, int page, bool extractPdf = false){if (page < 0) page = 0;- var chapter = await _cacheService.Ensure(chapterId);+ var chapter = await _cacheService.Ensure(chapterId, extractPdf);if (chapter == null) return BadRequest("There was an issue finding image file for reading");try@@ -155,12 +156,13 @@ public class ReaderController : BaseApiController/// Returns various information about a Chapter. Side effect: This will cache the chapter images for reading./// </summary>/// <param name="chapterId"></param>+ /// <param name="extractPdf">Should Kavita extract pdf into images. Defaults to false.</param>/// <returns></returns>[HttpGet("chapter-info")]- public async Task<ActionResult<ChapterInfoDto>> GetChapterInfo(int chapterId)+ public async Task<ActionResult<ChapterInfoDto>> GetChapterInfo(int chapterId, bool extractPdf = false){if (chapterId <= 0) return null; // This can happen occasionally from UI, we should just ignore- var chapter = await _cacheService.Ensure(chapterId);+ var chapter = await _cacheService.Ensure(chapterId, extractPdf);if (chapter == null) return BadRequest("Could not find Chapter");var dto = await _unitOfWork.ChapterRepository.GetChapterInfoDtoAsync(chapterId);diff --git a/API/Services/BookService.cs b/API/Services/BookService.csindex e358a46e2..3244ce07f 100644--- a/API/Services/BookService.cs+++ b/API/Services/BookService.cs@@ -49,9 +49,9 @@ public interface IBookService/// <summary>/// Extracts a PDF file's pages as images to an target directory/// </summary>+ /// <remarks>This method relies on Docnet which has explict patches from Kavita for ARM support. This should only be used with Tachiyomi</remarks>/// <param name="fileFilePath"></param>/// <param name="targetDirectory">Where the files will be extracted to. If doesn't exist, will be created.</param>- [Obsolete("This method of reading is no longer supported. Please use native pdf reader")]void ExtractPdfImages(string fileFilePath, string targetDirectory);Task<string> ScopePage(HtmlDocument doc, EpubBookRef book, string apiBase, HtmlNode body, Dictionary<string, int> mappings, int page);diff --git a/API/Services/CacheService.cs b/API/Services/CacheService.csindex 7cf00bf57..95a9a646e 100644--- a/API/Services/CacheService.cs+++ b/API/Services/CacheService.cs@@ -20,8 +20,9 @@ public interface ICacheService/// cache operations (except cleanup)./// </summary>/// <param name="chapterId"></param>+ /// <param name="extractPdfToImages">Extracts a PDF into images for a different reading experience</param>/// <returns>Chapter for the passed chapterId. Side-effect from ensuring cache.</returns>- Task<Chapter> Ensure(int chapterId);+ Task<Chapter> Ensure(int chapterId, bool extractPdfToImages = false);/// <summary>/// Clears cache directory of all volumes. This can be invoked from deleting a library or a series./// </summary>@@ -31,7 +32,7 @@ public interface ICacheServicestring GetCachedPagePath(Chapter chapter, int page);string GetCachedBookmarkPagePath(int seriesId, int page);string GetCachedFile(Chapter chapter);- public void ExtractChapterFiles(string extractPath, IReadOnlyList<MangaFile> files);+ public void ExtractChapterFiles(string extractPath, IReadOnlyList<MangaFile> files, bool extractPdfImages = false);Task<int> CacheBookmarkForSeries(int userId, int seriesId);void CleanupBookmarkCache(int seriesId);}@@ -95,7 +96,7 @@ public class CacheService : ICacheService/// </summary>/// <param name="chapterId"></param>/// <returns>This will always return the Chapter for the chapterId</returns>- public async Task<Chapter> Ensure(int chapterId)+ public async Task<Chapter> Ensure(int chapterId, bool extractPdfToImages = false){_directoryService.ExistOrCreate(_directoryService.CacheDirectory);var chapter = await _unitOfWork.ChapterRepository.GetChapterAsync(chapterId);@@ -103,7 +104,7 @@ public class CacheService : ICacheServiceif (_directoryService.Exists(extractPath)) return chapter;var files = chapter?.Files.ToList();- ExtractChapterFiles(extractPath, files);+ ExtractChapterFiles(extractPath, files, extractPdfToImages);return chapter;}@@ -114,8 +115,9 @@ public class CacheService : ICacheService/// </summary>/// <param name="extractPath"></param>/// <param name="files"></param>+ /// <param name="extractPdfImages">Defaults to false, if true, will extract the images from the PDF renderer and not move the pdf file</param>/// <returns></returns>- public void ExtractChapterFiles(string extractPath, IReadOnlyList<MangaFile> files)+ public void ExtractChapterFiles(string extractPath, IReadOnlyList<MangaFile> files, bool extractPdfImages = false){var removeNonImages = true;var fileCount = files.Count;@@ -143,12 +145,17 @@ public class CacheService : ICacheServicecase MangaFormat.Epub:case MangaFormat.Pdf:{- removeNonImages = false;if (!_directoryService.FileSystem.File.Exists(files[0].FilePath)){_logger.LogError("{File} does not exist on disk", files[0].FilePath);throw new KavitaException($"{files[0].FilePath} does not exist on disk");}+ if (extractPdfImages)+ {+ _readingItemService.Extract(file.FilePath, Path.Join(extractPath, extraPath), file.Format);+ break;+ }+ removeNonImages = false;_directoryService.ExistOrCreate(extractPath);_directoryService.CopyFileToDirectory(files[0].FilePath, extractPath);diff --git a/API/Services/ReadingItemService.cs b/API/Services/ReadingItemService.csindex a70f7f38e..14ced8674 100644--- a/API/Services/ReadingItemService.cs+++ b/API/Services/ReadingItemService.cs@@ -199,6 +199,8 @@ public class ReadingItemService : IReadingItemService_imageService.ExtractImages(fileFilePath, targetDirectory, imageCount);break;case MangaFormat.Pdf:+ _bookService.ExtractPdfImages(fileFilePath, targetDirectory);+ break;case MangaFormat.Unknown:case MangaFormat.Epub:break;diff --git a/openapi.json b/openapi.jsonindex 3e4194f53..13a9800e7 100644--- a/openapi.json+++ b/openapi.json@@ -7,7 +7,7 @@"name": "GPL-3.0","url": "https://github.com/Kareadita/Kavita/blob/develop/LICENSE"},- "version": "0.6.1.7"+ "version": "0.6.1.8"},"servers": [{@@ -3411,7 +3411,7 @@{"name": "chapterId","in": "query",- "description": "",+ "description": "Chapter Id","schema": {"type": "integer","format": "int32"@@ -3420,11 +3420,20 @@{"name": "page","in": "query",- "description": "",+ "description": "Page in question","schema": {"type": "integer","format": "int32"}+ },+ {+ "name": "extractPdf",+ "in": "query",+ "description": "Should Kavita extract pdf into images. Defaults to false.",+ "schema": {+ "type": "boolean",+ "default": false+ }}],"responses": {@@ -3491,6 +3500,15 @@"type": "integer","format": "int32"}+ },+ {+ "name": "extractPdf",+ "in": "query",+ "description": "Should Kavita extract pdf into images. Defaults to false.",+ "schema": {+ "type": "boolean",+ "default": false+ }}],"responses": {