From d3a326bbd9c1dc4de24b1fe14575df6882b34e46 Mon Sep 17 00:00:00 2001 From: masterhc Date: Sun, 21 Apr 2024 15:09:31 +0100 Subject: [PATCH] Fix: chapterToContinue must be the next chapter if the completely read is the highest value --- controllers/api.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/controllers/api.js b/controllers/api.js index 05f9940..e458745 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -131,7 +131,7 @@ exports.manga = async (req, res)=> const sortedChapters = chaptersRead.sort((a, b) => a.chapterNum - b.chapterNum); const sortedAndFilteredChapters = sortedChapters.filter(item=> item.lastImageRead && !item.completely); const lastChapterWithReadImages=sortedAndFilteredChapters.shift(); - const chapterNumToContinue = lastCompletelyRead?(lastCompletelyRead.chapterNum < lastChapterWithReadImages.chapterNum ? lastChapterWithReadImages.chapterNum:lastCompletelyRead.chapterNum):lastChapterWithReadImages.chapterNum; + const chapterNumToContinue = getChapterNumToContinue(lastCompletelyRead, lastChapterWithReadImages); manga.List[chapterNumToContinue-1]['continue'] = true; } catch (error) @@ -139,8 +139,20 @@ exports.manga = async (req, res)=> console.log('There was an error:', error); } res.render('mangaPage.ejs', {data:{...manga, scanlator}}); - } +function getChapterNumToContinue(lastCompletelyRead, lastChapterWithReadImages) +{ + if(lastCompletelyRead) + { + if(lastCompletelyRead.chapterNum < lastChapterWithReadImages.chapterNum) + { + return lastChapterWithReadImages.chapterNum; + } + return lastCompletelyRead.chapterNum+1; + } + return lastChapterWithReadImages.chapterNum; +} + exports.chapter = async (req, res)=> { const {scanlator, title, chapter, link} = req.params;