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

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