Adds support for multiple chapters. The previous version ignored any leading chapter numbers in the uri of {chapterId}/images/{image}. It now accounts for that and is working in a locally run user interface for an epub that was broken. I didn't check in the unit test over the GetBookPage method since it requires a specific file. I'll provide that in the PR description, though.
This commit is contained in:
parent
8ed2fa3829
commit
4ca4723ae9
4 changed files with 134 additions and 13 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue