fix: spam
This commit is contained in:
parent
8fa16c343c
commit
963b8c127d
2 changed files with 10 additions and 9 deletions
|
|
@ -14,10 +14,10 @@ import { isSpam } from '@/utils/detectSpam'
|
||||||
export async function send(toEmail: string, prevState: any, formData: FormData) {
|
export async function send(toEmail: string, prevState: any, formData: FormData) {
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
email: z.string().email(),
|
email: z.email().max(100),
|
||||||
subject: z.string(),
|
subject: z.string().max(150),
|
||||||
name: z.string(),
|
name: z.string().max(100),
|
||||||
message: z.string()
|
message: z.string().max(3000).min(30)
|
||||||
});
|
});
|
||||||
|
|
||||||
const validatedFields = schema.safeParse({
|
const validatedFields = schema.safeParse({
|
||||||
|
|
|
||||||
|
|
@ -15,18 +15,19 @@ const lngDetector = new LanguageDetect();
|
||||||
*/
|
*/
|
||||||
export const isSpam = (message: string): boolean => {
|
export const isSpam = (message: string): boolean => {
|
||||||
|
|
||||||
|
const trimmed = message.trim();
|
||||||
|
if (trimmed.length < 10 || trimmed.split(/\s+/).length < 5) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (message.includes('dreikoenige.berlin')) {
|
if (message.includes('dreikoenige.berlin')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.includes('https://') || message.includes('http://') || message.includes('$') || message.includes('www')) {
|
if (message.includes('https://') || message.includes('http://') || message.includes('$') || message.includes('www')) {
|
||||||
const language = lngDetector.detect(message)[0][0];
|
const language = lngDetector.detect(message.substring(0, 400))[0][0];
|
||||||
return language !== 'german';
|
return language !== 'german';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.split(" ").length < 5) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue