Don't delete unactioned reports anymore

This commit is contained in:
regalijan 2023-10-19 16:51:15 -04:00
parent 1a35cca6cf
commit 733d74824d
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -1,5 +1,5 @@
import { getBanList, setBanList } from "../../../roblox-open-cloud.js"; import { getBanList, setBanList } from "../../../roblox-open-cloud.js";
import { GetAccessToken, insertLogs } from "../../../gcloud.js"; import { insertLogs } from "../../../gcloud.js";
import { jsonError } from "../../../common.js"; import { jsonError } from "../../../common.js";
import sendEmail from "../../../email.js"; import sendEmail from "../../../email.js";
@ -17,43 +17,6 @@ export async function onRequestPost(context: RequestContext) {
const logMap: { [k: string]: number } = {}; const logMap: { [k: string]: number } = {};
const { user } = reportData as ReportCardProps & { user?: { email: string } }; const { user } = reportData as ReportCardProps & { user?: { email: string } };
if (user?.email)
await sendEmail(
user.email,
context.env.MAILGUN_API_KEY,
"Report Processed",
"report_processed",
{
username: reportData.user?.username as string,
},
);
if (!Object.values(actionMap).find((action) => action !== 0)) {
await context.env.DATA.delete(`report_${reportId}`);
await context.env.D1.prepare("DELETE FROM reports WHERE id = ?;")
.bind(reportId)
.run();
const gcloudAccessToken = await GetAccessToken(context.env);
for (const attachment of reportData.attachments) {
await fetch(
`https://storage.googleapis.com/storage/v1/b/portal-carcrushers-cc/o/${encodeURIComponent(
attachment,
)}`,
{
headers: {
authorization: `Bearer ${gcloudAccessToken}`,
},
method: "DELETE",
},
);
}
return new Response(null, {
status: 204,
});
}
for (const [user, action] of Object.entries(actionMap)) { for (const [user, action] of Object.entries(actionMap)) {
if ( if (
isNaN(parseInt(user)) || isNaN(parseInt(user)) ||
@ -69,14 +32,16 @@ export async function onRequestPost(context: RequestContext) {
logMap[user] = action; logMap[user] = action;
} }
await insertLogs(logMap, context.params.id as string, context); if (Object.values(logMap).length) {
await insertLogs(logMap, context.params.id as string, context);
const banList = (await getBanList(context)) as { const banList = (await getBanList(context)) as {
[k: string]: { BanType: number }; [k: string]: { BanType: number };
}; };
Object.assign(banList, newActions); Object.assign(banList, newActions);
await setBanList(context, banList); await setBanList(context, banList);
}
reportData.open = false; reportData.open = false;
await context.env.DATA.put(`report_${reportId}`, JSON.stringify(reportData)); await context.env.DATA.put(`report_${reportId}`, JSON.stringify(reportData));
@ -84,6 +49,17 @@ export async function onRequestPost(context: RequestContext) {
.bind(reportId) .bind(reportId)
.run(); .run();
if (user?.email)
await sendEmail(
user.email,
context.env.MAILGUN_API_KEY,
"Report Processed",
"report_processed",
{
username: reportData.user?.username as string,
},
);
return new Response(null, { return new Response(null, {
status: 204, status: 204,
}); });