From 75f545a9d7face07129b57d26dc98614714e774a Mon Sep 17 00:00:00 2001 From: miles Date: Tue, 13 Jun 2023 18:49:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E8=85=BE=E8=AE=AF=E4=BC=81?= =?UTF-8?q?=E9=B9=85=E5=8F=B7=E6=8A=93=E5=8F=96=E5=A4=B1=E8=B4=A5=20(#1265?= =?UTF-8?q?3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/v2/tencent/news/author.js | 54 ++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/lib/v2/tencent/news/author.js b/lib/v2/tencent/news/author.js index 5d473a85f..bc0cd8e40 100644 --- a/lib/v2/tencent/news/author.js +++ b/lib/v2/tencent/news/author.js @@ -2,38 +2,40 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const { parseDate } = require('@/utils/parse-date'); const timezone = require('@/utils/timezone'); +const config = require('@/config').value; module.exports = async (ctx) => { const mid = ctx.params.mid; - const response = await got(`https://pacaio.match.qq.com/om/mediaArticles?mid=${mid}&num=10&page=0`); - const reponse = response.data; - const title = reponse.mediainfo.name; - const description = reponse.mediainfo.intro; - const list = reponse.data; + const homePageInfoUrl = `https://i.news.qq.com/i/getUserHomepageInfo?chlid=${mid}`; + const userInfo = await ctx.cache.tryGet(homePageInfoUrl, async () => (await got(homePageInfoUrl)).data.userinfo); + const title = userInfo.nick; + const description = userInfo.user_desc; + const suid = encodeURIComponent(userInfo.suid); - const items = await Promise.all( - list.map((item) => { - const title = item.title; - const pubDate = timezone(parseDate(item.time), +8); - const itemUrl = item.vurl; - const author = item.source; - const abstract = item.abstract; + const newsListUrl = `https://i.news.qq.com/getSubNewsMixedList?guestSuid=${suid}&tabId=om_index`; + const news = await ctx.cache.tryGet(newsListUrl, async () => (await got(newsListUrl)).data.newslist, config.cache.routeExpire, false); - return ctx.cache.tryGet(itemUrl, async () => { - const response = await got(itemUrl); - const $ = cheerio.load(response.data); - const article = $('div.content-article'); + const items = news.map((item) => { + const title = item.title; + const pubDate = timezone(parseDate(item.time), +8); + const itemUrl = item.url; + const author = item.source; + const abstract = item.abstract; - return { - title, - description: article.html() || abstract, - link: itemUrl, - author, - pubDate, - }; - }); - }) - ); + return ctx.cache.tryGet(itemUrl, async () => { + const response = await got(itemUrl); + const $ = cheerio.load(response.data); + const article = $('#ArticleContent'); + + return { + title, + description: article.html() || abstract, + link: itemUrl, + author, + pubDate, + }; + }); + }); ctx.state.data = { title,