feat: add rockstar games social club events (#4221)

This commit is contained in:
Xiang Liu
2020-03-17 11:58:32 +08:00
committed by GitHub
parent 46d8f36616
commit 6348e6af21
3 changed files with 45 additions and 0 deletions
+13
View File
@@ -161,6 +161,19 @@ pageClass: routes
<Route author="LightStrawberry" example="/psnine/game" path="/psnine/game"/>
## Rockstar Games Social Club
### 在线活动
<Route author="kookxiang" example="/socialclub/events/GTAV" path="/socialclub/events/:game?" :paramsDesc="['游戏代码(默认所有)']">
| 游戏代码 | 游戏名称 |
| -------- | ------------ |
| GTAV | 侠盗猎车手 5 |
| RDR2 | 荒野大镖客 2 |
</Route>
## Steam
### Steam search
+3
View File
@@ -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'));
+29
View File
@@ -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 ? `<img src="${x.imgUrl}" /><br>` : '') + x.description,
pubDate: new Date(x.startDate).getTime() / 1000,
link: `https://zh.socialclub.rockstargames.com/events/${x.urlHash}/${x.slug}/1`,
})),
};
};