Skip to content

Commit

Permalink
feat(route): AGE动漫最近更新 (DIYgod#7145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Shen authored May 25, 2021
1 parent ec35396 commit b0031d1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
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 @@ -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'));
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,
};
};

0 comments on commit b0031d1

Please sign in to comment.