Add contact antispam and fix gallery video playback.
English-only messages, rate limiting, min fill time, and normalized email validation; improve modal video serving with posters, correct MIME types, and no gzip on gallery media. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
51
app/internal/contactcheck/english.go
Normal file
51
app/internal/contactcheck/english.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package contactcheck
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/abadojack/whatlanggo"
|
||||
)
|
||||
|
||||
const (
|
||||
minMessageRunes = 20
|
||||
maxMessageRunes = 8000
|
||||
maxNameRunes = 120
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNotEnglish = errors.New("message must be in English")
|
||||
ErrTooShort = errors.New("message too short")
|
||||
ErrTooLong = errors.New("message too long")
|
||||
ErrName = errors.New("name too long")
|
||||
)
|
||||
|
||||
// ValidateEnglish checks script and language for name + message combined.
|
||||
func ValidateEnglish(name, message string) error {
|
||||
msg := strings.TrimSpace(message)
|
||||
nMsg := len([]rune(msg))
|
||||
if nMsg < minMessageRunes {
|
||||
return ErrTooShort
|
||||
}
|
||||
if nMsg > maxMessageRunes {
|
||||
return ErrTooLong
|
||||
}
|
||||
if len([]rune(strings.TrimSpace(name))) > maxNameRunes {
|
||||
return ErrName
|
||||
}
|
||||
|
||||
combined := strings.TrimSpace(name) + "\n\n" + msg
|
||||
info := whatlanggo.Detect(combined)
|
||||
|
||||
if info.Script != nil && info.Script != unicode.Latin {
|
||||
return ErrNotEnglish
|
||||
}
|
||||
if info.Lang != whatlanggo.Eng {
|
||||
return ErrNotEnglish
|
||||
}
|
||||
if !info.IsReliable() && info.Confidence < 0.55 {
|
||||
return ErrNotEnglish
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user