66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
const { http, utils, db, config,router } = require("../../_");
|
||
|
||
/**
|
||
* 小说详情页面
|
||
* 地址:http://127.0.0.1:3000/api/json/1.0/info?id=28/28039/
|
||
*/
|
||
router.get('/info', async (req, res, next) => {
|
||
let id = req.query.id,
|
||
action = req.query.action == undefined ? null: req.query.action,
|
||
InfoData = {};
|
||
|
||
try {
|
||
let $ = utils.returnDOM(await http.get({ url: `${config.TargetUrl.baseUrl}${id}` }));
|
||
|
||
InfoData.title = $("#info").find("h1").text()
|
||
InfoData.author = $("#info p").eq(0).text()
|
||
InfoData.updateTime = $("#info p").eq(2).text()
|
||
InfoData.imgUrl = $("#fmimg img").attr("src")
|
||
InfoData.introduce = $("#intro p").eq(1).text()
|
||
InfoData.oldChapter = []
|
||
|
||
let father = $("#list dl dd a");
|
||
father.each(function (item) {
|
||
InfoData.oldChapter.push({
|
||
chapterTitle: $(this).text(),
|
||
chapterUrl: $(this).attr("href"),
|
||
})
|
||
})
|
||
|
||
if(action == null) {
|
||
InfoData.newChapter = {}
|
||
InfoData.newChapter.newTitle = $("#info p").eq(3).find("a").text()
|
||
InfoData.newChapter.newUrl = $("#info p").eq(3).find("a").attr("href")
|
||
|
||
utils.returnJson(200,InfoData,res)
|
||
} else {
|
||
res.json(InfoData)
|
||
}
|
||
|
||
|
||
|
||
}catch (e) {
|
||
console.log(e)
|
||
}
|
||
})
|
||
|
||
/**
|
||
* 阅读小说接口
|
||
* 地址:http://127.0.0.1:3000/api/json/1.0/read?id=/28/28039/13633573.html
|
||
*/
|
||
router.get('/read', async (req, res, next) => {
|
||
let id = req.query.id;
|
||
try {
|
||
let $ = utils.returnDOM(await http.get({ url: `${config.TargetUrl.baseUrl}${id}` }));
|
||
utils.returnJson(200,{
|
||
title: $(".bookname h1").text(),
|
||
content: (unescape($("#content").html().replace(/&#x/g,'%u').replace(/;/g,''))).replace(/%uA0%uA0%uA0%uA0|\n/gi,' ')
|
||
},res)
|
||
|
||
}catch (e) {
|
||
console.log(e)
|
||
}
|
||
|
||
|
||
})
|
||
module.exports = router |