From 9be1457ec8d3d303ae4c3bd480264bbf6326e365 Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 12 Oct 2022 21:18:48 +0400 Subject: [PATCH] fix(route): mtime (#11074) --- docs/multimedia.md | 2 +- lib/v2/mtime/maintainer.js | 2 +- lib/v2/mtime/news.js | 58 ++++++++++++++++++++------------------ lib/v2/mtime/radar.js | 2 +- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/docs/multimedia.md b/docs/multimedia.md index 79b3c53f9..67d194b71 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -1543,7 +1543,7 @@ JavDB 有多个备用域名,本路由默认使用永久域名 diff --git a/lib/v2/mtime/maintainer.js b/lib/v2/mtime/maintainer.js index ae0ebe642..80ea9ed53 100644 --- a/lib/v2/mtime/maintainer.js +++ b/lib/v2/mtime/maintainer.js @@ -1,3 +1,3 @@ module.exports = { - '/mtime/news': ['TsSmartTT'], + '/news': ['TsSmartTT'], }; diff --git a/lib/v2/mtime/news.js b/lib/v2/mtime/news.js index e939db6b8..97f238365 100644 --- a/lib/v2/mtime/news.js +++ b/lib/v2/mtime/news.js @@ -2,47 +2,51 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const timezone = require('@/utils/timezone'); const { parseDate } = require('@/utils/parse-date'); +const asyncPool = require('tiny-async-pool'); module.exports = async (ctx) => { - const link = 'http://news.mtime.com/'; - const response = await got({ - method: 'get', - url: link, + const link = 'https://news.mtime.com'; + const response = await got(link, { + https: { + rejectUnauthorized: false, + }, }); const $ = cheerio.load(response.data); const list = $('ul.left-cont.fix li') - .map((_, item) => { + .toArray() + .map((item) => { item = $(item); return { title: item.find('h4 a').text(), link: item.find('h4 a').attr('href'), }; + }); + + const items = []; + for await (const item of asyncPool(4, list, (item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const content = cheerio.load(detailResponse.data); + + content('.DRE-subject-wrapper').remove(); + + item.author = content('.editor').text().replace('编辑:', ''); + item.description = content('.body').first().html(); + item.pubDate = timezone(parseDate(content('.userCreateTime').text()), 8); + item.category = content('.keyword a') + .toArray() + .map((item) => content(item).text()); + + return item; }) - .get(); - - const items = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); - - content('.DRE-subject-wrapper').remove(); - - item.author = content('.editor').text().replace('编辑:', ''); - item.description = content('.body').first().html(); - item.pubDate = timezone(parseDate(content('.userCreateTime').text()), 8); - - return item; - }) - ) - ); + )) { + items.push(item); + } ctx.state.data = { - title: 'Mtime时光网 - 资讯', + title: $('head title').text().trim(), link, + image: 'http://static1.mtime.cn/favicon.ico', item: items, }; }; diff --git a/lib/v2/mtime/radar.js b/lib/v2/mtime/radar.js index 113c4feff..e5e558dc2 100644 --- a/lib/v2/mtime/radar.js +++ b/lib/v2/mtime/radar.js @@ -3,7 +3,7 @@ module.exports = { _name: '时光网', news: [ { - title: '资讯', + title: '时光新闻', docs: 'https://docs.rsshub.app/multimedia.html#shi-guang-wang', source: '/', target: '/mtime/news',