From 1d81a4a9ce8ebad75f53c0f6dfaec06a38dd2e90 Mon Sep 17 00:00:00 2001 From: Cloud Date: Mon, 1 Jul 2019 11:24:38 +0800 Subject: [PATCH] feat: add wechat uread channel (#2515) * feat: add wechat uread channel * feat: add wechat uread channel * feat: add wechat uread channel * Update social-media.md --- docs/social-media.md | 4 +++ lib/router.js | 1 + lib/routes/tencent/wechat/uread.js | 51 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 lib/routes/tencent/wechat/uread.js diff --git a/docs/social-media.md b/docs/social-media.md index bcacf90a79..cb141f7b5a 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -680,6 +680,10 @@ pageClass: routes ::: +### 公众号 (优读来源) + + + ### 公众平台系统公告栏目 diff --git a/lib/router.js b/lib/router.js index 76552e897b..85c0f9af87 100644 --- a/lib/router.js +++ b/lib/router.js @@ -447,6 +447,7 @@ router.get('/wechat/csm/:id', require('./routes/tencent/wechat/csm')); router.get('/wechat/announce', require('./routes/tencent/wechat/announce')); router.get('/wechat/miniprogram/plugins', require('./routes/tencent/wechat/miniprogram/plugins')); router.get('/wechat/tgchannel/:id', require('./routes/tencent/wechat/tgchannel')); +router.get('/wechat/uread/:userid', require('./routes/tencent/wechat/uread')); // All the Flight Deals router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index')); diff --git a/lib/routes/tencent/wechat/uread.js b/lib/routes/tencent/wechat/uread.js new file mode 100644 index 0000000000..8283342ebe --- /dev/null +++ b/lib/routes/tencent/wechat/uread.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const userid = ctx.params.userid; + const url = `http://119.29.146.143:8080/reading/subscription/account/recent?uid=${userid}`; + const response = await got({ + method: 'get', + url: url, + }); + const data = response.data; + + const ProcessFeed = (data) => { + const $ = cheerio.load(data); + return $('.rich_media_content').html(); + }; + + const items = await Promise.all( + data.data.map(async (item) => { + const link = item.url; + + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await got({ + method: 'get', + url: link, + }); + + const description = ProcessFeed(response.data); + + const single = { + title: item.title, + description, + link: link, + author: item.official_account, + pubDate: item.publish_time, + }; + ctx.cache.set(link, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `优读 - ${userid}`, + link: 'https://uread.ai/', + item: items, + }; +};