diff --git a/docs/reading.md b/docs/reading.md index 701344bed..04c3288c7 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -109,7 +109,7 @@ pageClass: routes ### 最新章节 - + ## 笔趣阁 diff --git a/lib/router.js b/lib/router.js index 32a68b554..c7e46a966 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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 diff --git a/lib/routes/novel/axdzs.js b/lib/routes/novel/axdzs.js index 07fc76b7d..1bf9ab422 100644 --- a/lib/routes/novel/axdzs.js +++ b/lib/routes/novel/axdzs.js @@ -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(); }); // 以下需要判断最新章节是否已填充内容