mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-31 20:24:27 -04:00
Fixed an off by 1 issue with reading manga.
This commit is contained in:
parent
a6b49052b9
commit
9a50241734
@ -34,12 +34,22 @@ namespace API.Controllers
|
|||||||
var chapter = await _cacheService.Ensure(chapterId);
|
var chapter = await _cacheService.Ensure(chapterId);
|
||||||
|
|
||||||
if (chapter == null) return BadRequest("There was an issue finding image file for reading");
|
if (chapter == null) return BadRequest("There was an issue finding image file for reading");
|
||||||
|
|
||||||
|
// TODO: This code works, but might need bounds checking. UI can send bad data
|
||||||
|
// if (page >= chapter.Pages)
|
||||||
|
// {
|
||||||
|
// page = chapter.Pages - 1;
|
||||||
|
// } else if (page < 0)
|
||||||
|
// {
|
||||||
|
// page = 0;
|
||||||
|
// }
|
||||||
|
|
||||||
var (path, mangaFile) = await _cacheService.GetCachedPagePath(chapter, page);
|
var (path, mangaFile) = await _cacheService.GetCachedPagePath(chapter, page);
|
||||||
if (string.IsNullOrEmpty(path)) return BadRequest($"No such image for page {page}");
|
if (string.IsNullOrEmpty(path)) return BadRequest($"No such image for page {page}");
|
||||||
var file = await _directoryService.ReadImageAsync(path);
|
var file = await _directoryService.ReadImageAsync(path);
|
||||||
file.Page = page;
|
file.Page = page;
|
||||||
file.MangaFileName = mangaFile.FilePath;
|
file.MangaFileName = mangaFile.FilePath;
|
||||||
|
file.NeedsSplitting = file.Width > file.Height;
|
||||||
|
|
||||||
return Ok(file);
|
return Ok(file);
|
||||||
}
|
}
|
||||||
|
@ -106,12 +106,18 @@ namespace API.Services
|
|||||||
var chapterFiles = chapter.Files ?? await _unitOfWork.VolumeRepository.GetFilesForChapter(chapter.Id);
|
var chapterFiles = chapter.Files ?? await _unitOfWork.VolumeRepository.GetFilesForChapter(chapter.Id);
|
||||||
foreach (var mangaFile in chapterFiles)
|
foreach (var mangaFile in chapterFiles)
|
||||||
{
|
{
|
||||||
if (page < (mangaFile.NumberOfPages + pagesSoFar))
|
if (page <= (mangaFile.NumberOfPages + pagesSoFar))
|
||||||
{
|
{
|
||||||
var path = GetCachePath(chapter.Id);
|
var path = GetCachePath(chapter.Id);
|
||||||
var files = _directoryService.GetFiles(path, Parser.Parser.ImageFileExtensions);
|
var files = _directoryService.GetFiles(path, Parser.Parser.ImageFileExtensions);
|
||||||
Array.Sort(files, _numericComparer);
|
Array.Sort(files, _numericComparer);
|
||||||
|
|
||||||
|
// Since array is 0 based, we need to keep that in account (only affects last image)
|
||||||
|
if (page - 1 == files.Length)
|
||||||
|
{
|
||||||
|
return (files.ElementAt(page - 1 - pagesSoFar), mangaFile);
|
||||||
|
}
|
||||||
|
|
||||||
return (files.ElementAt(page - pagesSoFar), mangaFile);
|
return (files.ElementAt(page - pagesSoFar), mangaFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user