Start inserting game mod logs into D1

This commit is contained in:
2024-03-20 15:43:16 -04:00
parent 4edf232d90
commit 8e5ff1f974
5 changed files with 56 additions and 107 deletions

View File

@ -1,5 +1,4 @@
import { getBanList, setBanList } from "../../../roblox-open-cloud.js";
import { insertLogs } from "../../../gcloud.js";
import { jsonError } from "../../../common.js";
import sendEmail from "../../../email.js";
import { sendPushNotification } from "../../../gcloud.js";
@ -32,14 +31,35 @@ export async function onRequestPost(context: RequestContext) {
}
if (Object.values(logMap).length) {
await insertLogs(logMap, context.params.id as string, context);
const batchedQueries = [];
const statement = context.env.D1.prepare(
"INSERT INTO game_mod_logs (action, evidence, executed_at, executor, id, target) VALUES (?, ?, ?, ?, ?, ?);",
);
const actionMap: { [k: number]: string } = {
1: "blacklist",
2: "ban",
};
for (const [k, v] of Object.entries(logMap)) {
if (v === 0) continue;
batchedQueries.push(
statement.bind(actionMap[v]),
`https://carcrushers.cc/mod-queue?type=report&id=${context.params.id}`,
Date.now(),
context.data.current_user.id,
crypto.randomUUID(),
parseInt(k),
);
}
await context.env.D1.batch(batchedQueries);
const banList = (await getBanList(context)) as {
[k: string]: { BanType: number };
};
Object.assign(banList, newActions);
await setBanList(context, banList);
await setBanList(context, Object.assign(banList, newActions));
}
reportData.open = false;