mirror of
https://github.com/OHTU-German-learning-website/OHTU-German-learning-website.git
synced 2026-10-12 19:13:51 +03:00
fix format
This commit is contained in:
@@ -51,4 +51,4 @@ export async function POST(req) {
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,63 +3,68 @@ const isDevelopment = process.env.NODE_ENV === "development";
|
||||
const isCI = process.env.CI === "true";
|
||||
|
||||
const settings = {
|
||||
hideToska: false,
|
||||
disableToska: true,
|
||||
color: "orange",
|
||||
header: "GRADESA",
|
||||
headerFontColor: "white",
|
||||
dryrun: false,
|
||||
hideToska: false,
|
||||
disableToska: true,
|
||||
color: "orange",
|
||||
header: "GRADESA",
|
||||
headerFontColor: "white",
|
||||
dryrun: false,
|
||||
};
|
||||
|
||||
const sendEmail = async ({ to, subject, text }) => {
|
||||
if (!to || !subject || !text) {
|
||||
throw new Error("Missing email fields: to, subject and text are required");
|
||||
}
|
||||
if (!to || !subject || !text) {
|
||||
throw new Error("Missing email fields: to, subject and text are required");
|
||||
}
|
||||
|
||||
const mail = {
|
||||
template: {
|
||||
from: "GRADESA",
|
||||
text,
|
||||
const mail = {
|
||||
template: {
|
||||
from: "GRADESA",
|
||||
text,
|
||||
},
|
||||
emails: [
|
||||
{
|
||||
to,
|
||||
subject,
|
||||
},
|
||||
],
|
||||
settings,
|
||||
};
|
||||
|
||||
if (isCI || isDevelopment) {
|
||||
console.info("Skipping email sending in CI/development", {
|
||||
to,
|
||||
subject,
|
||||
nodeEnv: process.env.NODE_ENV,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!process.env.PATE_TOKEN) {
|
||||
throw new Error("PATE_TOKEN missing");
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${PATE_URL}?token=${process.env.PATE_TOKEN}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
emails: [
|
||||
{
|
||||
to,
|
||||
subject,
|
||||
},
|
||||
],
|
||||
settings,
|
||||
};
|
||||
body: JSON.stringify(mail),
|
||||
}
|
||||
);
|
||||
|
||||
if (isCI || isDevelopment) {
|
||||
console.info("Skipping email sending in CI/development", {
|
||||
to,
|
||||
subject,
|
||||
nodeEnv: process.env.NODE_ENV,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!process.env.PATE_TOKEN) {
|
||||
throw new Error("PATE_TOKEN missing");
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${PATE_URL}?token=${process.env.PATE_TOKEN}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(mail),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorBody = await response.text();
|
||||
throw new Error(`PATE email sending failed with status ${response.status}: ${errorBody}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("PATE fetch error:", error);
|
||||
throw error;
|
||||
if (!response.ok) {
|
||||
const errorBody = await response.text();
|
||||
throw new Error(
|
||||
`PATE email sending failed with status ${response.status}: ${errorBody}`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("PATE fetch error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export default sendEmail;
|
||||
export default sendEmail;
|
||||
|
||||
Reference in New Issue
Block a user