somehwat AI CSS...but not good at all in teh slightest, logic works
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { createRoom } from '@/lib/rooms';
|
||||
import { rateLimit, getClientIdentifier } from '@/lib/rate-limit';
|
||||
import { createRoomSchema } from '@/lib/validation';
|
||||
import { z } from 'zod';
|
||||
|
||||
const createRoomSchema = z.object({
|
||||
teamMode: z.enum(['1', '2']).optional().default('2'),
|
||||
});
|
||||
|
||||
export async function POST(req: Request) {
|
||||
try {
|
||||
// Rate limit: max 5 rooms per IP per hour
|
||||
const clientId = getClientIdentifier(req);
|
||||
const rateLimitResult = rateLimit(`create:${clientId}`, 5, 3600000);
|
||||
|
||||
@@ -16,18 +19,17 @@ export async function POST(req: Request) {
|
||||
);
|
||||
}
|
||||
|
||||
// Validate request (empty body is fine for create)
|
||||
const body = await req.json().catch(() => ({}));
|
||||
createRoomSchema.parse(body);
|
||||
|
||||
const { code, moderatorId } = createRoom();
|
||||
const { teamMode } = createRoomSchema.parse(body);
|
||||
|
||||
const { code, moderatorId } = createRoom(parseInt(teamMode) as 1 | 2);
|
||||
|
||||
return NextResponse.json({
|
||||
code,
|
||||
moderatorId,
|
||||
remaining: rateLimitResult.remaining
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
} catch (error) {
|
||||
console.error('Create room error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to create room' },
|
||||
|
||||
Reference in New Issue
Block a user