diff --git a/docs/game.md b/docs/game.md index 709e81707a..7a1fd9e1c8 100644 --- a/docs/game.md +++ b/docs/game.md @@ -104,6 +104,10 @@ pageClass: routes +### PlayStation 4 系统更新纪录 + + + ## psnine ### 首页-白金攻略/游戏开箱 diff --git a/lib/router.js b/lib/router.js index 5e9752251f..306aa58536 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1287,6 +1287,7 @@ router.get('/mlhang', require('./routes/mlhang/latest')); // PlayStation Store router.get('/ps/list/:gridName', require('./routes/ps/list')); router.get('/ps/trophy/:id', require('./routes/ps/trophy')); +router.get('/ps/ps4updates', require('./routes/ps/ps4updates')); // Nintendo router.get('/nintendo/eshop/jp', require('./routes/nintendo/eshop_jp')); diff --git a/lib/routes/ps/ps4updates.js b/lib/routes/ps/ps4updates.js new file mode 100644 index 0000000000..9f435b0874 --- /dev/null +++ b/lib/routes/ps/ps4updates.js @@ -0,0 +1,70 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); +const host = 'https://asia.playstation.com/'; +module.exports = async (ctx) => { + const link = `https://asia.playstation.com/chs-hk/ps4/system-update/ps4-system-update-change-log/`; + const response = await got.get(link, { + responseType: 'buffer', + }); + const $ = cheerio.load(response.data); + // let title = $('.psc-main-format-style').first().text(); + function sortDate(e) { + // console.log(e); + const pubday = e.substr(8, 2); + const pubmonth = e.substr(5, 2); + const pubyear = e.substr(0, 4); + const pubdateString = pubmonth + `-` + pubday + `-` + pubyear; + // console.log(pubdateString); + return pubdateString; + } + const list = $('.layoutRowParsys ul li') + .map(function() { + const info = { + title: $(this) + .find('span.psc-d-block') + .text(), + link: $(this) + .find('a') + .attr('href'), + date: sortDate( + $(this) + .find('span.psc-info-date') + .text() + ), + }; + return info; + }) + .get(); + const out = await Promise.all( + list.map(async (info) => { + const title = info.title; + const date = info.date; + const itemUrl = url.resolve(host, info.link); + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const response = await got.get(itemUrl, { + responseType: 'buffer', + }); + const $ = cheerio.load(response.data); + const description = $('.layoutRowParsys').html(); + const single = { + title: title, + link: itemUrl, + description: description, + pubDate: new Date(date).toDateString(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + ctx.state.data = { + title: $('.psc-main-format-style') + .first() + .text(), + link: link, + item: out, + }; +};