feat: 添加对【PS4 系统更新纪录 】支持 (#3131)

This commit is contained in:
Jeason0228
2019-09-26 10:56:28 +08:00
committed by DIYgod
parent 95b7dc4c67
commit 33060beb6e
3 changed files with 75 additions and 0 deletions

View File

@@ -104,6 +104,10 @@ pageClass: routes
<Route author="DIYgod" example="/ps/trophy/DIYgod_" path="/ps/trophy/:id" :paramsDesc="['用户 ID']"/> <Route author="DIYgod" example="/ps/trophy/DIYgod_" path="/ps/trophy/:id" :paramsDesc="['用户 ID']"/>
### PlayStation 4 系统更新纪录
<Route author="Jeason0228" example="/ps/ps4updates/" path="/ps/ps4updates/" />
## psnine ## psnine
### 首页-白金攻略/游戏开箱 ### 首页-白金攻略/游戏开箱

View File

@@ -1287,6 +1287,7 @@ router.get('/mlhang', require('./routes/mlhang/latest'));
// PlayStation Store // PlayStation Store
router.get('/ps/list/:gridName', require('./routes/ps/list')); router.get('/ps/list/:gridName', require('./routes/ps/list'));
router.get('/ps/trophy/:id', require('./routes/ps/trophy')); router.get('/ps/trophy/:id', require('./routes/ps/trophy'));
router.get('/ps/ps4updates', require('./routes/ps/ps4updates'));
// Nintendo // Nintendo
router.get('/nintendo/eshop/jp', require('./routes/nintendo/eshop_jp')); router.get('/nintendo/eshop/jp', require('./routes/nintendo/eshop_jp'));

View File

@@ -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,
};
};