|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
const {Search, Chapter, Manga,SearchByTag, isValidID, Modules, Baker, Crypto, cookieParser} = require('../lib.js')
|
|
|
|
|
const mongoose = require('mongoose')
|
|
|
|
|
const FavoriteModel = require('../models/favorite.js');
|
|
|
|
|
const ChapterModel = require('../models/readChapter.js');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
const path = require('path');
|
|
|
|
|
const { isNullOrUndefined } = require('util');
|
|
|
|
@ -394,7 +395,24 @@ exports.errorPage = (req, res)=>
|
|
|
|
|
|
|
|
|
|
exports.chapterRead = async (req, res)=>
|
|
|
|
|
{
|
|
|
|
|
console.log('ChapterRead')
|
|
|
|
|
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);
|
|
|
|
|
const manga = await new Manga(scanlator, link, title).get();
|
|
|
|
|
const {latestChap} = manga;
|
|
|
|
|
if(chapter > latestChap || chapter < 0) return res.sendStatus(404);
|
|
|
|
|
const chap = new ChapterModel();
|
|
|
|
|
let chapterNum = chapter;
|
|
|
|
|
const chaps = await ChapterModel.find({scanlator, title, link, chapterNum});
|
|
|
|
|
if(chaps.length>0) return res.sendStatus(404);
|
|
|
|
|
chap.scanlator = scanlator;
|
|
|
|
|
chap.title = title;
|
|
|
|
|
chap.link = link;
|
|
|
|
|
chap.chapterNum = chapter;
|
|
|
|
|
chap.completely = true;
|
|
|
|
|
chap.save()
|
|
|
|
|
res.sendStatus(200);
|
|
|
|
|
//Send to db;
|
|
|
|
|
}
|
|
|
|
|