Fixed no next chapter issue. If it couldn't find a next chapter it would crash the backend

master
masterhc 10 months ago
parent 7c67c5b122
commit 6078e8efa2

3
.gitignore vendored

@ -1,3 +1,4 @@
node_modules
Saved
.vscode
.vscode
.env

@ -120,7 +120,7 @@ exports.manga = async (req, res)=>
}
}
}
const filteredArray = chaptersRead.filter(item => item.completely == true);
const filteredArray = chaptersRead.length>0?chaptersRead.filter(item => item.completely == true):chaptersRead;
filteredArray.sort((a, b) => a.chapterNum - b.chapterNum);
const lastCompletelyRead = filteredArray.pop();
const sortedChapters = chaptersRead.sort((a, b) => a.chapterNum - b.chapterNum);
@ -128,11 +128,14 @@ exports.manga = async (req, res)=>
const lastChapterWithReadImages=sortedAndFilteredChapters.shift();
let chapterNumToContinue = getChapterNumToContinue(lastCompletelyRead, lastChapterWithReadImages, manga.List);
if(!manga.List.some(item=> item.num==chapterNumToContinue)) chapterNumToContinue = Math.trunc(chapterNumToContinue);
let index = manga.List.indexOf(manga.List.filter(item=>
{
return item.num == chapterNumToContinue
})[0]);
manga.List[index]['continue'] = true;
if(lastCompletelyRead || lastChapterWithReadImages)
{
let index = manga.List.indexOf(manga.List.filter(item=>
{
return item.num == chapterNumToContinue
})[0]);
manga.List[index]['continue'] = true;
}
}
catch (error)
{
@ -140,8 +143,16 @@ exports.manga = async (req, res)=>
}
res.render('mangaPage.ejs', {data:{...manga, scanlator}});
}
/**
*
* @param {Chapter} lastCompletelyRead
* @param {Chapter} lastChapterWithReadImages
* @param {ChapterList} List
* @returns {Nyumber}
*/
function getChapterNumToContinue(lastCompletelyRead, lastChapterWithReadImages, List)
{
if(!lastCompletelyRead && !lastChapterWithReadImages) return List[0].num;
const firstIndex = List.indexOf(List.filter(item=>item.num == lastCompletelyRead.chapterNum)[0]);
if(lastCompletelyRead)
{

Loading…
Cancel
Save