From 33060beb6efc019919f4ac5efbaaed1e2c1777de Mon Sep 17 00:00:00 2001
From: Jeason0228 <44083849+Jeason0228@users.noreply.github.com>
Date: Thu, 26 Sep 2019 10:56:28 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9=E3=80=90PS4?=
=?UTF-8?q?=20=E7=B3=BB=E7=BB=9F=E6=9B=B4=E6=96=B0=E7=BA=AA=E5=BD=95=20?=
=?UTF-8?q?=E3=80=91=E6=94=AF=E6=8C=81=20(#3131)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/game.md | 4 +++
lib/router.js | 1 +
lib/routes/ps/ps4updates.js | 70 +++++++++++++++++++++++++++++++++++++
3 files changed, 75 insertions(+)
create mode 100644 lib/routes/ps/ps4updates.js
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,
+ };
+};