Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/anime.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 中找到']"/>
Expand Down
1 change: 1 addition & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2792,6 +2792,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'));
Expand Down
47 changes: 47 additions & 0 deletions lib/routes/agefans/update.js
Original file line number Diff line number Diff line change
@@ -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,
};
};