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,6 +1,5 @@
import { getBanList } from "../../../roblox-open-cloud.js";
import { jsonError, jsonResponse } from "../../../common.js";
import { queryLogs } from "../../../gcloud.js";
export async function onRequestGet(context: RequestContext) {
const robloxUserReq = await fetch(
@ -52,12 +51,13 @@ export async function onRequestGet(context: RequestContext) {
else if (banData.BanType === 2) current_status = "Banned";
const response = {
history: (await queryLogs(users[0].id, context)).sort((a, b) =>
a.entity.properties.executed_at.integerValue <
b.entity.properties.executed_at.integerValue
? 1
: -1,
),
history: (
await context.env.D1.prepare(
"SELECT * FROM game_mod_logs WHERE target = ? ORDER BY executed_at DESC;",
)
.bind(users[0].id)
.all()
).results,
user: {
avatar: thumbnailRequest.ok
? (

View File

@ -1,5 +1,4 @@
import { getBanList, setBanList } from "../../../roblox-open-cloud.js";
import { insertLogs } from "../../../gcloud.js";
import { jsonError } from "../../../common.js";
export async function onRequestPost(context: RequestContext) {
@ -19,7 +18,18 @@ export async function onRequestPost(context: RequestContext) {
if (isNaN(parseInt(user))) return jsonError("Invalid user ID", 400);
await insertLogs({ [user]: 3 }, ticket_link, context);
await context.env.D1.prepare(
"INSERT INTO game_mod_logs (action, evidence, executed_at, executor, id, target) VALUES (?, ?, ?, ?, ?, ?);",
)
.bind(
"revoke",
ticket_link,
Date.now(),
context.data.current_user.id,
crypto.randomUUID(),
parseInt(user),
)
.run();
const banList = (await getBanList(context)) as {
[k: string]: { BanType: number };