not ready for html message

This commit is contained in:
Nomi Nonsense (Nonszy) 2026-01-01 16:31:00 +07:00
parent 7cd5113ef0
commit 50461f1644
2 changed files with 14 additions and 8 deletions

View File

@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from "next/server";
import { rateLimited, sanitize, sendEmail } from "@/lib/server-utils";
import { rateLimited, sendEmail } from "@/lib/server-utils";
import { trimTooLong } from "@/lib/strings";
import validator from "validator";
@ -20,7 +20,8 @@ const validateInput = (data: any) => {
(
!data.name.trim() ||
!data.email.trim() ||
!validator.isEmail(data.email)
!validator.isEmail(data.email) ||
data.email.length > 30
) ||
!data.message.trim()
)
@ -56,11 +57,10 @@ export async function POST(req: NextRequest) {
}
try {
const name = trimTooLong(data.name as string, 20);
const rawMessage = trimTooLong(data.message, 5000);
const message = sanitize(validator.escape(rawMessage));
const email = data.anon || !data.email ? process.env.SMTP_USER : data.email;
const name = trimTooLong(data.anon || !data.name ? 'Anonymous' : data.name, 20);
await sendEmail(name, data.email, message);
await sendEmail(name, email, data.message);
return NextResponse.json({ status: "ok" });
}

View File

@ -4,6 +4,8 @@ import DOMPurify from "dompurify";
import { redis } from "./redis";
import { transporter } from "./mailer";
import { trimTooLong } from "./strings";
import { escape } from "validator";
export async function rateLimited(clientId: string) {
const key = `contact:${clientId}`;
@ -37,12 +39,16 @@ export async function validateTurnstile(token: string, remoteip: string) {
}
export async function sendEmail(name: string, email: string, message: string) {
const rawMessage = trimTooLong(message, 5000);
const messageHTML = sanitize(escape(rawMessage));
await transporter.sendMail({
from: `Nonszy Contact Form <${process.env.SMTP_USER}>`,
replyTo: email,
to: process.env.SMTP_REPLY,
subject: `Message from ${name}`,
text: message
subject: `[CONTACT_FORM] from ${name}`,
text: rawMessage,
// html: messageHTML
})
}