add 小黑盒 (#1445)

close #1435
This commit is contained in:
Chenyang Shi
2019-01-23 11:00:01 +08:00
committed by DIYgod
parent 96ff2b7dbe
commit f46df357ef
3 changed files with 47 additions and 0 deletions
+4
View File
@@ -2309,6 +2309,10 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
<route name="Steam news" author="maple3142" example="/steam/news/282800" path="/steam/news/:appids" :paramsDesc="['游戏 id']"/>
### 小黑盒
<route name="用户动态" author="LogicJake" example="/xiaoheihe/user/7775687" path="xiaoheihe/user/:id" :paramsDesc="['用户 id']"/>
## 小说·文学·阅读
### 观止(每日一文)
+3
View File
@@ -1001,4 +1001,7 @@ router.get('/duozhuayu/search/:wd', require('./routes/duozhuayu/search'));
// 创业邦
router.get('/cyzone/author/:id', require('./routes/cyzone/author'));
// 小黑盒
router.get('/xiaoheihe/user/:id', require('./routes/xiaoheihe/user'));
module.exports = router;
+40
View File
@@ -0,0 +1,40 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;
const response = await axios({
method: 'get',
url: `https://api.xiaoheihe.cn/bbs/web/profile/post/links?userid=${id}&limit=10&offset=0&version=999.0.0`,
});
const user_data = response.data.user;
const post_data = response.data.post_links;
const user_name = user_data.username;
const out = await Promise.all(
post_data.map(async (post) => {
const title = post.description;
const date = post.create_at;
const itemUrl = `https://xiaoheihe.cn/community/7216/list/${post.linkid}`;
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const description = $('.post-content').html();
const single = {
title: title,
link: itemUrl,
description: description,
pubDate: new Date(date * 1000).toUTCString(),
};
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `${user_name}的动态`,
link: `https://xiaoheihe.cn/community/user/${id}/post_list`,
item: out,
};
};