Move most email sending to common email function
This commit is contained in:
parent
86109eb770
commit
b5a92db954
@ -1,27 +1,20 @@
|
|||||||
import { jsonError } from "../../../common.js";
|
import { jsonError } from "../../../common.js";
|
||||||
|
import sendEmail from "../../../email.js";
|
||||||
|
|
||||||
export async function onRequestPost(context: RequestContext) {
|
export async function onRequestPost(context: RequestContext) {
|
||||||
const { appeal } = context.data;
|
const { appeal } = context.data;
|
||||||
const body = new FormData();
|
const emailResponse = await sendEmail(
|
||||||
body.append("from", "noreply@mail.carcrushers.cc");
|
appeal.user.email,
|
||||||
body.append("to", appeal.user.email);
|
context.env.MAILGUN_API_KEY,
|
||||||
body.append("subject", "Appeal Accepted");
|
"Appeal Accepted",
|
||||||
body.append("template", "appeal_accepted");
|
"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",
|
|
||||||
{
|
{
|
||||||
body,
|
note: context.data.body.feedback || "No note provided.",
|
||||||
headers: {
|
|
||||||
authorization: `Basic ${btoa("api:" + context.env.MAILGUN_API_KEY)}`,
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!emailReq.ok) {
|
if (!emailResponse.ok) {
|
||||||
console.log(await emailReq.json());
|
console.log(await emailResponse.json());
|
||||||
return jsonError("Failed to accept appeal", 500);
|
return jsonError("Failed to accept appeal", 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +24,12 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
.bind(context.params.id)
|
.bind(context.params.id)
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
|
delete appeal.user.email;
|
||||||
|
|
||||||
|
await context.env.DATA.put(`appeal_${appeal.id}`, JSON.stringify(appeal), {
|
||||||
|
expirationTtl: 94608000,
|
||||||
|
});
|
||||||
|
|
||||||
await fetch(
|
await fetch(
|
||||||
`https://discord.com/api/v10/guilds/242263977986359297/bans/${appeal.id}`,
|
`https://discord.com/api/v10/guilds/242263977986359297/bans/${appeal.id}`,
|
||||||
{
|
{
|
||||||
|
@ -1,27 +1,21 @@
|
|||||||
import { jsonError } from "../../../common.js";
|
import { jsonError } from "../../../common.js";
|
||||||
|
import sendEmail from "../../../email.js";
|
||||||
|
|
||||||
export async function onRequestPost(context: RequestContext) {
|
export async function onRequestPost(context: RequestContext) {
|
||||||
const { appeal } = context.data;
|
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(
|
const emailResponse = await sendEmail(
|
||||||
"https://api.mailgun.net/v3/mail.carcrushers.cc/messages",
|
appeal.user.email,
|
||||||
|
context.env.MAILGUN_API_KEY,
|
||||||
|
"Appeal Denied",
|
||||||
|
"appeal_denied",
|
||||||
{
|
{
|
||||||
body,
|
note: context.data.body.feedback || "No note provided.",
|
||||||
headers: {
|
|
||||||
authorization: `Basic ${btoa("api:" + context.env.MAILGUN_API_KEY)}`,
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!emailReq.ok) {
|
if (!emailResponse.ok) {
|
||||||
console.log(await emailReq.json());
|
console.log(await emailResponse.json());
|
||||||
return jsonError("Failed to deny appeal", 500);
|
return jsonError("Failed to deny appeal", 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { getBanList, setBanList } from "../../../roblox-open-cloud.js";
|
import { getBanList, setBanList } from "../../../roblox-open-cloud.js";
|
||||||
import { GetAccessToken, insertLogs } from "../../../gcloud.js";
|
import { GetAccessToken, insertLogs } from "../../../gcloud.js";
|
||||||
import { jsonError } from "../../../common.js";
|
import { jsonError } from "../../../common.js";
|
||||||
|
import sendEmail from "../../../email.js";
|
||||||
|
|
||||||
export async function onRequestPost(context: RequestContext) {
|
export async function onRequestPost(context: RequestContext) {
|
||||||
const reportId = context.params.id as string;
|
const reportId = context.params.id as string;
|
||||||
@ -14,6 +15,18 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
const actionMap = context.data.body;
|
const actionMap = context.data.body;
|
||||||
const newActions: { [k: string]: { BanType: number } } = {};
|
const newActions: { [k: string]: { BanType: number } } = {};
|
||||||
const logMap: { [k: string]: number } = {};
|
const logMap: { [k: string]: number } = {};
|
||||||
|
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)) {
|
if (!Object.values(actionMap).find((action) => action !== 0)) {
|
||||||
await context.env.DATA.delete(`report_${reportId}`);
|
await context.env.DATA.delete(`report_${reportId}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user