Skip to content
Permalink
7ec760efd4
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
77 lines (63 sloc) 2.16 KB
import { getBanList, setBanList } from "../../../roblox-open-cloud.js";
import { GetAccessToken, insertLogs } from "../../../gcloud.js";
import { jsonError } from "../../../common.js";
export async function onRequestPost(context: RequestContext) {
const reportId = context.params.id as string;
const reportData: ReportCardProps | null = await context.env.DATA.get(
`report_${reportId}`,
{ type: "json" },
);
if (!reportData) return jsonError("Report does not exist", 404);
const actionMap = context.data.body;
const newActions: { [k: string]: { BanType: number } } = {};
const logMap: { [k: string]: number } = {};
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)) {
if (
isNaN(parseInt(user)) ||
typeof action !== "number" ||
action < 0 ||
action > 2
)
return jsonError("Invalid action map", 400);
if (action === 0) continue;
newActions[user] = { BanType: action };
logMap[user] = action;
}
await insertLogs(logMap, context.params.id as string, context);
const banList = (await getBanList(context)) as {
[k: string]: { BanType: number };
};
Object.assign(banList, newActions);
await setBanList(context, banList);
reportData.open = false;
await context.env.DATA.put(`report_${reportId}`, JSON.stringify(reportData));
await context.env.D1.prepare("UPDATE reports SET open = 0 WHERE id = ?;")
.bind(reportId)
.run();
return new Response(null, {
status: 204,
});
}