Compare commits

..

3 Commits

2 changed files with 12 additions and 1 deletions

View File

@@ -28,7 +28,10 @@ async function sendOtp({ email, name }: OtpParams) {
SentEmails, SentEmails,
gte(SentEmails.sentAt, Date.now() - 1000 * 60 * 60 * 24), gte(SentEmails.sentAt, Date.now() - 1000 * 60 * 60 * 24),
); );
if (emailsSentLast24Hours > MAX_DAILY_EMAILS) { if (emailsSentLast24Hours >= MAX_DAILY_EMAILS) {
console.warn(
`${name} <${email}> requested an OTP, but ${emailsSentLast24Hours} have already been sent, whereas the max daily load is ${MAX_DAILY_EMAILS}.`,
);
throw new Error( throw new Error(
`${emailsSentLast24Hours} emails have been sent in the last 24 hours, but the max daily load is ${MAX_DAILY_EMAILS}.`, `${emailsSentLast24Hours} emails have been sent in the last 24 hours, but the max daily load is ${MAX_DAILY_EMAILS}.`,
); );
@@ -47,6 +50,10 @@ to do anything.`,
`Sent OTP (${otpPretty}) to ${email}. Message ID: ${info.messageId}`, `Sent OTP (${otpPretty}) to ${email}. Message ID: ${info.messageId}`,
); );
await db
.insert(SentEmails)
.values({ messageId: info.messageId, sentAt: Date.now() });
await db.insert(Otp).values({ await db.insert(Otp).values({
userId: email, userId: email,
value: otp, value: otp,

View File

@@ -61,6 +61,9 @@ async function sendmail({
gte(SentEmails.sentAt, Date.now() - 1000 * 60 * 60 * 24), gte(SentEmails.sentAt, Date.now() - 1000 * 60 * 60 * 24),
); );
if (emailsSentLast24Hours > MAX_DAILY_EMAILS) { if (emailsSentLast24Hours > MAX_DAILY_EMAILS) {
console.warn(
`${name} <${email}> tried to send an email, but ${emailsSentLast24Hours} have already been sent, whereas the max daily load is ${MAX_DAILY_EMAILS}.`,
);
throw new Error( throw new Error(
`${emailsSentLast24Hours} emails have been sent in the last 24 hours, but the max daily load is ${MAX_DAILY_EMAILS}.`, `${emailsSentLast24Hours} emails have been sent in the last 24 hours, but the max daily load is ${MAX_DAILY_EMAILS}.`,
); );
@@ -72,6 +75,7 @@ async function sendmail({
subject: `joeac.net: ${name} left a message`, subject: `joeac.net: ${name} left a message`,
text: `${name} <${email}> sent you a message:\n\n\n${message}`, text: `${name} <${email}> sent you a message:\n\n\n${message}`,
}); });
await db await db
.insert(SentEmails) .insert(SentEmails)
.values({ messageId: info.messageId, sentAt: Date.now() }); .values({ messageId: info.messageId, sentAt: Date.now() });