diff --git a/docs/README.md b/docs/README.md index 876bb912de..f007eb79a6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -581,6 +581,10 @@ RSSHub 提供下列 API 接口: +### 币乎 + + + ## 编程 ### 掘金 diff --git a/lib/router.js b/lib/router.js index e804368484..0dbd200472 100644 --- a/lib/router.js +++ b/lib/router.js @@ -935,6 +935,9 @@ router.get('/shanbay/checkin/:id', require('./routes/shanbay/checkin')); // Facebook router.get('/facebook/page/:id', require('./routes/facebook/page')); +// 币乎 +router.get('/bihu/activaties/:id', require('./routes/bihu/activaties')); + // 停电通知 router.get('/tingdiantz/95598/:orgNo/:provinceNo/:outageStartTime/:outageEndTime/:scope?', require('./routes/tingdiantz/95598')); router.get('/tingdiantz/95598/:orgNo/:provinceNo/:scope?', require('./routes/tingdiantz/95598')); diff --git a/lib/routes/bihu/activaties.js b/lib/routes/bihu/activaties.js new file mode 100644 index 0000000000..a1b7421b45 --- /dev/null +++ b/lib/routes/bihu/activaties.js @@ -0,0 +1,70 @@ +const axios = require('../../utils/axios'); +const url = require('url'); + +const api = 'https://be02.bihu.com/bihube-pc/bihu/user/getUserContentList/'; +const articleHost = 'https://bihu.com/article/'; +const host = 'https://bihu.com/people/'; +const getArticleApi = 'https://be02.bihu.com/bihube-pc/api/content/show/getArticle2/'; +const articleContent = 'https://oss02.bihu.com/'; + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const link = url.resolve(host, id); + const response = await axios.post(api, { + queryUserId: id, + pageNum: 1, + }); + + const data = response.data.data; + const contenList = data.list; + + let author = '未知用户'; + let out = ''; + + if (contenList.length !== 0) { + author = contenList[0].userName; + + out = await Promise.all( + contenList.map(async (item) => { + const type = item.type; + let description = item.content; + let title = '动态'; + let itemLink = link; + + // 文章 + if (type !== 1) { + title = item.title; + const contentId = item.contentId; + itemLink = url.resolve(articleHost, contentId.toString()); + + const getArticleApiResponse = await axios.post(getArticleApi, { + artId: contentId, + }); + + const articleContentPath = getArticleApiResponse.data.data.content; + + const link = url.resolve(articleContent, articleContentPath); + const articleContentResponse = await axios.get(link); + description = decodeURIComponent(articleContentResponse.data); + } + + const single = { + title: title, + link: itemLink, + author: author, + description: description, + pubDate: new Date(item.createTime), + }; + + return single; + }) + ); + } + + ctx.state.data = { + title: `币乎 - ${author}的动态`, + link: link, + item: out, + }; +};