diff --git a/docs/other.md b/docs/other.md index bb0562597..e245a8881 100644 --- a/docs/other.md +++ b/docs/other.md @@ -461,3 +461,7 @@ type 为 all 时,category 参数不支持 cost 和 free ### 艾瑞 + +### 腾讯谷雨 + + diff --git a/lib/router.js b/lib/router.js index e9859f471..478c51709 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1217,4 +1217,7 @@ router.get('/infoq/topic/:id', require('./routes/infoq/topic')); // 艾瑞 router.get('/iresearch/report', require('./routes/iresearch/report')); +// 谷雨 +router.get('/tencent/guyu/channel/:name', require('./routes/tencent/guyu/channel')); + module.exports = router; diff --git a/lib/routes/tencent/guyu/channel.js b/lib/routes/tencent/guyu/channel.js new file mode 100644 index 000000000..1f42530fc --- /dev/null +++ b/lib/routes/tencent/guyu/channel.js @@ -0,0 +1,62 @@ +const axios = require('../../../utils/axios'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); + +const map = new Map([ + ['lab', { title: '谷雨实验室', link: 'https://news.qq.com/guyu/huizong/hz_lab.htm', channelid: 498 }], + ['report', { title: '谷雨报道', link: 'https://news.qq.com/guyu/huizong/hz_report.htm', channelid: 500 }], + ['story', { title: '谷雨故事', link: 'https://gy.qq.com/hz_story.html', channelid: 332 }], + ['shalong', { title: '谷雨沙龙', link: 'https://news.qq.com/guyu/huizong/hz_shalong.htm', channelid: 542 }], +]); + +module.exports = async (ctx) => { + const type = ctx.params.name; + const title = map.get(type).title; + const channelid = map.get(type).channelid; + const link = map.get(type).link; + + const api = `https://i.match.qq.com/ninjayc/guyu?action=guyu&channelid=${channelid}&p=0&num=10`; + const response = await axios.get(api); + const list = response.data.data; + + const out = await Promise.all( + list.map(async (info) => { + const title = info.n_short_title; + const date = info.n_publishtime; + const itemUrl = info.n_url; + const author = info.name; + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await axios.get(itemUrl, { + responseType: 'arraybuffer', + }); + + response.data = iconv.decode(response.data, 'gbk'); + + const $ = cheerio.load(response.data); + const description = $('div.articleContent') + .html() + .replace(/src="/g, `src="https:`); + + const single = { + title: title, + link: itemUrl, + description: description, + author: author, + pubDate: new Date(date).toUTCString(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: title, + link: link, + item: out, + }; +};