Files
app
components
data
functions
api
admin-apps
appeals
auth
data-transfers
events-team
game-appeals
game-bans
gme
inactivity
infractions
me
mod-queue
reports
[id]
complete.ts
recall.ts
submit.ts
uploads
[[path]].ts
events.ts
webview-captcha.ts
_middleware.ts
common.ts
email.ts
gcloud.ts
permissions.ts
roblox-open-cloud.ts
public
.gitignore
.node-version
.prettierignore
OFL.txt
README.md
emotion-server.js
esbuild.config.js
index.css
index.d.ts
package-lock.json
package.json
remix.config.js
server.ts
theme.ts
tsconfig.json
car-crushers-portal/functions/api/reports/recall.ts

59 lines
1.7 KiB
TypeScript

import { GetAccessToken } from "../../gcloud.js";
import { jsonError } from "../../common.js";
export async function onRequestPost(context: RequestContext) {
const { id } = context.data.body;
if (!id) return jsonError("No ID provided", 400);
const reportUserId = await context.env.DATA.get(`reportprocessing_${id}`);
if (
!reportUserId ||
(context.data.current_user?.id !== reportUserId &&
context.request.headers.get("CF-Connecting-IP") !== reportUserId)
)
return jsonError("No processing report with that ID found", 404);
const data: { [k: string]: any } | null = await context.env.DATA.get(
`report_${id}`,
{ type: "json" },
);
if (!data) return jsonError("Report doesn't exist", 404);
const accessToken = await GetAccessToken(context.env);
const attachmentDeletePromises = [];
const existingAttachments = [...data.attachments];
for (const attachment of existingAttachments) {
if (!attachment.startsWith("t/")) data.attachments.push(`t/${attachment}`);
else data.attachments.push(attachment.replace("t/", ""));
}
for (const attachment of data.attachments)
attachmentDeletePromises.push(
fetch(
`https://storage.googleapis.com/storage/v1/b/portal-carcrushers-cc/o/${encodeURIComponent(
attachment,
)}`,
{
headers: {
authorization: `Bearer ${accessToken}`,
},
method: "DELETE",
},
),
);
await Promise.allSettled(attachmentDeletePromises);
await context.env.DATA.delete(`report_${id}`);
await context.env.D1.prepare("DELETE FROM reports WHERE id = ?;")
.bind(id)
.run();
return new Response(null, {
status: 204,
});
}