Hotfix: dajia (#1709)

This commit is contained in:
凉凉
2019-03-11 10:51:41 +08:00
committed by DIYgod
parent 9f96dcf77a
commit b3d938032d

View File

@@ -1,5 +1,6 @@
const axios = require('../../../utils/axios');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
module.exports = async (ctx) => {
const listRes = await axios({
@@ -13,15 +14,17 @@ module.exports = async (ctx) => {
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 mobileUrl = story.n_mobile_url;
const pcUrl = story.n_url;
const item = {
title: story.n_title,
description: '',
link: url,
link: pcUrl,
guid: mobileUrl,
author: story.name,
pubDate: new Date(story.n_publishtime).toUTCString(),
};
const key = `tx-dajia: ${url}`;
const key = `tx-dajia: ${mobileUrl}`;
const value = await ctx.cache.get(key);
if (value) {
@@ -29,13 +32,13 @@ module.exports = async (ctx) => {
} else {
const storyDetail = await axios({
method: 'get',
url: url,
url: pcUrl,
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',
Referer: pcUrl,
},
responseType: 'arraybuffer',
});
const $ = cheerio.load(storyDetail.data);
const $ = cheerio.load(iconv.decode(storyDetail.data, 'gb2312'));
$('#articleContent img').each(function(_, item) {
const $img = $(item);
const src = $img.attr('src');