diff --git a/docs/README.md b/docs/README.md index 6917f3842..c5809b9e8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1908,3 +1908,7 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运 ### 99% Invisible + +### 腾讯大家 + + diff --git a/router.js b/router.js index 67401c73a..8ee74b2e3 100644 --- a/router.js +++ b/router.js @@ -658,4 +658,7 @@ router.get('/99percentinvisible/transcript', require('./routes/99percentinvisibl // Hermes UK router.get('/parcel/hermesuk/:tracking', require('./routes/parcel/hermesuk')); +// 腾讯大家 +router.get('/dajia/index', require('./routes/dajia/')); + module.exports = router; diff --git a/routes/dajia/index.js b/routes/dajia/index.js new file mode 100644 index 000000000..fe89b9681 --- /dev/null +++ b/routes/dajia/index.js @@ -0,0 +1,63 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const listRes = await axios({ + method: 'get', + url: 'http://i.match.qq.com/ninjayc/dajia?action=getwenz&p=0&num=20&callback=', + headers: { + Referer: 'http://dajia.qq.com/m/index.html', + }, + }); + + const storyList = JSON.parse(listRes.data.slice(1, -2)).data; + const resultItem = await Promise.all( + storyList.map(async (story) => { + const url = story.n_mobile_url; + const item = { + title: story.n_title, + description: '', + link: url, + author: story.name, + pubDate: new Date(story.n_publishtime).toUTCString(), + }; + const key = `tx-dajia: ${url}`; + const value = await ctx.cache.get(key); + + if (value) { + item.description = value; + } else { + const storyDetail = await axios({ + method: 'get', + url: url, + headers: { + Referer: url, + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1', + }, + }); + const $ = cheerio.load(storyDetail.data); + $('#articleContent img').each(function(_, item) { + const $img = $(item); + const src = $img.attr('src'); + + if (!(src.startsWith('https://') || src.startsWith('http://'))) { + $img.attr('src', `https:${src}`); + } + + $img.attr('referrerpolicy', 'no-referrer'); + }); + + item.description = $('#articleContent').html(); + ctx.cache.set(key, item.description, 24 * 60 * 60); + } + + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: '腾讯大家', + link: 'http://dajia.qq.com/', + item: resultItem, + }; +};