This commit is contained in:
Michael DiLeo 2025-07-06 17:54:19 +10:00 committed by GitHub
commit d28321bb1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 134 additions and 13 deletions

View file

@ -103,9 +103,16 @@ public class BookController : BaseApiController
if (chapter == null) return BadRequest(await _localizationService.Get("en", "chapter-doesnt-exist"));
using var book = await EpubReader.OpenBookAsync(chapter.Files.ElementAt(0).FilePath, BookService.LenientBookReaderOptions);
var key = BookService.CoalesceKeyForAnyFile(book, file);
if (!book.Content.AllFiles.ContainsLocalFileRefWithKey(key)) return BadRequest(await _localizationService.Get("en", "file-missing"));
var key = BookService.CoalesceKeyForAnyFile(book, file);
if (!book.Content.AllFiles.ContainsLocalFileRefWithKey(key))
{
// the first attempt looks for the image directly, assuming no nesting.
// this attempt appends the chapter id in the front in case there are multiple chapters.
key = BookService.CoalesceKeyForChapterFile(book, chapterId, file);
if (!book.Content.AllFiles.ContainsLocalFileRefWithKey(key))
return BadRequest(await _localizationService.Get("en", "file-missing"));
}
var bookFile = book.Content.AllFiles.GetLocalFileRefByKey(key);
var content = await bookFile.ReadContentAsBytesAsync();