From c02040bf5862f21e81d761fe8610f08c6d76fced Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Fri, 21 Aug 2020 05:07:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E6=82=9F=E7=A9=BA=E9=97=AE?= =?UTF-8?q?=E7=AD=94=E7=94=A8=E6=88=B7=E5=9B=9E=E7=AD=94=20&=20=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=8F=90=E9=97=AE=20(#5461)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/social-media.md | 12 +++++- lib/router.js | 2 +- lib/routes/wukong/user.js | 87 ++++++++++++++++++++++++++++++++------- 3 files changed, 85 insertions(+), 16 deletions(-) diff --git a/docs/social-media.md b/docs/social-media.md index d54d75a2c..628c980c0 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -863,7 +863,17 @@ rule ### 用户动态 - + + +::: tip 注意 + +用户的动态是一定时间范围内用户提出的问题和作出的回答,距离现在时间较久的问题和回答不会出现,此时选择 `dongtai` 用户动态是会缺失的。 + +同理选择 `answers` 和 `questions` 作为参数时,对于没有提出过问题和作出过回答的用户,其内容也会相应缺失。 + +::: + + ## 小红书 diff --git a/lib/router.js b/lib/router.js index 1e61f27db..43a3bdbf0 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/wukong/user.js b/lib/routes/wukong/user.js index 82735bb48..07e56356b 100644 --- a/lib/routes/wukong/user.js +++ b/lib/routes/wukong/user.js @@ -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}`, };