diff --git a/lib/routes/monsterhunter/update.js b/lib/routes/monsterhunter/update.js index 54f0dae6e..6907522cd 100644 --- a/lib/routes/monsterhunter/update.js +++ b/lib/routes/monsterhunter/update.js @@ -2,33 +2,67 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); module.exports = async (ctx) => { - const url = 'http://game.capcom.com/world/cn/infomation.html'; - - const response = await got({ + const url1 = 'http://game.capcom.com/world/cn/infomation.html'; + const response1 = await got({ method: 'get', - url, + url: url1, + }); + let $ = cheerio.load(response1.data); + const result1 = $('.version') + .map((index, item) => { + item = $(item); + return { + title: item.find('h3').text(), + description: item.children('div').html(), + link: url1, + author: 'MONSTER HUNTER: WORLD', + }; + }) + .get(); + + const url2 = 'https://www.monsterhunter.com/update/mhw/cn/'; + const response2 = await got({ + method: 'get', + url: url2, }); - const data = response.data; + $ = cheerio.load(response2.data); + let result2 = $('.btn a') + .map((index, item) => { + item = $(item); + return { + title: item.find('.text').text(), + pubDate: new Date(item.find('.date').text()).toUTCString(), + link: url2 + item.attr('href'), + }; + }) + .get(); - const $ = cheerio.load(data); - const list = $('.version'); + result2 = await Promise.all( + result2.map(async (item) => + Promise.resolve( + await ctx.cache.tryGet(item.link, async () => { + const response = await got.get(item.link); + const $ = cheerio.load(response.data); + + return { + title: + $('.page-ttl') + .text() + .trim() || item.title, + description: $('#contents').html(), + link: item.link, + pubDate: item.pubDate, + author: 'MONSTER HUNTER WORLD: ICEBORNE', + }; + }) + ) + ) + ); ctx.state.data = { title: '怪物猎人更新情报', - link: url, - item: - list && - list - .map((index, item) => { - item = $(item); - return { - title: item.find('h3').text(), - description: item.children('div').html(), - link: url, - guid: item.find('h3').text(), - }; - }) - .get(), + link: url2, + item: result2.concat(result1), }; };