Fixed: [OPDS] Recreate a pdf chapter's cache if images are missing (This happens when the pdf chapter is accessed first using the web reader) #3477
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixed
More details
When a user acccesses a PDF Chapter for the first time using the web reader, a corresponding cache directory is created containing only the pdf file. The pages are not extracted as png images into the cache directory.
If the user then requests a page from the same PDF Chapter using the OPDS controller/api, Kavita returns the error
No such image for page {0}. Try refreshing to allow re-cache.
.This happens because the OPDS controller expects the chapter's pages (png images) to already exist in the cache directory. It does not attempt to extract them from the PDF file if the directory exists.
This code change fixes the issues by recreating the chapter's cache directory if chapter's cache directory exists and the opds contoller doesn't find in it the requested page by the user.
(note : I'm not sure if this is the best way to handle this issue and I didn't look into how the fix behaves if the user tries to requests multiple pages in parallel)
Steps to reproduce
ReaderController#GetPdf
which callsCacheService#Ensure
withextractPdf=false
. A chapter directory is created containing the pdf files without extracting the pages as images.http://localhost:5000/api/opds/81235fbc-e77c-4ad5-b789-a0967beb3b6a/image?libraryId=1&seriesId=1&volumeId=1&chapterId=1&pageNumber=50
)OPDSController#GetPageStreamedImage
which callsCacheService#Ensure
withextractPdf=true
CacheService#Ensure
has no effect since the cache directory already existsNo such image for page {0}. Try refreshing to allow re-cache.