diff --git a/docs/install/README.md b/docs/install/README.md index 0e0fb10e17..e73f22ce31 100644 --- a/docs/install/README.md +++ b/docs/install/README.md @@ -415,3 +415,7 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式 - 邮箱 邮件列表路由: - `EMAIL_CONFIG_{email}`: 邮箱设置,替换 `{email}` 为 邮箱账号,邮件账户的 `@` 替换为 `.`,例如 `EMAIL_CONFIG_xxx.qq.com`。内容格式为 `password=密码&host=服务器&port=端口`,例如 `password=123456&host=imap.qq.com&port=993`。 + +- 吹牛部落 栏目更新 + + - `CHUINIU_MEMBER`: 吹牛部落登录后的 x-member,获取方式:1. 登陆后点开文章正文 2. 打开控制台 3. 刷新 4. 找到 开头的请求 5. 找到请求头中的 x-member diff --git a/docs/reading.md b/docs/reading.md index 9f8a230422..89f2a7b19b 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -52,6 +52,18 @@ pageClass: routes +## 吹牛部落 + +### 栏目 + + + +::: warning 注意 + +正文内容需要用户登录后的 x-member 值,详情见部署页面的配置模块。若无相关配置或 x-member 失效,则只显示文章摘要。 +::: + + ## 刺猬猫 ### 章节 diff --git a/lib/config.js b/lib/config.js index f242a7bc60..c4753b2124 100644 --- a/lib/config.js +++ b/lib/config.js @@ -89,4 +89,7 @@ module.exports = { config: email_config, }, sentry: process.env.SENTRY, + chuiniu: { + member: process.env.CHUINIU_MEMBER, + }, }; diff --git a/lib/router.js b/lib/router.js index 8689e4cf6c..f9f296ccc2 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1710,4 +1710,7 @@ router.get('/pintu360/:type?', require('./routes/pintu360/index')); // engadget中国版 router.get('/engadget-cn', require('./routes/engadget-cn/home')); +// 吹牛部落 +router.get('/chuiniu/column/:id', require('./routes/chuiniu/column')); + module.exports = router; diff --git a/lib/routes/chuiniu/column.js b/lib/routes/chuiniu/column.js new file mode 100644 index 0000000000..7219a00df6 --- /dev/null +++ b/lib/routes/chuiniu/column.js @@ -0,0 +1,88 @@ +const got = require('@/utils/got'); +const config = require('@/config'); + +module.exports = async (ctx) => { + const url = 'http://chuiniu.duanshu.com'; + const column_id = ctx.params.id; + + let response = await got({ + method: 'get', + url: 'http://api.duanshu.com/fairy/api/v1/shop/identifier/', + headers: { + Origin: url, + Referer: url, + }, + }); + const shop_id = response.data.shop_id; + + response = await got({ + method: 'get', + url: `http://api.duanshu.com/h5/content/free/column/detail/${column_id}?shop_id=${shop_id}`, + headers: { + Referer: url, + }, + }); + const title = response.data.response.data.title; + const description = response.data.response.data.brief; + + response = await got({ + method: 'get', + url: `http://api.duanshu.com/h5/content/column/contents?page=1&count=10&column_id=${column_id}&shop_id=${shop_id}`, + headers: { + Referer: url, + }, + }); + const list = response.data.response.data; + + const out = await Promise.all( + list.map(async (item) => { + const title = item.title; + const brief = item.brief; + const up_time = item.up_time; + const content_id = item.content_id; + const item_link = `http://chuiniu.duanshu.com/#/brief/article/${content_id}`; + + const cache = await ctx.cache.get(item_link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const member = config.chuiniu.member; + let content; + if (member === undefined) { + content = brief + '
...
正文内容需会员登录后查看'; + } else { + try { + const response = await got({ + method: 'get', + url: `http://api.duanshu.com/h5/content/detail/${content_id}?shop_id=${shop_id}`, + headers: { + Referer: url, + 'x-member': member, + }, + }); + content = response.data.response.data.content; + } catch (error) { + content = brief + '
...
正文内容需会员登录后查看'; + } + } + + const single = { + pubDate: new Date(up_time).toUTCString(), + link: item_link, + title: title, + description: content, + }; + + ctx.cache.set(item_link, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title, + description, + link: url, + item: out, + }; +};