A self-hosted, Roblox-flavored game platform: browse/play published browser games, build them by hand or by describing them to an LLM. Fully independent from top-tickets — separate repo, DB, port (8082). - Auth: email+password accounts (argon2, httpOnly session cookies), no admin/agent split — every account can create and play. - Three game templates (quiz, clicker, maze), each a zod schema paired with a Phaser 4 Scene that renders purely from a validated instance of that schema — manual and AI-generated games hit the same renderer, so a saved game is always guaranteed to load and run. The maze schema BFS-validates that the exit is reachable from the start. - Manual constructor: per-template builder forms, draft/publish/edit/ delete, a launcher grid of published games, a full-bleed play page. - AI generation: Anthropic API key configured under Settings → AI (encrypted at rest, validated with a live call before saving, same shape as top-tickets' mailbox/LDAP settings). Generation uses the SDK's zodOutputFormat/messages.parse to force schema-shaped JSON output, with one retry feeding back the validation error. Output always prefills the manual builder for review — never auto-published blind. Clean, distinct error message when no key is configured yet (no silent fallback exists here, so it doesn't pretend one does). - Docker Compose on port 8082 (bakes in the busy_timeout=30000 SQLite pragma from day one — top-tickets hit this build-time race twice). Deferred: more templates/genres, drag-and-drop level editor, likes/ leaderboards, AI-generated sprite assets, multiplayer, moderation. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QcXH24ky6zjk2UyK5oZUPH
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
export const runtime = "nodejs";
|
|
|
|
import { NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { requireSession } from "@/lib/auth/require";
|
|
import { getGameById, updateGame, deleteGame } from "@/lib/games/service";
|
|
import { safeParseDefinition } from "@/lib/games/types";
|
|
|
|
const patchSchema = z.object({
|
|
title: z.string().min(1).max(120).optional(),
|
|
description: z.string().max(500).nullable().optional(),
|
|
definition: z.unknown().optional(),
|
|
status: z.enum(["draft", "published"]).optional(),
|
|
});
|
|
|
|
export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
const { session, response } = await requireSession();
|
|
if (!session) return response;
|
|
|
|
const { id } = await params;
|
|
const existing = await getGameById(id);
|
|
if (!existing || existing.ownerId !== session.user.id) {
|
|
return NextResponse.json({ error: "Not found" }, { status: 404 });
|
|
}
|
|
|
|
const body = await request.json().catch(() => null);
|
|
const parsed = patchSchema.safeParse(body);
|
|
if (!parsed.success) {
|
|
return NextResponse.json({ error: parsed.error.issues[0]?.message ?? "Invalid input" }, { status: 400 });
|
|
}
|
|
|
|
let definition = undefined;
|
|
if (parsed.data.definition !== undefined) {
|
|
const defResult = safeParseDefinition(existing.templateType, parsed.data.definition);
|
|
if (!defResult.success) {
|
|
return NextResponse.json({ error: defResult.error.issues[0]?.message ?? "Invalid definition" }, { status: 400 });
|
|
}
|
|
definition = defResult.data;
|
|
}
|
|
|
|
const game = await updateGame(id, session.user.id, {
|
|
title: parsed.data.title,
|
|
description: parsed.data.description,
|
|
definition,
|
|
status: parsed.data.status,
|
|
});
|
|
|
|
return NextResponse.json({ game });
|
|
}
|
|
|
|
export async function DELETE(_request: Request, { params }: { params: Promise<{ id: string }> }) {
|
|
const { session, response } = await requireSession();
|
|
if (!session) return response;
|
|
|
|
const { id } = await params;
|
|
const ok = await deleteGame(id, session.user.id);
|
|
if (!ok) {
|
|
return NextResponse.json({ error: "Not found" }, { status: 404 });
|
|
}
|
|
return NextResponse.json({ ok: true });
|
|
}
|