Get almost everything else
All checks were successful
Test, Build, Deploy / Test, Build, and Deploy (push) Successful in 55s
Test, Build, Deploy / Create Sentry Release (push) Successful in 6s

This commit is contained in:
2026-04-11 04:49:02 -04:00
parent fe206e2fbd
commit 5457898ff9
4 changed files with 101 additions and 78 deletions

View File

@@ -14,11 +14,12 @@ export async function onRequestPost(context: RequestContext) {
fcm_token, fcm_token,
); );
await context.env.D1.prepare( await context.data.prisma.pushNotification.delete({
"DELETE FROM push_notifications WHERE event_id = ? AND event_type = 'appeal';", where: {
) event_id: appeal.id,
.bind(appeal.id) event_type: "appeal",
.run(); },
});
} else { } else {
const emailResponse = await sendEmail( const emailResponse = await sendEmail(
appeal.user.email, appeal.user.email,
@@ -36,11 +37,8 @@ export async function onRequestPost(context: RequestContext) {
} }
} }
await context.env.D1.prepare( await context.data.prisma
"UPDATE appeals SET approved = 0, user = json_remove(user, '$.email') WHERE id = ?;", .$executeRaw`UPDATE appeals SET approved = FALSE, user = json_remove(user, '$.id') WHERE id = ${appeal.id};`;
)
.bind(context.params.id)
.run();
const { current_user: currentUser } = context.data; const { current_user: currentUser } = context.data;

View File

@@ -1,9 +1,11 @@
import { jsonResponse } from "../../common.js"; import { jsonResponse } from "../../common.js";
export async function onRequestGet(context: RequestContext) { export async function onRequestGet(context: RequestContext) {
const { results } = await context.env.D1.prepare( const results = await context.data.prisma.appealBan.findMany({
"SELECT * FROM appeal_bans ORDER BY created_by DESC;", orderBy: {
).all(); created_at: "desc",
},
});
return jsonResponse(JSON.stringify(results)); return jsonResponse(JSON.stringify(results));
} }

View File

@@ -1,4 +1,8 @@
import { jsonError, jsonResponse } from "../../../../common.js"; import { jsonError, jsonResponse } from "../../../../common.js";
import {
type JsonArray,
type JsonObject,
} from "../../../../../generated/prisma/internal/prismaNamespace.js";
export async function onRequestGet(context: RequestContext) { export async function onRequestGet(context: RequestContext) {
const { id, type } = context.params; const { id, type } = context.params;
@@ -6,57 +10,65 @@ export async function onRequestGet(context: RequestContext) {
if (!["appeal", "inactivity", "report"].includes(type as string)) if (!["appeal", "inactivity", "report"].includes(type as string))
return jsonError("Invalid type", 400); return jsonError("Invalid type", 400);
const tables: { [k: string]: string } = { const { prisma } = context.data;
appeal: "appeals", let item;
inactivity: "inactivity_notices",
report: "reports",
};
const data: Record<string, any> | null = await context.env.D1.prepare( switch (type as string) {
`SELECT * case "appeal":
FROM ${tables[type as string]} item = await prisma.appeal.findUnique({
WHERE id = ?;`, where: {
) id: id as string,
.bind(id) },
.first(); });
if (data?.user) data.user = JSON.parse(data.user); break;
if (!data || data.user?.id !== context.data.current_user.id) case "inactivity":
return jsonError("Item does not exist", 404); item = await prisma.inactivityNotice.findUnique({
where: {
id: id as string,
},
});
if (type === "inactivity") { break;
data.decisions = JSON.parse(data.decisions); case "report":
data.departments = JSON.parse(data.departments); item = await prisma.report.findUnique({
} where: {
id: id as string,
},
});
if (!item) break;
if (type === "report") {
data.attachments = JSON.parse(data.attachments);
data.target_ids = JSON.parse(data.target_ids);
data.target_usernames = JSON.parse(data.target_usernames);
const { AwsClient } = await import("aws4fetch"); const { AwsClient } = await import("aws4fetch");
const aws = new AwsClient({ const aws = new AwsClient({
accessKeyId: context.env.R2_ACCESS_KEY, accessKeyId: context.env.R2_ACCESS_KEY,
secretAccessKey: context.env.R2_SECRET_KEY, secretAccessKey: context.env.R2_SECRET_KEY,
}); });
let urlPromises = [];
let urls = []; for (const attachment of item.attachments as JsonArray) {
urlPromises.push(
for (const attachment of data.attachments) { aws.sign(
const { url } = await aws.sign(
`https://car-crushers.${context.env.R2_ZONE}.r2.cloudflarestorage.com/${attachment}?X-Amz-Expires=1800`, `https://car-crushers.${context.env.R2_ZONE}.r2.cloudflarestorage.com/${attachment}?X-Amz-Expires=1800`,
{ ),
aws: {
signQuery: true,
},
},
); );
}
const urls = (await Promise.all(urlPromises)).map((p) => p.url);
item = Object.defineProperty(item, "resolved_attachments", {
value: urls,
});
urls.push(url); break;
default:
break;
} }
data.resolved_attachments = urls; if (
} !item ||
(item.user as JsonObject | undefined)?.id !== context.data.current_user.id
)
return jsonError("Item does not exist", 404);
return jsonResponse(JSON.stringify(data)); return jsonResponse(JSON.stringify(item));
} }

View File

@@ -4,6 +4,7 @@ import sendEmail from "../../../email.js";
import { sendPushNotification } from "../../../gcloud.js"; import { sendPushNotification } from "../../../gcloud.js";
export async function onRequestPost(context: RequestContext) { export async function onRequestPost(context: RequestContext) {
const { prisma } = context.data;
const reportId = context.params.id as string; const reportId = context.params.id as string;
const report: { const report: {
[k: string]: any; [k: string]: any;
@@ -83,12 +84,15 @@ export async function onRequestPost(context: RequestContext) {
await setBanList(context, Object.assign(banList, newActions), etag); await setBanList(context, Object.assign(banList, newActions), etag);
} }
const pushNotificationData: Record<string, string> | null = const pushNotificationData = await prisma.pushNotification.findUnique({
await context.env.D1.prepare( select: {
"SELECT token FROM push_notifications WHERE event_id = ? AND event_type = 'report';", token: true,
) },
.bind(reportId) where: {
.first(); event_id: reportId,
event_type: "report",
},
});
if (user?.email) if (user?.email)
await sendEmail( await sendEmail(
@@ -100,26 +104,33 @@ export async function onRequestPost(context: RequestContext) {
username: user.username as string, username: user.username as string,
}, },
); );
else if (pushNotificationData) else if (pushNotificationData) {
await sendPushNotification( await sendPushNotification(
context.env, context.env,
"Report Processed", "Report Processed",
`Your report for ${JSON.parse(report.target_usernames).toString()} has been reviewed.`, `Your report for ${JSON.parse(report.target_usernames).toString()} has been reviewed.`,
pushNotificationData.token, pushNotificationData.token,
); );
await prisma.pushNotification.delete({
where: {
event_id: reportId,
event_type: "report",
},
});
}
delete (report.user as { email?: string; id: string; username: string }) delete (report.user as { email?: string; id: string; username: string })
?.email; ?.email;
await context.env.D1.prepare("UPDATE reports SET open = 0 WHERE id = ?;") await prisma.report.update({
.bind(reportId) data: {
.run(); open: false,
user: report.user,
await context.env.D1.prepare( },
"DELETE FROM push_notifications WHERE event_id = ? AND event_type = 'report';", where: {
) id: reportId,
.bind(reportId) },
.run(); });
return new Response(null, { return new Response(null, {
status: 204, status: 204,