From b0031d1041d889954acdaf950705fb26bfff7dec Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 25 May 2021 21:18:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20AGE=E5=8A=A8=E6=BC=AB=E6=9C=80?= =?UTF-8?q?=E8=BF=91=E6=9B=B4=E6=96=B0=20(#7145)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/anime.md | 4 +++ lib/router.js | 1 + lib/routes/agefans/update.js | 47 ++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 lib/routes/agefans/update.js diff --git a/docs/anime.md b/docs/anime.md index bedc0fc2707034..911ce7310e14d3 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -35,6 +35,10 @@ pageClass: routes ## AGE 动漫 +### 最近更新 + + + ### 番剧详情 diff --git a/lib/router.js b/lib/router.js index 9bf400d3ffdab8..b17bec9bce1b08 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2799,6 +2799,7 @@ router.get('/swjtu/tl/news', require('./routes/swjtu/tl/news')); // AGE动漫 router.get('/agefans/detail/:id', require('./routes/agefans/detail')); +router.get('/agefans/update', require('./routes/agefans/update')); // Checkra1n router.get('/checkra1n/releases', require('./routes/checkra1n/releases')); diff --git a/lib/routes/agefans/update.js b/lib/routes/agefans/update.js new file mode 100644 index 00000000000000..b062210ff06b98 --- /dev/null +++ b/lib/routes/agefans/update.js @@ -0,0 +1,47 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.agefans.net'; + const currentUrl = `${rootUrl}/update`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.anime_icon2_name a') + .slice(0, 15) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('.div_left').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};