From 6348e6af21e4754b3c313b1ea9e6388120237f37 Mon Sep 17 00:00:00 2001 From: Xiang Liu Date: Tue, 17 Mar 2020 11:58:32 +0800 Subject: [PATCH] feat: add rockstar games social club events (#4221) --- docs/game.md | 13 +++++++++++++ lib/router.js | 3 +++ lib/routes/socialclub/events.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 lib/routes/socialclub/events.js diff --git a/docs/game.md b/docs/game.md index 15b751d8d..4c7beaafd 100644 --- a/docs/game.md +++ b/docs/game.md @@ -161,6 +161,19 @@ pageClass: routes +## Rockstar Games Social Club + +### 在线活动 + + + +| 游戏代码 | 游戏名称 | +| -------- | ------------ | +| GTAV | 侠盗猎车手 5 | +| RDR2 | 荒野大镖客 2 | + + + ## Steam ### Steam search diff --git a/lib/router.js b/lib/router.js index e5bcfaa1d..1ac25e8fe 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2360,6 +2360,9 @@ router.get('/moxingfans', require('./routes/moxingfans')); // Chiphell router.get('/chiphell/forum/:forumId?', require('./routes/chiphell/forum')); +// Rockstar Games Social Club +router.get('/socialclub/events/:game?', require('./routes/socialclub/events')); + // 湖北大学 router.get('/hubu/news/:type', require('./routes/universities/hubu/news')); diff --git a/lib/routes/socialclub/events.js b/lib/routes/socialclub/events.js new file mode 100644 index 000000000..4c53fb127 --- /dev/null +++ b/lib/routes/socialclub/events.js @@ -0,0 +1,29 @@ +const gameList = ['GTAV', 'RDR2']; + +module.exports = async (ctx) => { + const gameId = gameList.includes(ctx.params.game) ? ctx.params.game : ''; + const baseUrl = `https://zh.socialclub.rockstargames.com/events/eventlisting?pageId=1&gameId=${gameId}`; + // R星的傻逼防爬 + const browser = await require('@/utils/puppeteer')(); + const page = await browser.newPage(); + await page.goto(baseUrl + '&_=' + Date.now()); + // eslint-disable-next-line + const jsonStr = await page.evaluate(() => document.body.innerText); + browser.close(); + + const { events } = JSON.parse(jsonStr); + + ctx.state.data = { + title: 'Online Events - Rockstar Games Social Club', + link: 'https://zh.socialclub.rockstargames.com/events?gameId=' + gameId, + item: + events && + events.map((x) => ({ + title: x.headerText, + category: x.eventType, + description: (x.imgUrl ? `
` : '') + x.description, + pubDate: new Date(x.startDate).getTime() / 1000, + link: `https://zh.socialclub.rockstargames.com/events/${x.urlHash}/${x.slug}/1`, + })), + }; +};