rsshub
Version:
Make RSS Great Again!
61 lines (60 loc) • 2.13 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
//#region lib/routes/rockstargames/events.ts
const gameList = /* @__PURE__ */ new Set(["GTAV", "RDR2"]);
const eventTypeName = {
InGameBonus: "游戏内奖励",
InGameUnlock: "游戏内解锁",
InGameDiscount: "游戏内折扣"
};
const route = {
path: "/socialclub/events/:game?",
categories: ["game"],
example: "/rockstargames/socialclub/events/GTAV",
parameters: { game: "游戏代码(默认所有)" },
name: "在线活动",
maintainers: ["kookxiang"],
description: `| 游戏代码 | 游戏名称 |
| -------- | ------------ |
| GTAV | 侠盗猎车手 5 |
| RDR2 | 荒野大镖客 2 |`,
handler
};
async function handler(ctx) {
const { game } = ctx.req.param();
const gameId = gameList.has(game) ? game : "";
const baseUrl = "https://socialclub.rockstargames.com";
const cookies = /* @__PURE__ */ new Map();
let url = `${baseUrl}/events/eventlisting?pageId=1&gameId=${gameId}&_=${Date.now()}`;
let response;
for (let i = 0; i < 5; i++) {
response = await rofetch.raw(url, {
redirect: "manual",
headers: { cookie: [...cookies].map(([k, v]) => `${k}=${v}`).join("; ") }
});
for (const c of response.headers.getSetCookie()) {
const pair = c.split(";", 1)[0];
const eq = pair.indexOf("=");
const value = pair.slice(eq + 1);
if (value) cookies.set(pair.slice(0, eq), value);
else cookies.delete(pair.slice(0, eq));
}
const location = response.headers.get("location");
if (!location) break;
url = new URL(location, baseUrl).href;
}
const { events } = response._data;
return {
title: "在线活动 - Rockstar Games Social Club",
link: `${baseUrl}/events?gameId=${gameId}`,
item: events?.map((x) => ({
title: x.headerText,
category: eventTypeName[x.eventType] || x.eventType,
description: (x.imgUrl ? `<img src="${x.imgUrl}"><br>` : "") + x.description,
pubDate: parseDate(x.startDate),
link: x.linkToUrl ? new URL(x.linkToUrl, baseUrl).href : `${baseUrl}/events/${x.urlHash}/${x.slug}/1`
}))
};
}
//#endregion
export { route };