Persist Plutonium keys by server ID and add key management

This commit is contained in:
2026-09-17 15:54:10 -04:00
parent e4505a3be8
commit ae173517b6
10 changed files with 305 additions and 19 deletions
+5 -7
View File
@@ -43,25 +43,23 @@ export async function POST({ request }: { request: Request }) {
gameMode?: string;
mapSlug?: string;
plutoKey?: string;
lobby?: number;
};
if (typeof body.gameMode !== 'string' || typeof body.mapSlug !== 'string' || typeof body.plutoKey !== 'string') {
if (!body || typeof body.gameMode !== 'string' || typeof body.mapSlug !== 'string' || (body.plutoKey !== undefined && typeof body.plutoKey !== 'string') || (body.lobby !== undefined && typeof body.lobby !== 'number')) {
return json(
{ ok: false, error: 'gameMode, mapSlug, and plutoKey are required strings', kind: 'bad-request' },
{ ok: false, error: 'gameMode and mapSlug are required strings; plutoKey and lobby are optional', kind: 'bad-request' },
{ status: 400 }
);
}
if (body.plutoKey.trim().length === 0) {
return json({ ok: false, error: 'plutoKey cannot be empty', kind: 'bad-request' }, { status: 400 });
}
const result = await createServer({
gameMode: body.gameMode as GameMode,
mapSlug: body.mapSlug,
plutoKey: body.plutoKey,
lobby: body.lobby,
createdBy: 'ui'
});
if (!result.ok) {
const status = result.kind === 'unconfigured' ? 503
const status = result.kind === 'bad-request' ? 400 : result.kind === 'unconfigured' ? 503
: result.kind === 'unknown-map' || result.kind === 'no-slot' || result.kind === 'no-port' ? 409
: 500;
return json({ ok: false, error: result.message, kind: result.kind }, { status });