fix long usernames

This commit is contained in:
Face 2025-06-02 11:17:22 +03:00
parent a80a1a4e5c
commit 8b0d04f372
2 changed files with 7 additions and 6 deletions

View file

@ -8,10 +8,6 @@ import { MAX_FILE_SIZE } from '$lib/data/constants';
import { isNameAppropriate } from '$lib/server/moderation'; import { isNameAppropriate } from '$lib/server/moderation';
async function validateInputs(name: string, bio: string, username: string, avatarFile: File | null) { async function validateInputs(name: string, bio: string, username: string, avatarFile: File | null) {
if (name && name.trim().length < 1) {
throw error(400, 'Name cannot be empty');
}
if (name && !(await isNameAppropriate(name.trim()))) { if (name && !(await isNameAppropriate(name.trim()))) {
throw error(400, 'Name contains inappropriate content'); throw error(400, 'Name contains inappropriate content');
} }
@ -54,11 +50,14 @@ export async function POST({ request }) {
} }
const formData = await request.formData(); const formData = await request.formData();
const name = (formData.get('name') as string)?.trim();
let name = (formData.get('name') as string)?.trim();
const bio = formData.get('bio') as string; const bio = formData.get('bio') as string;
const username = (formData.get('username') as string)?.toLowerCase().trim(); const username = (formData.get('username') as string)?.toLowerCase().trim();
const avatarFile = formData.get('avatar') as File | null; const avatarFile = formData.get('avatar') as File | null;
name = name?.trim().replace(/\s+/g, ' ');
await validateInputs(name, bio, username, avatarFile); await validateInputs(name, bio, username, avatarFile);
const updates: Record<string, any> = { const updates: Record<string, any> = {

View file

@ -5,11 +5,13 @@ import { eq } from 'drizzle-orm';
import { isNameAppropriate } from '$lib/server/moderation'; import { isNameAppropriate } from '$lib/server/moderation';
export async function GET({ url }) { export async function GET({ url }) {
const username = url.searchParams.get('username')?.toLowerCase().trim(); let username = url.searchParams.get('username')?.toLowerCase().trim();
if (!username) { if (!username) {
return json({ available: false }); return json({ available: false });
} }
username = username.trim().replace(/\s+/g, ' ');
if (username.length < 3 || username.length > 30) { if (username.length < 3 || username.length > 30) {
return json({ return json({
available: false, available: false,