KV to D1 migration (this is totally gonna break something)
This commit is contained in:
@ -7,13 +7,14 @@ export async function onRequestPost(context: RequestContext) {
|
||||
if (statsReduction && typeof statsReduction !== "number")
|
||||
return jsonError("Invalid stat reduction", 400);
|
||||
|
||||
const appeal = await context.env.DATA.get(
|
||||
`gameappeal_${context.params.id as string}`,
|
||||
);
|
||||
const appeal: Record<string, any> | null = await context.env.D1.prepare(
|
||||
"SELECT * FROM game_appeals WHERE id = ?;",
|
||||
)
|
||||
.bind(context.params.id)
|
||||
.first();
|
||||
|
||||
if (!appeal) return jsonError("Appeal not found", 400);
|
||||
|
||||
const data = JSON.parse(appeal);
|
||||
const banList = (await getBanList(context)) as {
|
||||
[k: string]: { BanType: number; Unbanned?: boolean; UnbanReduct?: number };
|
||||
};
|
||||
@ -23,12 +24,12 @@ export async function onRequestPost(context: RequestContext) {
|
||||
.bind(context.params.id)
|
||||
.run();
|
||||
|
||||
if (!banList[data.roblox_id])
|
||||
if (!banList[appeal.roblox_id])
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
});
|
||||
|
||||
banList[data.roblox_id] = {
|
||||
banList[appeal.roblox_id] = {
|
||||
BanType: 0,
|
||||
Unbanned: true,
|
||||
UnbanReduct: statsReduction,
|
||||
@ -43,7 +44,7 @@ export async function onRequestPost(context: RequestContext) {
|
||||
Date.now(),
|
||||
context.data.current_user.id,
|
||||
crypto.randomUUID(),
|
||||
data.roblox_id,
|
||||
appeal.roblox_id,
|
||||
)
|
||||
.run();
|
||||
|
||||
|
@ -3,18 +3,20 @@ import { jsonError } from "../../../common.js";
|
||||
export async function onRequestPost(context: RequestContext) {
|
||||
const appealId = context.params.id as string;
|
||||
|
||||
const appeal = await context.env.DATA.get(`gameappeal_${appealId}`);
|
||||
const appeal = await context.env.D1.prepare(
|
||||
"SELECT * FROM game_appeals WHERE id = ?;",
|
||||
)
|
||||
.bind(appealId)
|
||||
.first();
|
||||
|
||||
if (!appeal) return jsonError("Appeal not found", 404);
|
||||
|
||||
const appealData = JSON.parse(appeal);
|
||||
|
||||
await context.env.DATA.delete(`gameappeal_${appealId}`);
|
||||
await context.env.D1.prepare("DELETE FROM game_appeals WHERE id = ?;")
|
||||
.bind(appealId)
|
||||
.run();
|
||||
await context.env.DATA.put(
|
||||
`gameappealblock_${appealData.roblox_id}`,
|
||||
`gameappealblock_${appeal.roblox_id}`,
|
||||
`${Date.now() + 2592000000}`,
|
||||
{ expirationTtl: 2592000 },
|
||||
);
|
||||
|
@ -5,9 +5,7 @@ export default async function (
|
||||
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 = ?;",
|
||||
)
|
||||
await context.env.D1.prepare("SELECT * FROM game_appeals WHERE user = ?;")
|
||||
.bind(user)
|
||||
.first()
|
||||
)
|
||||
|
@ -43,25 +43,14 @@ export async function onRequestPost(context: RequestContext) {
|
||||
if (!precheckData.can_appeal)
|
||||
return jsonError(precheckData.reason as string, 400);
|
||||
|
||||
const appealId = `${id}${context.request.headers
|
||||
.get("cf-ray")
|
||||
?.split("-")[0]}${Date.now()}`;
|
||||
|
||||
await context.env.DATA.put(
|
||||
`gameappeal_${appealId}`,
|
||||
JSON.stringify({
|
||||
id: appealId,
|
||||
reasonForUnban,
|
||||
roblox_id: id,
|
||||
roblox_username: username,
|
||||
whatHappened,
|
||||
}),
|
||||
);
|
||||
const appealId = `${id}${
|
||||
context.request.headers.get("cf-ray")?.split("-")[0]
|
||||
}${Date.now()}`;
|
||||
|
||||
await context.env.D1.prepare(
|
||||
"INSERT INTO game_appeals (created_at, id, open, user) VALUES (?, ?, ?, ?);",
|
||||
"INSERT INTO game_appeals (created_at, id, reason_for_unban, roblox_id, roblox_username) VALUES (?, ?, ?, ?, ?);",
|
||||
)
|
||||
.bind(Date.now(), appealId, 1, id)
|
||||
.bind(Date.now(), appealId, reasonForUnban, id, username)
|
||||
.run();
|
||||
|
||||
await fetch(context.env.REPORTS_WEBHOOK, {
|
||||
|
Reference in New Issue
Block a user