Skip to content
Permalink
dd2d9f2672
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
59 lines (52 sloc) 1.54 KB
import { jsonError } from "../../../common.js";
export async function onRequestPost(context: RequestContext) {
const { appeal } = context.data;
const body = new FormData();
body.append("from", "noreply@mail.carcrushers.cc");
body.append("to", appeal.user.email);
body.append("subject", "Appeal Denied");
body.append("template", "appeal_denied");
body.append("v:note", context.data.body.feedback || "No note provided.");
const emailReq = await fetch(
"https://api.mailgun.net/v3/mail.carcrushers.cc/messages",
{
body,
headers: {
authorization: `Basic ${btoa("api:" + context.env.MAILGUN_API_KEY)}`,
},
method: "POST",
},
);
if (!emailReq.ok) {
console.log(await emailReq.json());
return jsonError("Failed to deny appeal", 500);
}
await context.env.D1.prepare("UPDATE appeals SET open = 0 WHERE id = ?;")
.bind(context.params.id)
.run();
const { current_user: currentUser } = context.data;
await fetch(context.env.APPEALS_WEBHOOK, {
body: JSON.stringify({
embeds: [
{
title: "Appeal Denied",
color: 0xff0000,
description: `Appeal from user ${appeal.user.username} (${appeal.user.id}) was denied.`,
fields: [
{
name: "Moderator",
value: `${currentUser.username} (${currentUser.id})`,
},
],
},
],
}),
headers: {
"content-type": "application/json",
},
method: "POST",
});
return new Response(null, {
status: 204,
});
}