Partypack/Server/Source/Routes/Pages.ts

54 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-01-20 23:34:31 +01:00
import { Router } from "express";
import { FullFortnitePages, GenerateFortnitePages } from "../Modules/FNUtil";
2024-01-20 23:34:31 +01:00
import axios from "axios";
import { IS_DEBUG } from "../Modules/Constants";
import { RequireAuthentication } from "../Modules/Middleware";
2024-01-20 23:34:31 +01:00
const App = Router();
App.get("/content/api/pages/fortnite-game", (_, res) => res.json({
...FullFortnitePages,
sparkTracks: {
...FullFortnitePages!.sparkTracks,
_activeDate: "2023-01-01T01:00:00.000Z",
lastModified: new Date().toISOString()
}
}))
2024-01-20 23:34:31 +01:00
App.get("/content/api/pages/fortnite-game/:Section", RequireAuthentication(), async (req, res) => {
2024-01-20 23:34:31 +01:00
if (req.params.Section.toLowerCase() === "spark-tracks") // custom song injection
{
const ProcessedPages = await GenerateFortnitePages(req.user!);
res.removeHeader("Access-Control-Allow-Origin");
res.removeHeader("Access-Control-Allow-Credentials");
res.removeHeader("Vary");
2024-01-20 23:34:31 +01:00
return res.json(
{
_title: "spark-tracks",
_noIndex: false,
_activeDate: "2023-01-01T01:00:00.000Z",
2024-01-20 23:34:31 +01:00
lastModified: new Date().toISOString(),
_locale: "en-US",
_templateName: "blank",
...ProcessedPages.FNPages,
2024-01-20 23:34:31 +01:00
_suggestedPrefetch: []
}
);
}
2024-01-20 23:34:31 +01:00
const CachedSection = Object.values(FullFortnitePages!).find(x => x._title === req.params.Section);
if (!CachedSection)
return res.status(404).send("funny section not found haha kill me");
2024-01-20 23:34:31 +01:00
const ContentFromServer = await axios.get(`https://fortnitecontent-website-prod07.ol.epicgames.com/content/api/pages/fortnite-game/${CachedSection._title}`);
if (ContentFromServer.status !== 200)
return res.status(404).json({ error: IS_DEBUG ? ContentFromServer.data : "Fortnite server returned an error." });
res.json(ContentFromServer.data);
})
export default {
App
}