Compare commits
2 Commits
cae1b523f5
...
b1448ac30e
| Author | SHA1 | Date | |
|---|---|---|---|
|
b1448ac30e
|
|||
|
bd053908a4
|
39
functions/api/game-bans/notes/[id].ts
Normal file
39
functions/api/game-bans/notes/[id].ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { jsonError, jsonResponse } from "../../../common.js";
|
||||
|
||||
export async function onRequestDelete(context: RequestContext) {
|
||||
const noteId = context.params.id as string;
|
||||
const creatorIdResult: null | Record<string, string> =
|
||||
await context.env.D1.prepare(
|
||||
"SELECT created_by FROM game_mod_logs WHERE id = ?;",
|
||||
)
|
||||
.bind(noteId)
|
||||
.first();
|
||||
|
||||
if (creatorIdResult?.created_by !== context.data.current_user.id)
|
||||
return jsonError("Cannot delete notes that are not your own", 403);
|
||||
|
||||
await context.env.D1.prepare("DELETE FROM game_mod_logs WHERE id = ?;")
|
||||
.bind(noteId)
|
||||
.first();
|
||||
|
||||
return new Response(null, { status: 204 });
|
||||
}
|
||||
|
||||
export async function onRequestGet(context: RequestContext) {
|
||||
const noteId = context.params.id as string;
|
||||
const result = await context.env.D1.prepare(
|
||||
"SELECT * FROM game_mod_notes WHERE id = ?;",
|
||||
)
|
||||
.bind(noteId)
|
||||
.first();
|
||||
|
||||
if (!result) return jsonError("Note not found", 404);
|
||||
|
||||
const noteData = structuredClone(result);
|
||||
const gmeEntry: null | { time: number; user: string; name: string } =
|
||||
await context.env.DATA.get(`gamemod_${result.created_by}`, "json");
|
||||
|
||||
if (gmeEntry) noteData.creator_name = gmeEntry.name;
|
||||
|
||||
return jsonResponse(JSON.stringify(noteData));
|
||||
}
|
||||
@@ -20,7 +20,11 @@ export async function onRequestPost(context: RequestContext) {
|
||||
|
||||
if (!user.match(/^\d{17,19}$/)) return jsonError("Invalid User ID", 400);
|
||||
|
||||
const data = { time: Date.now(), user: context.data.current_user.id };
|
||||
const data = {
|
||||
time: Date.now(),
|
||||
user: context.data.current_user.id,
|
||||
name: context.data.current_user.username,
|
||||
};
|
||||
|
||||
await context.env.DATA.put(`gamemod_${user}`, JSON.stringify(data), {
|
||||
metadata: data,
|
||||
|
||||
Reference in New Issue
Block a user