Pool Plutonium keys by game for launches and autoscaling

This commit is contained in:
2026-10-07 11:24:53 -04:00
parent 56e5a2d06d
commit ec45371478
47 changed files with 956 additions and 305 deletions
+9 -5
View File
@@ -1,5 +1,5 @@
import { json } from '@sveltejs/kit';
import { listServerKeys, saveServerKey, removeServerKey, validServerId } from '$lib/server/fleet/server-keys.js';
import { listServerKeys, saveServerKey, removeServerKey } from '$lib/server/fleet/server-keys.js';
export function GET() {
return json({ keys: listServerKeys() }, { headers: { 'Cache-Control': 'no-store' } });
@@ -8,8 +8,8 @@ export function GET() {
export async function PUT({ request }: { request: Request }) {
const body = await request.json().catch(() => null);
try {
saveServerKey(body?.serverId, body?.plutoKey);
return json({ ok: true });
const id = saveServerKey(body?.game, body?.plutoKey, body?.label);
return json({ ok: true, id });
} catch (err) {
return json({ ok: false, error: (err as Error).message }, { status: 400 });
}
@@ -17,6 +17,10 @@ export async function PUT({ request }: { request: Request }) {
export async function DELETE({ request }: { request: Request }) {
const body = await request.json().catch(() => null);
if (!validServerId(body?.serverId)) return json({ error: 'Invalid server ID' }, { status: 400 });
return json({ ok: removeServerKey(body.serverId) });
if (typeof body?.id !== 'string' || !body.id.trim() || body.id.length > 128) return json({ error: 'Invalid key ID' }, { status: 400 });
try {
return json({ ok: removeServerKey(body.id) });
} catch (err) {
return json({ ok: false, error: (err as Error).message }, { status: 400 });
}
}