From 48003a068cf8194a0949ca441f9135cbedcf5cfd Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 22 Jun 2023 09:31:31 -0600 Subject: [PATCH] fix(route): ifeng (#12697) * fix(route): ifeng * fix: image --- lib/v2/ifeng/feng.js | 82 ++++++++++++++++---------------- lib/v2/ifeng/radar.js | 12 ++++- lib/v2/ifeng/templates/video.art | 5 ++ lib/v2/ifeng/utils.js | 26 +++++----- 4 files changed, 68 insertions(+), 57 deletions(-) create mode 100644 lib/v2/ifeng/templates/video.art diff --git a/lib/v2/ifeng/feng.js b/lib/v2/ifeng/feng.js index de417a642..005c3cbc2 100644 --- a/lib/v2/ifeng/feng.js +++ b/lib/v2/ifeng/feng.js @@ -1,71 +1,69 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const { JSDOM } = require('jsdom'); -const utils = require('./utils'); +const { extractDoc, renderVideo } = require('./utils'); const { parseDate } = require('@/utils/parse-date'); const timezone = require('@/utils/timezone'); module.exports = async (ctx) => { - const id = ctx.params.id; - const type = ctx.params.type; - const userResponse = await got({ - method: 'get', - url: `https://shankapi.ifeng.com/winter/ishare/getAccountInfo/${id}`, + const { id, type } = ctx.params; + const { data: userResponse } = await got(`https://ishare.ifeng.com/mediaShare/home/${id}/media`, { headers: { Referer: `https://feng.ifeng.com/author/${id}`, }, }); - const contentResponse = await got({ - method: 'get', - url: `https://shankapi.ifeng.com/season/ishare/getShareListData/${id}/${type}/1/ifengnewsh5/getListData`, + const { data: contentResponse } = await got(`https://shankapi.ifeng.com/season/ishare/getShareListData/${id}/${type}/1/ifengnewsh5/getListData`, { headers: { Referer: `https://feng.ifeng.com/author/${id}`, }, }); - const userData = userResponse.data.data.data; - const contentData = JSON.parse(contentResponse.data.match(/"data":(\[(.*?)\])/)[1]); + const $ = cheerio.load(userResponse); + const { sockpuppetInfo: allData } = JSON.parse( + $('script') + .text() + .match(/var allData = (.*?);/)[1] + ); + const { data: contentData } = JSON.parse(contentResponse.match(/getListData\((.*)\)/)[1]); + const { weMediaName: mediaName } = allData; + + const list = contentData.map((item) => ({ + title: item.title, + pubDate: timezone(parseDate(item.newsTime), +8), + author: mediaName, + link: `https:${item.url}`, + })); - const mediaName = userData.weMediaName; const items = await Promise.all( - (contentData || []).map(async (item) => { - const link = `https:${item.url}`; - const simple = { - title: item.title, - description: `${item.title}`, - pubDate: timezone(parseDate(item.newsTime), +8), - author: mediaName, - link, - }; + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); - const details = await ctx.cache.tryGet(`ifeng:feng:${link}`, async () => { - const response = await got(link); - const $ = cheerio.load(response.data); + const allData = JSON.parse( + $('script') + .text() + .match(/var allData = ({.*?});/)[1] + ); if (type === 'doc') { - const dom = new JSDOM(``, { - runScripts: 'dangerously', - }); - const data = dom.window.allData; - return { - description: utils.extractDoc(data), - }; + item.description = extractDoc(allData.docData.contentData.contentList); } if (type === 'video') { - return { - description: `