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
This commit is contained in:
Cloud
2019-07-01 11:24:38 +08:00
committed by DIYgod
parent 0281592839
commit 1d81a4a9ce
3 changed files with 56 additions and 0 deletions

View File

@@ -680,6 +680,10 @@ pageClass: routes
::: :::
</Route> </Route>
### 公众号 (优读来源)
<Route author="kt286" example="/wechat/uread/shensing" path="/wechat/uread/:userid" :paramsDesc="['公众号ID, 可在 优读APP 中找到']"/>
### 公众平台系统公告栏目 ### 公众平台系统公告栏目
<Route author="xyqfer" example="/wechat/announce" path="/wechat/announce" /> <Route author="xyqfer" example="/wechat/announce" path="/wechat/announce" />

View File

@@ -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/announce', require('./routes/tencent/wechat/announce'));
router.get('/wechat/miniprogram/plugins', require('./routes/tencent/wechat/miniprogram/plugins')); router.get('/wechat/miniprogram/plugins', require('./routes/tencent/wechat/miniprogram/plugins'));
router.get('/wechat/tgchannel/:id', require('./routes/tencent/wechat/tgchannel')); router.get('/wechat/tgchannel/:id', require('./routes/tencent/wechat/tgchannel'));
router.get('/wechat/uread/:userid', require('./routes/tencent/wechat/uread'));
// All the Flight Deals // All the Flight Deals
router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index')); router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index'));

View File

@@ -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,
};
};