diff --git a/controllers/api.js b/controllers/api.js index bb1ed9c..dc75156 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -20,7 +20,7 @@ exports.searchBar = (req, res)=> exports.search = async (req, res)=> { if(!req.body?.searchstring) return res.sendStatus(404) - var data = await new Search(req.body.searchstring).search(); + var data = await new Search(req.body.searchstring).searchExtraInfo(); if(!Array.isArray(data)) return res.sendStatus(404); const favorites = await FavoriteModel.find() const favoriteScanlators = favorites.map(favorite => favorite.scanlator); @@ -109,13 +109,22 @@ exports.manga = async (req, res)=> const scanlatorHasTitle = await new Modules(scanlator).titleExists(title); if(!scanlatorHasTitle) return res.sendStatus(404); let manga; + let chaptersRead; try { - manga = await new Manga(scanlator,link, title).get() + manga = await new Manga(scanlator,link, title).get(); + chaptersRead = await ChapterModel.find({scanlator,title}); + for(let i = 0; i const {scanlator, title, chapter, link} = req.params; //IF its already there even with wrong things its there just show it const fileExists = fs.existsSync(`./public/Saved/${scanlator}/${title}/CH_${chapter}`); + if(fileExists) { const imgs =fs.readdirSync(`./public/Saved/${scanlator}/${title}/CH_${chapter}`); const latestChap = fs.readdirSync(`./public/Saved/${scanlator}/${title}`).length const List = imgs.map(filename => {return `./Saved/${scanlator}/${title}/CH_${chapter}/${filename}`}); const mangaLink = await new Chapter(scanlator, link, title, chapter).getMangaLink(); - return res.render('display.ejs', {data:{title,latestChap,scanlator, chapterNum:parseInt(chapter), mangaLink, List}}); + return res.render('chapterPage.ejs', {data:{title,latestChap,scanlator, chapterNum:parseInt(chapter), mangaLink, List}}); } //If it isn't make sure there is no bad params being passed const scanlatorExists = await new Modules(scanlator).exists(); @@ -147,7 +157,7 @@ exports.chapter = async (req, res)=> { return res.sendStatus(404); } - res.render('display.ejs', {data:{...manga, scanlator, chapterNum:parseInt(chapter)}}); + res.render('chapterPage.ejs', {data:{...manga, scanlator, chapterNum:parseInt(chapter)}}); } exports.favorites = async (req, res)=> @@ -401,20 +411,73 @@ exports.chapterRead = async (req, res)=> const scanlatorHasTitle = await new Modules(scanlator).titleExists(title); if(!scanlatorHasTitle) return res.sendStatus(404); const manga = await new Manga(scanlator, link, title).get(); - const {latestChap} = manga; + const {latestChap, List} = manga; if(chapter > latestChap || chapter < 0) return res.sendStatus(404); const chap = new ChapterModel(); let chapterNum = chapter; + let chapterLink = List.filter(item=>item.num == chapterNum)[0].link; + if(!chapterLink) return res.sendStatus(404); + const _chapter = await new Chapter(scanlator, chapterLink,title, chapter).get(); + let lastImageRead = _chapter.List[_chapter.List.length-1]; + chap.lastImageRead = lastImageRead; const chaps = await ChapterModel.find({scanlator, title, link, chapterNum}); - if(chaps.length>0) return res.sendStatus(404); + if(chaps.length>0) return updateChapter(chaps[0],res, lastImageRead, true) chap.scanlator = scanlator; chap.title = title; chap.link = link; chap.chapterNum = chapter; + chap.lastImageRead = lastImageRead; chap.completely = true; chap.save() res.sendStatus(200); - //Send to db; +} +async function updateChapter(chap, res, lastImageRead, completely=false) +{ + await ChapterModel.findOneAndUpdate(chap._id,{completely, lastImageRead:lastImageRead}, {new:true}); + res.sendStatus(200); +} +exports.chapterIncompleteRead = async (req,res)=> +{ + const {scanlator, title, chapter, link, img} = req.params; + const scanlatorExists = await new Modules(scanlator).exists(); + if(!scanlatorExists) return res.sendStatus(404); + const scanlatorHasTitle = await new Modules(scanlator).titleExists(title); + if(!scanlatorHasTitle) return res.sendStatus(404); + let chapterNum = chapter; + const manga = await new Manga(scanlator, link, title).get(); + const {latestChap, List} = manga; + let chapterLink = List.filter(item=> item.num == chapterNum)[0].link; + if(chapter > latestChap || chapter < 0) return res.sendStatus(404); + const chap = new ChapterModel(); + const _chapter = await new Chapter(scanlator, chapterLink,title, chapterNum).get(); + let lastImageRead = _chapter.List.filter(item=> + { + let parsedImageURL = item.split('.')[item.split('.').length-2].split('/')[item.split('.')[item.split('.').length-2].split('/').length-1] + return(parsedImageURL==img) + })[0]; + const chaps = await ChapterModel.find({scanlator, title, link, chapterNum}); + if(chaps.length>0) return updateChapter(chaps[0],res, lastImageRead) + chap.scanlator = scanlator; + chap.title = title; + chap.link = link; + chap.chapterNum = chapter; + chap.lastImageRead = lastImageRead; + chap.completely = false; + chap.save() + res.sendStatus(200); +} +exports.chapterLastRead = async (req, res)=> +{ + const {scanlator, title, chapter, link} = req.params; + const scanlatorExists = await new Modules(scanlator).exists(); + if(!scanlatorExists) return res.sendStatus(404); + const scanlatorHasTitle = await new Modules(scanlator).titleExists(title); + if(!scanlatorHasTitle) return res.sendStatus(404); + let chapterNum = chapter; + const chaps = await ChapterModel.find({scanlator, title, link, chapterNum}); + if(chaps.length == 0) return res.sendStatus(404); + let data = chaps[0].lastImageRead; + res.render('data.ejs', {data}); } exports.dashboard = async (req, res)=> { diff --git a/models/readChapter.js b/models/readChapter.js index ba77639..b9a10cf 100644 --- a/models/readChapter.js +++ b/models/readChapter.js @@ -8,7 +8,7 @@ new Schema( title: {type: String, required: true, max: 100}, link:{type: String, require:true, max:100}, chapterNum:{type: Number, require:true}, - lastImageRead:{type:Number, required:false}, + lastImageRead:{type:String, required:false}, completely:{type:Boolean, required:false} } ); diff --git a/public/css/home.css b/public/css/home.css index 7b23952..3de4cc9 100644 --- a/public/css/home.css +++ b/public/css/home.css @@ -353,6 +353,7 @@ button:hover margin-left: 1em; margin-right: 1em; margin-top: 1em; + min-height: 3.6em; } .card:hover > .card__img { @@ -463,12 +464,27 @@ button:hover text-decoration: none; color: var(--text); } - -.list > .chapterButton > a > h4 , .list > .chapterButton > a > h5 +.buttonWrapper +{ + display:flex; + flex-wrap: nowrap; + flex-direction: row; + align-items: center; + justify-content: center; + height:100% +} +.list > .chapterButton > a >.buttonWrapper > div > h4 , +.list > .chapterButton > a >.buttonWrapper > div > h5 +{ + margin: 0; +} +.readMarker { - /* margin-left: 0.6em; */ - margin-bottom: 0.1em; - margin-top: 0.1em; + height:auto; + width:auto; + color:var(--text); + position: relative; + left: 0.7em; } .infoCard > .infoText > .tags { diff --git a/routes/routes.js b/routes/routes.js index 381edbd..4dfb0b3 100644 --- a/routes/routes.js +++ b/routes/routes.js @@ -23,6 +23,7 @@ module.exports = (worker)=> router.route('/logout').get(api.logout); router.route('/chapterRead/:scanlator/:link/:title/:chapter/').post(api.chapterRead); router.route('/chapterRead/:scanlator/:link/:title/:chapter/:img').post(api.chapterIncompleteRead); + router.route('/chapterReadLastImage/:scanlator/:link/:title/:chapter/').get(api.chapterLastRead); //Undefined Routes v diff --git a/views/chapterButton.ejs b/views/chapterButton.ejs index a566728..535bb55 100644 --- a/views/chapterButton.ejs +++ b/views/chapterButton.ejs @@ -1,10 +1,20 @@
- -

- Chapter <%= chapter.num %> -

-
- <%= chapter.date %> -
+
+
+ <% if(chapter.Read){ %> + + beenhere + + <% } %> +
+

+ Chapter <%= chapter.num %> +

+
+ <%= chapter.date %> +
+
+
-
\ No newline at end of file + + \ No newline at end of file diff --git a/views/chapterPage.ejs b/views/chapterPage.ejs new file mode 100644 index 0000000..7f3ed76 --- /dev/null +++ b/views/chapterPage.ejs @@ -0,0 +1,28 @@ + + + + + + + Manga Reader + + + + + + + + +
+
+
+
+ <%- include('navBar.ejs', {data, selected:'none'}) %> +
+ <%- include('display.ejs', {data}) %> +
+
+ + + + diff --git a/views/data.ejs b/views/data.ejs new file mode 100644 index 0000000..214f1e5 --- /dev/null +++ b/views/data.ejs @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/views/display.ejs b/views/display.ejs index 3ec4709..c848beb 100644 --- a/views/display.ejs +++ b/views/display.ejs @@ -2,10 +2,10 @@
<% for(var [index, img] of data.List.entries()){ %> - onclick="_scrollTo('<%= '_img'+index%>')" /> + onclick="_scrollTo('<%= '_img'+index%>')" /> <% } %>
-
+
chevron_right
@@ -24,7 +24,7 @@
<% for(var [index, img] of data.List.entries()){ %> - alt="img<%= index %>"/> + alt="img<%= index %>"/> <% } %>
+
+
\ No newline at end of file