Add first game appeal endpoints
This commit is contained in:
parent
db28e70b90
commit
f135368dc4
16
functions/api/game-appeals/metadata.ts
Normal file
16
functions/api/game-appeals/metadata.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { jsonError, jsonResponse } from "../../common.js";
|
||||||
|
import precheck from "./precheck.js";
|
||||||
|
|
||||||
|
export async function onRequestPost(context: RequestContext) {
|
||||||
|
const { id }: { id: any } = context.data.body;
|
||||||
|
|
||||||
|
if (typeof id !== "number") return jsonError("Invalid user id", 400);
|
||||||
|
|
||||||
|
const precheckData = await precheck(context, id);
|
||||||
|
|
||||||
|
if (precheckData.error) return jsonError(precheckData.error, 500);
|
||||||
|
|
||||||
|
const { can_appeal, reason } = precheckData;
|
||||||
|
|
||||||
|
return jsonResponse(JSON.stringify({ can_appeal, reason }));
|
||||||
|
}
|
66
functions/api/game-appeals/precheck.ts
Normal file
66
functions/api/game-appeals/precheck.ts
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import { queryLogs } from "../../gcloud.js";
|
||||||
|
import { getBanList } from "../../roblox-open-cloud.js";
|
||||||
|
|
||||||
|
export default async function (
|
||||||
|
context: RequestContext,
|
||||||
|
user: number,
|
||||||
|
): Promise<{ can_appeal?: boolean; error?: string; reason?: string }> {
|
||||||
|
if (
|
||||||
|
await context.env.D1.prepare("SELECT * FROM game_appeals WHERE open = 1 AND user = ?;")
|
||||||
|
.bind(user)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
can_appeal: false,
|
||||||
|
reason: "You have already submitted an appeal",
|
||||||
|
};
|
||||||
|
|
||||||
|
let banList;
|
||||||
|
|
||||||
|
try {
|
||||||
|
banList = (await getBanList(context)) as {
|
||||||
|
[k: number]: { BanType: number };
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
return {
|
||||||
|
error: "Failed to check your ban status",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!banList[user]?.BanType)
|
||||||
|
return {
|
||||||
|
can_appeal: false,
|
||||||
|
reason: "You do not appear to be banned",
|
||||||
|
};
|
||||||
|
|
||||||
|
let userLogs;
|
||||||
|
|
||||||
|
try {
|
||||||
|
userLogs = await queryLogs(user, context);
|
||||||
|
} catch {
|
||||||
|
return {
|
||||||
|
error: "Could not determine your eligibility",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
userLogs.sort((a, b) =>
|
||||||
|
parseInt(a.entity.properties.executed_at.integerValue) >
|
||||||
|
parseInt(b.entity.properties.executed_at.integerValue)
|
||||||
|
? -1
|
||||||
|
: 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
const allowedTime =
|
||||||
|
parseInt(userLogs[0].entity.properties.executed_at.integerValue) +
|
||||||
|
2592000000;
|
||||||
|
|
||||||
|
if (Date.now() < allowedTime)
|
||||||
|
return {
|
||||||
|
can_appeal: false,
|
||||||
|
reason: `You must wait until ${new Date(
|
||||||
|
allowedTime,
|
||||||
|
).toLocaleString()} to submit an appeal`,
|
||||||
|
};
|
||||||
|
|
||||||
|
return { can_appeal: true, reason: "" };
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user