feat(route): AGE动漫最近更新 (#7145)

This commit is contained in:
Ethan Shen 2021-05-25 21:18:26 +08:00 committed by GitHub
parent ec35396bf1
commit b0031d1041
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 0 deletions

View File

@ -35,6 +35,10 @@ pageClass: routes
## AGE 动漫
### 最近更新
<Route author="nczitzk" example="/agefans/update" path="/agefans/update"/>
### 番剧详情
<Route author="s2marine" example="/agefans/detail/20200035" path="/agefans/detail/:id" :paramsDesc="['番剧 id对应详情 URL 中找到']"/>

View File

@ -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'));

View File

@ -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,
};
};