Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2ddb851cab | ||
|
92f01aad52 | ||
|
98ac93aad8 | ||
|
0c3d568197 | ||
|
271d899125 | ||
|
22ca67e0fe | ||
|
8bd9d627e5 | ||
|
dc98e45e2c | ||
|
99519058d7 |
|
@ -1,5 +1,2 @@
|
||||||
# Partypack
|
# Partypack
|
||||||
|
The #1 tool to modify Fortnite Festival songs!
|
||||||
The "best" tool for playing custom songs on Fortnite Festival.
|
|
||||||
|
|
||||||
please submit pull requests to fix mc's shit code
|
|
||||||
|
|
136
Server/Source/Modules/Errors.ts
Normal file
136
Server/Source/Modules/Errors.ts
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
export interface ApiError {
|
||||||
|
errorCode: string
|
||||||
|
errorMessage: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const errorCode = Symbol("errorCode");
|
||||||
|
|
||||||
|
export abstract class ApiError {
|
||||||
|
static [errorCode]?: string;
|
||||||
|
static [Symbol.hasInstance](instance: unknown) {
|
||||||
|
if (typeof instance !== "object" || instance === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!("errorCode" in instance) || !("errorMessage" in instance) || typeof instance.errorCode !== "string" || typeof instance.errorMessage !== "string") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this === ApiError) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this[errorCode]) {
|
||||||
|
this[errorCode] = new (this as any)().errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this[errorCode] === instance.errorCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const errorPrefix = `errors.dev.mcthe.partypacker`
|
||||||
|
|
||||||
|
export class InternalError extends ApiError {
|
||||||
|
errorCode: string;
|
||||||
|
errorMessage: string;
|
||||||
|
|
||||||
|
constructor(errorMessage: string) {
|
||||||
|
super();
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
this.errorCode = `${errorPrefix}.internal_error`;
|
||||||
|
}
|
||||||
|
errorString() {
|
||||||
|
return `${this.errorCode}: ${this.errorMessage}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorJSON() {
|
||||||
|
return {
|
||||||
|
errorCode: this.errorCode,
|
||||||
|
errorMessage: this.errorMessage
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MissingPermissions extends ApiError {
|
||||||
|
errorCode: string;
|
||||||
|
errorMessage: string;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.errorCode = `${errorPrefix}.missing_permissions`;
|
||||||
|
this.errorMessage = "You don't have permission to access this endpoint.";
|
||||||
|
}
|
||||||
|
|
||||||
|
errorString() {
|
||||||
|
return `${this.errorCode}: ${this.errorMessage}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorJSON() {
|
||||||
|
return {
|
||||||
|
errorCode: this.errorCode,
|
||||||
|
errorMessage: this.errorMessage
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MisconfiguredDiscordBot extends ApiError {
|
||||||
|
/*errorCode: string;
|
||||||
|
errorMessage: string*/
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.errorCode = `${errorPrefix}.instance.invalid_discord_bot`;
|
||||||
|
this.errorMessage = "This Partypack instance has a misconfigured Discord bot.";;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorString() {
|
||||||
|
return `${this.errorCode}: ${this.errorMessage}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorJSON() {
|
||||||
|
return {
|
||||||
|
errorCode: this.errorCode,
|
||||||
|
errorMessage: this.errorMessage
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MissingServerRole extends ApiError {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.errorCode = `${errorPrefix}.missing_discord_server_role`;
|
||||||
|
this.errorMessage = "This role does not exist in the Discord server.";
|
||||||
|
}
|
||||||
|
|
||||||
|
errorString() {
|
||||||
|
return `${this.errorCode}: ${this.errorMessage}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorJSON() {
|
||||||
|
return {
|
||||||
|
errorCode: this.errorCode,
|
||||||
|
errorMessage: this.errorMessage
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MissingDatabaseRole extends ApiError {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.errorCode = `${errorPrefix}.missing_database_role`;
|
||||||
|
this.errorMessage = "This role does not exist in the database.";
|
||||||
|
}
|
||||||
|
|
||||||
|
errorString() {
|
||||||
|
return `${this.errorCode}: ${this.errorMessage}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
errorJSON() {
|
||||||
|
return {
|
||||||
|
errorCode: this.errorCode,
|
||||||
|
errorMessage: this.errorMessage
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//console.log(new MisconfiguredDiscordBot().errorJSON())
|
|
@ -1,26 +1,41 @@
|
||||||
import axios from "axios";
|
|
||||||
import { Err } from "./Logger";
|
import { Err } from "./Logger";
|
||||||
import { red } from "colorette";
|
import { red } from "colorette";
|
||||||
import { FULL_SERVER_ROOT } from "./Constants";
|
import { FULL_SERVER_ROOT } from "./Constants";
|
||||||
import { User } from "../Schemas/User";
|
import { User } from "../Schemas/User";
|
||||||
import { Song } from "../Schemas/Song";
|
import { Song } from "../Schemas/Song";
|
||||||
|
|
||||||
export let FullFortnitePages: {[key: string]: any} | null = null;
|
export let FullFortnitePages: { [key: string]: any } | null = null;
|
||||||
export let OriginalSparks: {[key: string]: any} | null = null;
|
export let OriginalSparks: {[key: string]: any} | null = null;
|
||||||
let LastContentDownloadDate: Date = new Date(0); // set it to 1970 as default cuz im not boutta check if its null
|
let LastContentDownloadDate: Date = new Date(0); // set it to 1970 as default cuz im not boutta check if its null
|
||||||
|
|
||||||
GenerateFortnitePages(null);
|
GenerateFortnitePages(null);
|
||||||
|
|
||||||
export async function GenerateFortnitePages(ForUser: User | null): Promise<{ Success: boolean, FNPages: { [key: string]: unknown } | null }> {
|
export async function GenerateFortnitePages(ForUser: User | null): Promise<{ Success: boolean, FNPages: { [key: string]: unknown } | null }> {
|
||||||
const { status, data } = // check if 30 minutes have passed since last content update. if so, get a new copy of pages, if not, fuck off
|
let status;
|
||||||
|
let data;
|
||||||
|
if (FullFortnitePages === null || Date.now() > LastContentDownloadDate.getTime() + 30 * 60 * 1000) {
|
||||||
|
const response = await fetch("https://fortnitecontent-website-prod07.ol.epicgames.com/content/api/pages/fortnite-game");
|
||||||
|
status = response.status;
|
||||||
|
data = await response.json();
|
||||||
|
} else {
|
||||||
|
status = 200;
|
||||||
|
data = FullFortnitePages;
|
||||||
|
}
|
||||||
|
/*const { status, data } = // check if 30 minutes have passed since last content update. if so, get a new copy of pages, if not, fuck off
|
||||||
FullFortnitePages === null || Date.now() > LastContentDownloadDate.getTime() + 30 * 60 * 1000 ?
|
FullFortnitePages === null || Date.now() > LastContentDownloadDate.getTime() + 30 * 60 * 1000 ?
|
||||||
await axios.get("https://fortnitecontent-website-prod07.ol.epicgames.com/content/api/pages/fortnite-game") :
|
await fetch("https://fortnitecontent-website-prod07.ol.epicgames.com/content/api/pages/fortnite-game") :
|
||||||
{ status: 200, data: FullFortnitePages };
|
FullFortnitePages;*/
|
||||||
|
|
||||||
|
let OGSparks;
|
||||||
|
|
||||||
|
if (OriginalSparks === null || Date.now() > LastContentDownloadDate.getTime() + 30 * 60 * 1000) {
|
||||||
|
const response = await fetch("https://fortnitecontent-website-prod07.ol.epicgames.com/content/api/pages/fortnite-game/spark-tracks");
|
||||||
|
OGSparks = {status: 200, data: await response.json()}
|
||||||
|
} else {
|
||||||
|
OGSparks = OriginalSparks
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const OGSparks =
|
|
||||||
OriginalSparks === null || Date.now() > LastContentDownloadDate.getTime() + 30 * 60 * 1000 ?
|
|
||||||
await axios.get("https://fortnitecontent-website-prod07.ol.epicgames.com/content/api/pages/fortnite-game/spark-tracks") :
|
|
||||||
{ status: 200, data: OriginalSparks };
|
|
||||||
|
|
||||||
FullFortnitePages = {
|
FullFortnitePages = {
|
||||||
...data,
|
...data,
|
||||||
|
|
|
@ -16,7 +16,7 @@ declare global {
|
||||||
export function RequireAuthentication(Relations?: object) {
|
export function RequireAuthentication(Relations?: object) {
|
||||||
return async (req: Request, res: Response, next: NextFunction) => {
|
return async (req: Request, res: Response, next: NextFunction) => {
|
||||||
if (!req.header("X-Partypack-Token") && !req.cookies["Token"] && !req.header("Authorization"))
|
if (!req.header("X-Partypack-Token") && !req.cookies["Token"] && !req.header("Authorization"))
|
||||||
return res.status(401).send("This endpoint requires authorization.");
|
return res.status(401).send("You must be logged in to perform this action.");
|
||||||
|
|
||||||
let JWT: JwtPayload;
|
let JWT: JwtPayload;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { ForcedCategory } from "../Schemas/ForcedCategory";
|
||||||
import { DiscordRole } from "../Schemas/DiscordRole";
|
import { DiscordRole } from "../Schemas/DiscordRole";
|
||||||
import { Bot } from "../Handlers/DiscordBot";
|
import { Bot } from "../Handlers/DiscordBot";
|
||||||
import { DISCORD_SERVER_ID } from "../Modules/Constants";
|
import { DISCORD_SERVER_ID } from "../Modules/Constants";
|
||||||
|
import { MisconfiguredDiscordBot, MissingDatabaseRole, MissingServerRole, MissingPermissions } from "../Modules/Errors";
|
||||||
|
|
||||||
const App = Router();
|
const App = Router();
|
||||||
|
|
||||||
|
@ -19,8 +20,8 @@ App.use(RequireAuthentication());
|
||||||
|
|
||||||
App.use((req, res, next) => {
|
App.use((req, res, next) => {
|
||||||
if (req.user!.PermissionLevel! < UserPermissions.Administrator)
|
if (req.user!.PermissionLevel! < UserPermissions.Administrator)
|
||||||
return res.status(403).send("You don't have permission to access this endpoint.");
|
//return res.status(403).send("You don't have permission to access this endpoint.");
|
||||||
|
return res.status(403).json(new MissingPermissions().errorJSON()).set('X-PartyPacker-ErrorString', new MissingPermissions().errorString());
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -32,10 +33,11 @@ ValidateBody(j.object({
|
||||||
})),
|
})),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
if (!Bot.isReady())
|
if (!Bot.isReady())
|
||||||
return res.status(500).send("This Partypack instance has a misconfigured Discord bot.");
|
//return res.status(503).send("This Partypack instance has a misconfigured Discord bot.");
|
||||||
|
return res.status(503).json(new MisconfiguredDiscordBot().errorJSON()).set('X-PartyPacker-ErrorString', new MisconfiguredDiscordBot().errorString());
|
||||||
if (!Bot.guilds.cache.get(DISCORD_SERVER_ID as string)?.roles.cache.has(req.body.ID))
|
if (!Bot.guilds.cache.get(DISCORD_SERVER_ID as string)?.roles.cache.has(req.body.ID))
|
||||||
return res.status(404).send("This role does not exist in the Discord server.");
|
//return res.status(400).send("This role does not exist in the Discord server.");
|
||||||
|
return res.status(400).json(new MissingServerRole().errorJSON()).set('X-PartyPacker-ErrorString', new MissingServerRole().errorString());
|
||||||
|
|
||||||
const Existing = await DiscordRole.findOne({ where: { ID: req.body.ID } });
|
const Existing = await DiscordRole.findOne({ where: { ID: req.body.ID } });
|
||||||
if (Existing) {
|
if (Existing) {
|
||||||
|
@ -61,10 +63,12 @@ ValidateBody(j.object({
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const RoleData = await DiscordRole.findOne({ where: { ID: req.body.ID } });
|
const RoleData = await DiscordRole.findOne({ where: { ID: req.body.ID } });
|
||||||
if (!RoleData)
|
if (!RoleData)
|
||||||
return res.status(404).send("This role does not exist in the database.");
|
//return res.status(404).json(new MissingDatabaseRole());
|
||||||
|
return res.status(404).json(new MissingDatabaseRole().errorJSON()).set('X-PartyPacker-ErrorString', new MissingDatabaseRole().errorString());
|
||||||
|
|
||||||
|
|
||||||
await RoleData.remove();
|
await RoleData.remove();
|
||||||
res.send("Removed role successfully.");
|
res.send.status(204);
|
||||||
})
|
})
|
||||||
|
|
||||||
App.get("/roles", async (_, res) => res.json((await DiscordRole.find()).map(x => x.Package(true))));
|
App.get("/roles", async (_, res) => res.json((await DiscordRole.find()).map(x => x.Package(true))));
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import axios from "axios";
|
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import qs from "querystring";
|
import qs from "querystring";
|
||||||
import j from "joi";
|
import j from "joi";
|
||||||
|
@ -16,31 +15,65 @@ const App = Router();
|
||||||
|
|
||||||
// ? hacky, if you want, make it less hacky
|
// ? hacky, if you want, make it less hacky
|
||||||
async function QuickRevokeToken(res: Response, Token: string) {
|
async function QuickRevokeToken(res: Response, Token: string) {
|
||||||
await axios.post("https://discord.com/api/oauth2/token/revoke", qs.stringify({ token: Token, token_type_hint: "access_token" }), { auth: { username: DISCORD_CLIENT_ID!, password: DISCORD_CLIENT_SECRET! } })
|
|
||||||
|
await fetch("https://discord.com/api/oauth2/token/revoke", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Authorization": `Basic ${Buffer.from(`${DISCORD_CLIENT_ID}:${DISCORD_CLIENT_SECRET}`).toString("base64")}`
|
||||||
|
},
|
||||||
|
body: qs.stringify({ token: Token, token_type_hint: "access_token" })
|
||||||
|
|
||||||
|
})
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
App.get("/discord/url", (_ ,res) => res.send(`https://discord.com/api/oauth2/authorize?client_id=${qs.escape(DISCORD_CLIENT_ID!)}&response_type=code&redirect_uri=${qs.escape(`${FULL_SERVER_ROOT}/api/discord`)}&scope=identify`))
|
App.get("/discord/url", (_, res) => res.send(`https://discord.com/api/oauth2/authorize?client_id=${qs.escape(DISCORD_CLIENT_ID!)}&response_type=code&redirect_uri=${qs.escape(`${FULL_SERVER_ROOT}/api/discord`)}&scope=identify`))
|
||||||
|
|
||||||
App.get("/discord",
|
App.get("/discord",
|
||||||
ValidateQuery(j.object({
|
ValidateQuery(j.object({
|
||||||
code: j.string().pattern(/^(\w|\d)+$/i).required(),
|
code: j.string().pattern(/^(\w|\d)+$/i).required(),
|
||||||
state: j.string()
|
state: j.string()
|
||||||
})),
|
})),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const Discord = await axios.post(`https://discord.com/api/oauth2/token`, qs.stringify({ grant_type: "authorization_code", code: req.query.code as string, redirect_uri: `${FULL_SERVER_ROOT}/api/discord` }), { auth: { username: DISCORD_CLIENT_ID!, password: DISCORD_CLIENT_SECRET! } });
|
|
||||||
|
//const Discord = await axios.post(`https://discord.com/api/oauth2/token`, qs.stringify({ grant_type: "authorization_code", code: req.query.code as string, redirect_uri: `${FULL_SERVER_ROOT}/api/discord` }), { auth: { username: DISCORD_CLIENT_ID!, password: DISCORD_CLIENT_SECRET! } });
|
||||||
|
|
||||||
|
const Discord = await fetch(
|
||||||
|
"https://discord.com/api/oauth2/token",
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Authorization": `Basic ${Buffer.from(`${DISCORD_CLIENT_ID}:${DISCORD_CLIENT_SECRET}`).toString("base64")}`
|
||||||
|
},
|
||||||
|
body: qs.stringify({ grant_type: "authorization_code", code: req.query.code as string, redirect_uri: `${FULL_SERVER_ROOT}/api/discord` })
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
if (Discord.status !== 200)
|
if (Discord.status !== 200)
|
||||||
return res.status(500).send("Failed to request OAuth token from Discord's services.");
|
return res.status(500).send("Failed to request OAuth token from Discord's services.");
|
||||||
|
|
||||||
if (!Discord.data.scope.includes("identify"))
|
const DiscordData = await Discord.json() as any; // :waaaaa:
|
||||||
return (await QuickRevokeToken(res, Discord.data.access_token)).status(400).send("Missing identify scope. Please check if your OAuth link is correctly set up!");
|
|
||||||
|
if (!DiscordData.scope.includes("identify"))
|
||||||
|
return (await QuickRevokeToken(res, DiscordData.access_token)).status(400).send("Missing identify scope. Please check if your OAuth link is correctly set up!");
|
||||||
|
|
||||||
|
|
||||||
|
const UserData = await fetch("https://discord.com/api/v10/users/@me", {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Authorization": `${DiscordData.token_type} ${DiscordData.access_token}`
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
const UserDataBody = await UserData.json() as any;
|
||||||
|
|
||||||
const UserData = await axios.get(`https://discord.com/api/users/@me`, { headers: { Authorization: `${Discord.data.token_type} ${Discord.data.access_token}` } });
|
|
||||||
if (UserData.status !== 200)
|
if (UserData.status !== 200)
|
||||||
return (await QuickRevokeToken(res, Discord.data.access_token)).status(500).send("Failed to request user data from Discord's services.");
|
return (await QuickRevokeToken(res, DiscordData.access_token)).status(500).send("Failed to request user data from Discord's services.");
|
||||||
|
|
||||||
await QuickRevokeToken(res, Discord.data.access_token);
|
await QuickRevokeToken(res, DiscordData.access_token);
|
||||||
|
|
||||||
const AnyUserExists = await User.exists(); // automatically grant the first user on the database administrator permissions
|
const AnyUserExists = await User.exists(); // automatically grant the first user on the database administrator permissions
|
||||||
let UserPermissionLevel = !AnyUserExists ? UserPermissions.Administrator : UserPermissions.User;
|
let UserPermissionLevel = !AnyUserExists ? UserPermissions.Administrator : UserPermissions.User;
|
||||||
|
@ -49,38 +82,37 @@ async (req, res) => {
|
||||||
Debug("Using Discord roles to determine user permission level since the Discord bot exists and is ready.");
|
Debug("Using Discord roles to determine user permission level since the Discord bot exists and is ready.");
|
||||||
|
|
||||||
const Sewer = Bot.guilds.cache.get(DISCORD_SERVER_ID as string);
|
const Sewer = Bot.guilds.cache.get(DISCORD_SERVER_ID as string);
|
||||||
const Membuh = await Sewer?.members.fetch(UserData.data.id);
|
const Membuh = await Sewer?.members.fetch(UserDataBody.id);
|
||||||
|
|
||||||
if (Membuh) {
|
if (Membuh) {
|
||||||
const RoulInDeightabaise = await DiscordRole.find({ where: { ID: In(Membuh.roles.cache.map(x => x.id)) }, order: { GrantedPermissions: "DESC" } });
|
const RoulInDeightabaise = await DiscordRole.find({ where: { ID: In(Membuh.roles.cache.map(x => x.id)) }, order: { GrantedPermissions: "DESC" } });
|
||||||
if (RoulInDeightabaise.length > 0)
|
if (RoulInDeightabaise.length > 0)
|
||||||
UserPermissionLevel = RoulInDeightabaise[0].GrantedPermissions;
|
UserPermissionLevel = RoulInDeightabaise[0].GrantedPermissions;
|
||||||
|
|
||||||
Debug(`Detected ${magenta(RoulInDeightabaise.length)} roles that override Database permissions for user ${magenta(`@${UserData.data.username}`)}. Giving permission level ${magenta(UserPermissionLevel)}.`)
|
Debug(`Detected ${magenta(RoulInDeightabaise.length)} roles that override Database permissions for user ${magenta(`@${UserDataBody.username}`)}. Giving permission level ${magenta(UserPermissionLevel)}.`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let DBUser = await User.findOne({ where: { ID: UserData.data.id } });
|
let DBUser = await User.findOne({ where: { ID: UserDataBody.id } });
|
||||||
if (!DBUser)
|
if (!DBUser)
|
||||||
DBUser = await User.create({
|
DBUser = await User.create({
|
||||||
ID: UserData.data.id,
|
ID: UserDataBody.id,
|
||||||
Username: UserData.data.username,
|
Username: UserDataBody.username,
|
||||||
DisplayName: UserData.data.global_name ?? UserData.data.username,
|
DisplayName: UserDataBody.global_name ?? UserDataBody.username,
|
||||||
ProfilePictureURL: `https://cdn.discordapp.com/avatars/${UserData.data.id}/${UserData.data.avatar}.webp`,
|
ProfilePictureURL: `https://cdn.discordapp.com/avatars/${UserDataBody.id}/${UserDataBody.avatar}.webp`,
|
||||||
Library: [],
|
Library: [],
|
||||||
PermissionLevel: UserPermissionLevel
|
PermissionLevel: UserPermissionLevel
|
||||||
}).save();
|
}).save();
|
||||||
else
|
else {
|
||||||
{
|
DBUser.Username = UserDataBody.username;
|
||||||
DBUser.Username = UserData.data.username;
|
DBUser.DisplayName = UserDataBody.global_name ?? UserDataBody.username;
|
||||||
DBUser.DisplayName = UserData.data.global_name ?? UserData.data.username;
|
DBUser.ProfilePictureURL = `https://cdn.discordapp.com/avatars/${UserDataBody.id}/${UserDataBody.avatar}.webp`;
|
||||||
DBUser.ProfilePictureURL = `https://cdn.discordapp.com/avatars/${UserData.data.id}/${UserData.data.avatar}.webp`;
|
|
||||||
DBUser.PermissionLevel = UserPermissionLevel;
|
DBUser.PermissionLevel = UserPermissionLevel;
|
||||||
await DBUser.save();
|
await DBUser.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
const JWT = jwt.sign({ ID: UserData.data.id }, JWT_KEY!, { algorithm: "HS256" });
|
const JWT = jwt.sign({ ID: UserDataBody.id }, JWT_KEY!, { algorithm: "HS256" });
|
||||||
const UserDetails = Buffer.from(JSON.stringify({ ID: UserData.data.id, Username: UserData.data.username, GlobalName: UserData.data.global_name, Avatar: `https://cdn.discordapp.com/avatars/${UserData.data.id}/${UserData.data.avatar}.webp`, IsAdmin: DBUser.PermissionLevel >= UserPermissions.Administrator, Role: DBUser.PermissionLevel })).toString("hex")
|
const UserDetails = Buffer.from(JSON.stringify({ ID: UserDataBody.id, Username: UserDataBody.username, GlobalName: UserDataBody.global_name, Avatar: `https://cdn.discordapp.com/avatars/${UserDataBody.id}/${UserDataBody.avatar}.webp`, IsAdmin: DBUser.PermissionLevel >= UserPermissions.Administrator, Role: DBUser.PermissionLevel })).toString("hex")
|
||||||
if (req.query.state) {
|
if (req.query.state) {
|
||||||
try {
|
try {
|
||||||
const Decoded = JSON.parse(Buffer.from(decodeURI(req.query.state as string), "base64").toString("utf-8"));
|
const Decoded = JSON.parse(Buffer.from(decodeURI(req.query.state as string), "base64").toString("utf-8"));
|
||||||
|
@ -97,7 +129,7 @@ async (req, res) => {
|
||||||
.cookie("Token", JWT)
|
.cookie("Token", JWT)
|
||||||
.cookie("UserDetails", UserDetails)
|
.cookie("UserDetails", UserDetails)
|
||||||
.redirect(`${DASHBOARD_ROOT}/profile`);
|
.redirect(`${DASHBOARD_ROOT}/profile`);
|
||||||
})
|
})
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
App,
|
App,
|
||||||
|
|
|
@ -73,7 +73,7 @@ async (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
App.get("/:InternalID",
|
App.get("/:InternalID",
|
||||||
RequireAuthentication()
|
RequireAuthentication(),
|
||||||
async (req, res, next) => {
|
async (req, res, next) => {
|
||||||
const SongData = await Song.findOne({ where: { ID: req.params.InternalID }, relations: { Author: true } });
|
const SongData = await Song.findOne({ where: { ID: req.params.InternalID }, relations: { Author: true } });
|
||||||
if (!SongData)
|
if (!SongData)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import { FullFortnitePages, GenerateFortnitePages } from "../Modules/FNUtil";
|
import { FullFortnitePages, GenerateFortnitePages } from "../Modules/FNUtil";
|
||||||
import axios from "axios";
|
|
||||||
import { IS_DEBUG } from "../Modules/Constants";
|
import { IS_DEBUG } from "../Modules/Constants";
|
||||||
import { RequireAuthentication } from "../Modules/Middleware";
|
import { RequireAuthentication } from "../Modules/Middleware";
|
||||||
|
|
||||||
|
@ -42,11 +41,11 @@ App.get("/content/api/pages/fortnite-game/:Section", RequireAuthentication(), as
|
||||||
if (!CachedSection)
|
if (!CachedSection)
|
||||||
return res.status(404).send("funny section not found haha kill me");
|
return res.status(404).send("funny section not found haha kill me");
|
||||||
|
|
||||||
const ContentFromServer = await axios.get(`https://fortnitecontent-website-prod07.ol.epicgames.com/content/api/pages/fortnite-game/${CachedSection._title}`);
|
const ContentFromServer = await fetch(`https://fortnitecontent-website-prod07.ol.epicgames.com/content/api/pages/fortnite-game/${CachedSection._title}`)
|
||||||
if (ContentFromServer.status !== 200)
|
if (ContentFromServer.status !== 200)
|
||||||
return res.status(404).json({ error: IS_DEBUG ? ContentFromServer.data : "Fortnite server returned an error." });
|
return res.status(404).json({ error: IS_DEBUG ? await ContentFromServer.text() : "Fortnite server returned an error." });
|
||||||
|
|
||||||
res.json(ContentFromServer.data);
|
res.json(await ContentFromServer.json());
|
||||||
})
|
})
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
88
Server/package-lock.json
generated
88
Server/package-lock.json
generated
|
@ -10,7 +10,6 @@
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node-cron": "^3.0.11",
|
"@types/node-cron": "^3.0.11",
|
||||||
"axios": "^1.6.5",
|
|
||||||
"better-sqlite3": "^9.3.0",
|
"better-sqlite3": "^9.3.0",
|
||||||
"colorette": "^2.0.20",
|
"colorette": "^2.0.20",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
|
@ -34,7 +33,7 @@
|
||||||
"@types/express": "^4.17.18",
|
"@types/express": "^4.17.18",
|
||||||
"@types/fluent-ffmpeg": "^2.1.24",
|
"@types/fluent-ffmpeg": "^2.1.24",
|
||||||
"@types/jsonwebtoken": "^9.0.5",
|
"@types/jsonwebtoken": "^9.0.5",
|
||||||
"@types/node": "^20.6.3",
|
"@types/node": "^20.11.16",
|
||||||
"@types/underscore": "^1.11.15",
|
"@types/underscore": "^1.11.15",
|
||||||
"@types/uuid": "^9.0.7",
|
"@types/uuid": "^9.0.7",
|
||||||
"tslib": "^2.6.2",
|
"tslib": "^2.6.2",
|
||||||
|
@ -335,9 +334,12 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "20.8.2",
|
"version": "20.11.16",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.16.tgz",
|
||||||
"integrity": "sha512-Vvycsc9FQdwhxE3y3DzeIxuEJbWGDsnrxvMADzTDF/lcdR9/K+AQIeAghTQsHtotg/q0j3WEOYS/jQgSdWue3w=="
|
"integrity": "sha512-gKb0enTmRCzXSSUJDq6/sPcqrfCv2mkkG6Jt/clpn5eiCbKTY+SgZUxo+p8ZKMof5dCp9vHQUAB7wOUTod22wQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"undici-types": "~5.26.4"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/node-cron": {
|
"node_modules/@types/node-cron": {
|
||||||
"version": "3.0.11",
|
"version": "3.0.11",
|
||||||
|
@ -466,21 +468,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz",
|
"resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz",
|
||||||
"integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg=="
|
"integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg=="
|
||||||
},
|
},
|
||||||
"node_modules/asynckit": {
|
|
||||||
"version": "0.4.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
|
||||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
|
||||||
},
|
|
||||||
"node_modules/axios": {
|
|
||||||
"version": "1.6.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.5.tgz",
|
|
||||||
"integrity": "sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg==",
|
|
||||||
"dependencies": {
|
|
||||||
"follow-redirects": "^1.15.4",
|
|
||||||
"form-data": "^4.0.0",
|
|
||||||
"proxy-from-env": "^1.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/balanced-match": {
|
"node_modules/balanced-match": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||||
|
@ -850,17 +837,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz",
|
"resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz",
|
||||||
"integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w=="
|
"integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w=="
|
||||||
},
|
},
|
||||||
"node_modules/combined-stream": {
|
|
||||||
"version": "1.0.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
|
||||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
|
||||||
"dependencies": {
|
|
||||||
"delayed-stream": "~1.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/content-disposition": {
|
"node_modules/content-disposition": {
|
||||||
"version": "0.5.4",
|
"version": "0.5.4",
|
||||||
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
|
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
|
||||||
|
@ -973,14 +949,6 @@
|
||||||
"node": ">=4.0.0"
|
"node": ">=4.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/delayed-stream": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
|
||||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.4.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/depd": {
|
"node_modules/depd": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
||||||
|
@ -1221,25 +1189,6 @@
|
||||||
"which": "bin/which"
|
"which": "bin/which"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/follow-redirects": {
|
|
||||||
"version": "1.15.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz",
|
|
||||||
"integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==",
|
|
||||||
"funding": [
|
|
||||||
{
|
|
||||||
"type": "individual",
|
|
||||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4.0"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"debug": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/foreground-child": {
|
"node_modules/foreground-child": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz",
|
||||||
|
@ -1255,19 +1204,6 @@
|
||||||
"url": "https://github.com/sponsors/isaacs"
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/form-data": {
|
|
||||||
"version": "4.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
|
||||||
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
|
||||||
"dependencies": {
|
|
||||||
"asynckit": "^0.4.0",
|
|
||||||
"combined-stream": "^1.0.8",
|
|
||||||
"mime-types": "^2.1.12"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/forwarded": {
|
"node_modules/forwarded": {
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||||
|
@ -1928,11 +1864,6 @@
|
||||||
"node": ">= 0.10"
|
"node": ">= 0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/proxy-from-env": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
|
||||||
},
|
|
||||||
"node_modules/pump": {
|
"node_modules/pump": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
|
||||||
|
@ -2620,6 +2551,11 @@
|
||||||
"node": ">=14.0"
|
"node": ">=14.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/undici-types": {
|
||||||
|
"version": "5.26.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
||||||
|
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
|
||||||
|
},
|
||||||
"node_modules/unpipe": {
|
"node_modules/unpipe": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
"@types/express": "^4.17.18",
|
"@types/express": "^4.17.18",
|
||||||
"@types/fluent-ffmpeg": "^2.1.24",
|
"@types/fluent-ffmpeg": "^2.1.24",
|
||||||
"@types/jsonwebtoken": "^9.0.5",
|
"@types/jsonwebtoken": "^9.0.5",
|
||||||
"@types/node": "^20.6.3",
|
"@types/node": "^20.11.16",
|
||||||
"@types/underscore": "^1.11.15",
|
"@types/underscore": "^1.11.15",
|
||||||
"@types/uuid": "^9.0.7",
|
"@types/uuid": "^9.0.7",
|
||||||
"tslib": "^2.6.2",
|
"tslib": "^2.6.2",
|
||||||
|
@ -42,7 +42,6 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node-cron": "^3.0.11",
|
"@types/node-cron": "^3.0.11",
|
||||||
"axios": "^1.6.5",
|
|
||||||
"better-sqlite3": "^9.3.0",
|
"better-sqlite3": "^9.3.0",
|
||||||
"colorette": "^2.0.20",
|
"colorette": "^2.0.20",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
|
|
10
package-lock.json
generated
10
package-lock.json
generated
|
@ -11,6 +11,7 @@
|
||||||
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
||||||
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
||||||
"@primer/react": "^36.5.0",
|
"@primer/react": "^36.5.0",
|
||||||
|
"@types/axios": "^0.14.0",
|
||||||
"axios": "^1.6.5",
|
"axios": "^1.6.5",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"deepmerge": "^4.3.1",
|
"deepmerge": "^4.3.1",
|
||||||
|
@ -1501,6 +1502,15 @@
|
||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/axios": {
|
||||||
|
"version": "0.14.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/axios/-/axios-0.14.0.tgz",
|
||||||
|
"integrity": "sha512-KqQnQbdYE54D7oa/UmYVMZKq7CO4l8DEENzOKc4aBRwxCXSlJXGz83flFx5L7AWrOQnmuN3kVsRdt+GZPPjiVQ==",
|
||||||
|
"deprecated": "This is a stub types definition for axios (https://github.com/mzabriskie/axios). axios provides its own type definitions, so you don't need @types/axios installed!",
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/babel__core": {
|
"node_modules/@types/babel__core": {
|
||||||
"version": "7.20.5",
|
"version": "7.20.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
||||||
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
||||||
"@primer/react": "^36.5.0",
|
"@primer/react": "^36.5.0",
|
||||||
|
"@types/axios": "^0.14.0",
|
||||||
"axios": "^1.6.5",
|
"axios": "^1.6.5",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"deepmerge": "^4.3.1",
|
"deepmerge": "^4.3.1",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user