feat: add 悟空问答用户回答 & 用户提问 (#5461)
This commit is contained in:
parent
0da7051539
commit
c02040bf58
|
|
@ -863,7 +863,17 @@ rule
|
|||
|
||||
### 用户动态
|
||||
|
||||
<Route author="nczitzk" example="/wukong/user/5826687196" path="/wukong/user/:id" :paramsDesc="['用户ID,可在用户页 URL 中找到']"/>
|
||||
<Route author="nczitzk" example="/wukong/user/5826687196" path="/wukong/user/:id/:type?" :paramsDesc="['用户ID,可在用户页 URL 中找到', '类型,可选 `dongtai` 即 动态,`answers` 即 回答,`questions` 即 提问,默认为 `dongtai`']">
|
||||
|
||||
::: tip 注意
|
||||
|
||||
用户的动态是一定时间范围内用户提出的问题和作出的回答,距离现在时间较久的问题和回答不会出现,此时选择 `dongtai` 用户动态是会缺失的。
|
||||
|
||||
同理选择 `answers` 和 `questions` 作为参数时,对于没有提出过问题和作出过回答的用户,其内容也会相应缺失。
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
## 小红书
|
||||
|
||||
|
|
|
|||
|
|
@ -3070,7 +3070,7 @@ router.get('/medsci/recommend', require('./routes/medsci/recommend'));
|
|||
router.get('/wallpaperhub', require('./routes/wallpaperhub/index'));
|
||||
|
||||
// 悟空问答
|
||||
router.get('/wukong/user/:id', require('./routes/wukong/user'));
|
||||
router.get('/wukong/user/:id/:type?', require('./routes/wukong/user'));
|
||||
|
||||
// 腾讯大数据
|
||||
router.get('/tencent/bigdata', require('./routes/tencent/bigdata/index'));
|
||||
|
|
|
|||
|
|
@ -1,33 +1,92 @@
|
|||
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 rootUrl = 'https://www.wukong.com/wenda/web';
|
||||
const userUrl = `${rootUrl}/my/brow/?count=20&other_uid=${ctx.params.id}`;
|
||||
const dongtaiUrl = `${rootUrl}/dongtai/list/brow/?other_uid=${ctx.params.id}&count=15&max_time=&style=1`;
|
||||
const answerUrl = `${rootUrl}/my/brow/?count=15&t=${new Date().getTime()}&other_uid=${ctx.params.id}`;
|
||||
const questionUrl = `${rootUrl}/myquestion/brow/?count=15&t=${new Date().getTime()}&offset=0&other_uid=${ctx.params.id}`;
|
||||
|
||||
let number = '';
|
||||
let currentUrl = '';
|
||||
const type = ctx.params.type || 'dongtai';
|
||||
|
||||
switch (type) {
|
||||
case 'dongtai':
|
||||
number = '2';
|
||||
currentUrl = dongtaiUrl;
|
||||
break;
|
||||
case 'answers':
|
||||
number = '0';
|
||||
currentUrl = answerUrl;
|
||||
break;
|
||||
case 'questions':
|
||||
number = '1';
|
||||
currentUrl = questionUrl;
|
||||
break;
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: dongtaiUrl,
|
||||
url: currentUrl,
|
||||
});
|
||||
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('');
|
||||
let data = '';
|
||||
|
||||
switch (type) {
|
||||
case 'dongtai':
|
||||
data = response.data.data.dongtai_list;
|
||||
break;
|
||||
case 'answers':
|
||||
data = response.data.data.feed_question;
|
||||
break;
|
||||
case 'questions':
|
||||
data = response.data.question_list;
|
||||
break;
|
||||
}
|
||||
|
||||
const list = data.map((item) => {
|
||||
switch (type) {
|
||||
case 'dongtai': {
|
||||
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(),
|
||||
};
|
||||
}
|
||||
case 'answers': {
|
||||
return {
|
||||
title: `${item.question.title}`,
|
||||
link: `https://www.wukong.com/answer/${item.ans_list[0].ansid}`,
|
||||
description: item.ans_list[0].content,
|
||||
pubDate: new Date(item.ans_list[0].create_time * 1000).toUTCString(),
|
||||
};
|
||||
}
|
||||
case 'questions': {
|
||||
return {
|
||||
title: `${item.title}`,
|
||||
link: `https://www.wukong.com/question/${item.qid}`,
|
||||
description: item.content.text,
|
||||
pubDate: new Date(item.create_time * 1000).toUTCString(),
|
||||
};
|
||||
}
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
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}`,
|
||||
link: `https://www.wukong.com/user/?uid=${ctx.params.id}&type=${number}`,
|
||||
item: list,
|
||||
description: `${userResponse.data.other_user_info.description}`,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue