From 7691b21998bbed8671fdf0a85edbae6cad9806bf Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sun, 21 Apr 2019 21:51:49 +0800 Subject: [PATCH] add PlayStation Store list --- docs/game.md | 12 ++++++++++-- docs/other.md | 2 +- lib/router.js | 3 +++ lib/routes/ps/list.js | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 lib/routes/ps/list.js diff --git a/docs/game.md b/docs/game.md index 0a98fe533..e8a3a6316 100644 --- a/docs/game.md +++ b/docs/game.md @@ -1,4 +1,4 @@ -# 游戏资讯 +# 游戏 ## 3DMGame @@ -100,7 +100,7 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 ## 游研社 - + | 推游 | 游戏史 | 大事件 | 文化 | 趣闻 | 经典回顾 | | --------- | ------- | ------ | ------- | ---- | -------- | @@ -115,3 +115,11 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 + +## PlayStation Store + + + +适用于 URL 如 的列表页,比如 [PSN 每月免费游戏](https://store.playstation.com/zh-hans-hk/grid/STORE-MSF86012-PLUS_FTT_CONTENT) 的 gridName 为 STORE-MSF86012-PLUS_FTT_CONTENT + + diff --git a/docs/other.md b/docs/other.md index 0e2075eb2..1031bfbeb 100644 --- a/docs/other.md +++ b/docs/other.md @@ -1,4 +1,4 @@ -# 待分类 +# 其他 ## 自如 diff --git a/lib/router.js b/lib/router.js index 5653a44ba..e382b1d37 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1279,4 +1279,7 @@ router.get('/gaoqingla/:tag?', require('./routes/gaoqingla/latest')); // 马良行 router.get('/mlhang', require('./routes/mlhang/latest')); +// PlayStation Store +router.get('/ps/list/:gridName', require('./routes/ps/list')); + module.exports = router; diff --git a/lib/routes/ps/list.js b/lib/routes/ps/list.js new file mode 100644 index 000000000..49e3f8445 --- /dev/null +++ b/lib/routes/ps/list.js @@ -0,0 +1,34 @@ +const axios = require('../../utils/axios'); + +module.exports = async (ctx) => { + const gridName = ctx.params.gridName; + + const response = await axios({ + method: 'get', + url: `https://store.playstation.com/valkyrie-api/zh/HK/19/container/${gridName}?size=30&bucket=games&start=0`, + headers: { + Referer: `https://store.playstation.com/zh-hans-hk/grid/${gridName}/1`, + }, + }); + const data = response.data; + const items = data.included && data.included.filter((item, index) => index % 2); + const sub = data.included && data.included.filter((item, index) => !(index % 2)); + + ctx.state.data = { + title: `PlayStation Store - ${data.data.attributes.name}`, + link: `https://store.playstation.com/zh-hans-hk/grid/${gridName}/1`, + item: + items && + items.map((item, index) => ({ + title: `${item.attributes.name} (${sub[index].attributes.name})`, + description: `大小:${item.attributes['file-size'].value}${item.attributes['file-size'].unit}

设备:${item.attributes.platforms.join(', ')}

类型:${item.attributes.genres.join(', ')}

评分:${ + item.attributes['star-rating'].score + }

描述:${item.attributes['long-description']}

预览:${ + item.attributes['media-list'] && item.attributes['media-list'].preview && item.attributes['media-list'].preview[0] && item.attributes['media-list'].preview[0].url + ? `` + : '无' + }`, + link: `https://store.playstation.com/zh-hans-hk/product/${item.id}`, + })), + }; +};