first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
const { http, utils, db, config,router } = require("../../_");
// http://127.0.0.1:3000/api/json/1.0/class?class=1&page=1
router.get('/class', async function(req,res,next){
// 请求数据 and 返回dom数据
let $ = await utils.AnalyticalData({ class:req.query.class, page: req.query.page } ),
left = [],
father = null;
/**
* 存在 action 爬取每个分类下面的更多小说
*/
if(req.query.hasOwnProperty("action")){
// http://127.0.0.1:3000/api/json/1.0/class?class=2&page=1&action=more
father = $("#newscontent .l ul li")
father.each(function(){
left.push({
title: $(this).find(".s2 a").text(),
url: $(this).find(".s2 a").attr("href")
})
})
let newList = []
left.forEach(async (item) => {
let $ = await utils.AnalyticalData({ siteUrl: item.url } )
newList.push({
title: $('#maininfo #info').find('h1').text(),
imgURL: $('#sidebar #fmimg').find('img').attr('src'),
introduce: $('#maininfo #intro').children().last().text(),
author: ($('#maininfo #info').find('h1+p').text()).substring(7),
url: item.url
})
if(newList.length == 30) {
return res.json(newList)
}
})
/**
* 不存在 action 爬取每个分类小面的推荐小说
*/
} else {
// http://127.0.0.1:3000/api/json/1.0/class?class=2
father = $("#hotcontent .ll .item")
father.each(async function() {
left.push({
title: $(this).find("dl dt a").text(),
imgURL: $(this).find(".image img").attr("src"),
author: $(this).find("dl dt span").text(),
introduce: $(this).find("dl dd").text(),
url: $(this).find(".image a").attr("href")
})
})
return res.json(left)
}
})
module.exports = router

View File

@@ -0,0 +1,8 @@
const { http, utils, db, config,router } = require("../../_");
router.get('/index', async function(req, res, next) {
console.log('index');
})
module.exports = router

View File

@@ -0,0 +1,66 @@
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

View File

@@ -0,0 +1,83 @@
const { http, utils, db, config,router,md5 } = require("../../_");
/**
* 检查用户是否已经添加过某本小说
*/
router.post('/user/checkbook', async function (req, res, next) {
let userid = req.body.userid,
bookid = req.body.bookid;
let Check = await db.Query({ sql: config.sql.user.checkBook, par: [ userid, bookid ] });
if(Check.length) {
utils.returnJson(200,"已收藏",res);
}else {
utils.returnJson(200,"未收藏",res);
}
});
/**
* 用户添加小说到书架
*/
router.post('/user/addbok', async function (req, res, next) {
let userid = req.body.userid,
bookid = req.body.bookid;
let add = await db.Query({ sql: config.sql.user.insertBook, par: [ userid, bookid ] });
if(add.message.length == 0) {
utils.returnJson(200,"添加成功",res);
}else {
utils.returnJson(404,"添加失败",res);
}
})
/**
* 获取用户书架中收藏的书
* http://127.0.0.1:3000/api/json/1.0/user/getbook?userid=1
*/
router.get('/user/getbook', async function (req, res, next) {
let userid = req.query.userid;
let getBook = await db.Query({ sql: config.sql.user.selectBook, par: [ userid ] }),
infoData = [],
keys = 0;
if(getBook.length ==0) {
utils.returnJson(404,"数据没有数据",res);
}else {
getBook.forEach(async (value , index) => {
infoData.push(await http.get({ url: `http://127.0.0.1:3000/api/json/1.0/info?action=back&id=${value.collection_bookid}` }));
infoData[keys].bookid = value.collection_bookid
keys++;
if(keys == getBook.length) {
utils.returnJson(200,infoData,res);
}
})
}
})
/**
* 获取用户书架中收藏的书
* http://127.0.0.1:3000/api/json/1.0/user/deletebook?uid=1&bid=26/26966/
*/
router.get('/user/deletebook', async function (req, res, next) {
let userid = req.query.uid,
bookid = req.query.bid;
let delbook = await db.Query({ sql: config.sql.user.deleteBook, par: [ userid, bookid ] });
if(delbook.message.length == 0) {
utils.returnJson(200,"删除成功",res);
}else {
utils.returnJson(404,"删除失败",res);
}
})
module.exports = router

View File

@@ -0,0 +1,65 @@
const { http, utils, db, config,router,md5 } = require("../../_");
/**
* 用户登录
*/
router.post('/user/login', async function (req, res, next) {
let UserName = req.body.name,
UserPwd = req.body.pwd,
IP = req.body.ip;
let UserInfo = await db.Query({ sql: config.sql.user.login, par: [ UserName, md5(UserPwd) ] });
if(UserInfo.length) {
req.session.userinfo = UserInfo;
utils.returnJson(200,UserInfo[0],res);
}else {
utils.returnJson(404,'账号和密码不匹配',res)
}
});
/**
* 注册账户
*/
router.post('/user/reg', async (req, res, next) => {
let userName = req.body.name,
UserPwd = req.body.pwd;
if(/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(userName)) {
if( (await db.Query({ sql: config.sql.user.checkUser, par: [userName] })).length ) {
utils.returnJson(404,'手机号已存在',res)
}else {
let userReg = await db.Query({ sql: config.sql.user.userReg, par: [userName, md5(UserPwd), await utils.GetIp()] })
req.session.userinfo = await db.Query({ sql: config.sql.user.getUserInfo, par: [userReg.insertId] })
utils.returnJson(200,'regSuccess',res)
}
}else {
utils.returnJson(404,'手机号格式不正确',res)
}
});
/**
* 退出登录
*/
router.post('/user/outLogin', async (req, res, next) => {
});
/**
* 检查用户是否登录 前端检查 + 后端session检查
*/
router.get('/user/checkLogin', async (req, res, next) => {
console.log(req.session.userinfo)
// if(req.session.userinfo.length) {
// utils.returnJson(200,'Logined',res)
// }else {
// utils.returnJson(404,'noLogin',res)
// }
});
/**
* 重置密码
*/
router.post('/user/restPwd', async (req, res, next) => {
});
module.exports = router