fix(route): 爱下电子书 axdzs (#8738)

This commit is contained in:
Xiang Li 2022-01-22 10:17:11 -08:00 committed by GitHub
parent d7d0b153d9
commit b4feea696f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 13 deletions

View File

@ -109,7 +109,7 @@ pageClass: routes
### 最新章节
<Route author="JeasonLau" example="/axdzs/191/191976" path="/axdzs/:id1/:id2" :paramsDesc="['小说网站链接倒数第二部分的数字, 可在对应小说页 URL 中找到', '小说网站链接最后的数字, 可在对应小说页 URL 中找到']" />
<Route author="JeasonLau Maecenas" example="/axdzs/诡秘之主" path="/axdzs/:novel" :paramsDesc="['小说的中文名, 可在对应小说页 URL 中找到']" />
## 笔趣阁

View File

@ -2599,6 +2599,8 @@ router.get('/ifeng/feng/:id/:type', lazyloadRouteHandler('./routes/ifeng/feng'))
router.get('/novel/d1bz/:category/:id', lazyloadRouteHandler('./routes/d1bz/novel'));
// 爱下电子书
router.get('/axdzs/:novel', lazyloadRouteHandler('./routes/novel/axdzs'));
// deprecated
router.get('/axdzs/:id1/:id2', lazyloadRouteHandler('./routes/novel/axdzs'));
// HackerOne

View File

@ -1,16 +1,22 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const baseUrl = 'https://read.aixdzs.com/';
const baseUrl = 'https://www.aixdzs.com';
module.exports = async (ctx) => {
const id1 = ctx.params.id1;
const id2 = ctx.params.id2;
const novelUrl = `${baseUrl}${id1}/${id2}/`;
const response = await got({
method: 'get',
url: novelUrl,
});
if (ctx.params.id2) {
const redirect = await got.head(`https://read.aixdzs.com/${ctx.params.id1}/${ctx.params.id2}/`, { followRedirect: false });
const redirectUrl = redirect.headers.location;
const novel = redirectUrl.substring(1 + redirectUrl.lastIndexOf('/'));
ctx.status = 301;
ctx.redirect(`/axdzs/${novel}`);
return;
}
const novel = ctx.params.novel;
const novelUrl = `${baseUrl}/novel/${novel}/`;
const response = await got.get(novelUrl);
const data = response.data;
const $ = cheerio.load(data);
@ -19,11 +25,15 @@ module.exports = async (ctx) => {
const description = $('meta[name="description"]').attr('content');
const lastChapter = $('.chapter').last().children();
const secondChapter = $('.chapter').last().prev().children();
const lastChapterUrl = novelUrl + lastChapter.attr('href');
const secondChapterUrl = novelUrl + secondChapter.attr('href');
let lastChapterUrl = lastChapter.attr('href');
let secondChapterUrl = secondChapter.attr('href');
if (lastChapterUrl.startsWith('/')) {
lastChapterUrl = baseUrl + lastChapterUrl;
secondChapterUrl = baseUrl + secondChapterUrl;
}
const lastChapterContent = await ctx.cache.tryGet(lastChapterUrl, async () => {
const lastChapter = await got.get(lastChapterUrl);
const $ = cheerio.load(lastChapter.data, { decodeEntities: false });
const res = await got.get(lastChapterUrl);
const $ = cheerio.load(res.data, { decodeEntities: false });
return $('.content').html();
});
// 以下需要判断最新章节是否已填充内容