增加:腾讯大家 (#912)

- 实现 #863 的后半部分
This commit is contained in:
凉凉
2018-10-18 09:32:57 +08:00
committed by DIYgod
parent 32b3c5892c
commit 5152e757c4
3 changed files with 70 additions and 0 deletions
+4
View File
@@ -1908,3 +1908,7 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
### 99% Invisible
<route name="Transcript" author="Ji4n1ng" example="/99percentinvisible/transcript" path="/99percentinvisible/transcript"/>
### 腾讯大家
<route name="首页" author="xyqfer" example="/dajia/index" path="/dajia/index"/>
+3
View File
@@ -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;
+63
View File
@@ -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,
};
};