feat: add 悟空问答用户动态 (#5426)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
Ethan Shen 2020-08-19 04:21:54 +08:00 committed by GitHub
parent 020cef5e5b
commit 8d933537c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 0 deletions

View File

@ -887,6 +887,12 @@ rule
免费版账户抖音每天查询次数 20 次,如需增加次数可购买新榜会员或等待未来多账户支持
:::
## 悟空问答
### 用户动态
<Route author="nczitzk" example="/wukong/user/5826687196" path="/wukong/user/:id" :paramsDesc="['用户ID可在用户页 URL 中找到']"/>
## 知乎
### 收藏夹

View File

@ -3061,6 +3061,9 @@ router.get('/telecompaper/news/:caty/:year?/:country?/:type?/:keyword?', require
// 水木社区
router.get('/newsmth/account/:id', require('./routes/newsmth/account'));
// 悟空问答
router.get('/wukong/user/:id', require('./routes/wukong/user'));
// 腾讯大数据
router.get('/tencent/bigdata', require('./routes/tencent/bigdata/index'));

34
lib/routes/wukong/user.js Normal file
View File

@ -0,0 +1,34 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const userUrl = `https://www.wukong.com/wenda/web/my/brow/?count=20&other_uid=${ctx.params.id}`;
const dongtaiUrl = `https://www.wukong.com/wenda/web/dongtai/list/brow/?other_uid=${ctx.params.id}&count=15&max_time=&style=1`;
const response = await got({
method: 'get',
url: dongtaiUrl,
});
const userResponse = await got({
method: 'get',
url: userUrl,
});
const list = response.data.data.dongtai_list.map((item) => {
if (item.cell_id === 0) {
return Promise.resolve('');
}
const isQuestion = item.dongtai_cell.dongtai.OriginIdType === 1;
return {
title: `${item.dongtai_cell.dongtai.content.text}${item.dongtai_cell.dongtai.base.question.title}`,
link: isQuestion ? `https://www.wukong.com/question/${item.dongtai_cell.dongtai.base.question.qid}` : `https://www.wukong.com/answer/${item.dongtai_cell.dongtai.base.answer.ansid}`,
description: isQuestion ? item.dongtai_cell.dongtai.base.question.content.text : item.dongtai_cell.dongtai.base.answer.content,
pubDate: new Date((isQuestion ? item.dongtai_cell.dongtai.base.question.create_time : item.dongtai_cell.dongtai.base.answer.create_time) * 1000).toUTCString(),
};
});
ctx.state.data = {
title: `悟空问答 - ${userResponse.data.other_user_info.uname}`,
link: `https://www.wukong.com/user/?uid=${ctx.params.id}`,
item: list,
description: `${userResponse.data.other_user_info.description}`,
};
};