Pool Plutonium keys by game for launches and autoscaling
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user