Move most email sending to common email function
This commit is contained in:
@ -1,27 +1,20 @@
|
||||
import { jsonError } from "../../../common.js";
|
||||
import sendEmail from "../../../email.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 Accepted");
|
||||
body.append("template", "appeal_accepted");
|
||||
body.append("v:note", context.data.body.feedback || "No note provided.");
|
||||
|
||||
const emailReq = await fetch(
|
||||
"https://api.mailgun.net/v3/mail.carcrushers.cc/messages",
|
||||
const emailResponse = await sendEmail(
|
||||
appeal.user.email,
|
||||
context.env.MAILGUN_API_KEY,
|
||||
"Appeal Accepted",
|
||||
"appeal_accepted",
|
||||
{
|
||||
body,
|
||||
headers: {
|
||||
authorization: `Basic ${btoa("api:" + context.env.MAILGUN_API_KEY)}`,
|
||||
},
|
||||
method: "POST",
|
||||
note: context.data.body.feedback || "No note provided.",
|
||||
},
|
||||
);
|
||||
|
||||
if (!emailReq.ok) {
|
||||
console.log(await emailReq.json());
|
||||
if (!emailResponse.ok) {
|
||||
console.log(await emailResponse.json());
|
||||
return jsonError("Failed to accept appeal", 500);
|
||||
}
|
||||
|
||||
@ -31,6 +24,12 @@ export async function onRequestPost(context: RequestContext) {
|
||||
.bind(context.params.id)
|
||||
.run();
|
||||
|
||||
delete appeal.user.email;
|
||||
|
||||
await context.env.DATA.put(`appeal_${appeal.id}`, JSON.stringify(appeal), {
|
||||
expirationTtl: 94608000,
|
||||
});
|
||||
|
||||
await fetch(
|
||||
`https://discord.com/api/v10/guilds/242263977986359297/bans/${appeal.id}`,
|
||||
{
|
||||
|
@ -1,27 +1,21 @@
|
||||
import { jsonError } from "../../../common.js";
|
||||
import sendEmail from "../../../email.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",
|
||||
const emailResponse = await sendEmail(
|
||||
appeal.user.email,
|
||||
context.env.MAILGUN_API_KEY,
|
||||
"Appeal Denied",
|
||||
"appeal_denied",
|
||||
{
|
||||
body,
|
||||
headers: {
|
||||
authorization: `Basic ${btoa("api:" + context.env.MAILGUN_API_KEY)}`,
|
||||
},
|
||||
method: "POST",
|
||||
note: context.data.body.feedback || "No note provided.",
|
||||
},
|
||||
);
|
||||
|
||||
if (!emailReq.ok) {
|
||||
console.log(await emailReq.json());
|
||||
if (!emailResponse.ok) {
|
||||
console.log(await emailResponse.json());
|
||||
return jsonError("Failed to deny appeal", 500);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user