feat: add 8btc (#2462)
* feat: add 8btc * feat: add 8btc * feat: add 8btc * Update other.md
This commit is contained in:
parent
57da1ea463
commit
990dac8eee
|
|
@ -271,6 +271,12 @@ type 为 all 时,category 参数不支持 cost 和 free
|
|||
|
||||
<Route author="brilon" example="/iresearch/report" path="/iresearch/report"/>
|
||||
|
||||
## 巴比特
|
||||
|
||||
### 作者专栏
|
||||
|
||||
<Route author="kt286" example="/8btc/45703" path="/8btc/:authorid" :paramsDesc="['作者ID,可在对应专辑页面的 URL 中找到']"/>
|
||||
|
||||
## 百度
|
||||
|
||||
### 百度趣画
|
||||
|
|
|
|||
|
|
@ -1427,4 +1427,7 @@ router.get('/aiyanxishe/:id/:sort?', require('./routes/aiyanxishe/home'));
|
|||
// 飞客茶馆优惠信息
|
||||
router.get('/flyertea/preferential', require('./routes/flyertea/preferential'));
|
||||
|
||||
// 巴比特作者专栏
|
||||
router.get('/8btc/:authorid', require('./routes/8btc/author'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const authorid = ctx.params.authorid;
|
||||
const response = await got.get(`https://webapi.8btc.com/bbt_api/comments/list?author_id=${authorid}&fetch_num=20`);
|
||||
|
||||
const ProcessFeed = (data) => {
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
$('img').each((index, elem) => {
|
||||
const $elem = $(elem);
|
||||
$elem.attr('referrerpolicy', 'no-referrer');
|
||||
});
|
||||
|
||||
// 提取内容
|
||||
return $('.bbt-html').html();
|
||||
};
|
||||
|
||||
const items = await Promise.all(
|
||||
response.data.data.list.map(async (item) => {
|
||||
const link = `https://www.8btc.com/article/${item.post_id}`;
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
|
||||
const description = ProcessFeed(response.data);
|
||||
|
||||
const single = {
|
||||
title: item.post.title,
|
||||
description,
|
||||
pubDate: item.date_gmt,
|
||||
link: link,
|
||||
author: item.reviewer.name,
|
||||
};
|
||||
ctx.cache.set(link, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '巴比特作者专栏',
|
||||
link: `https://www.8btc.com/author/${authorid}`,
|
||||
description: '巴比特作者专栏',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue