Persist Plutonium keys by server ID and add key management
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { listServerKeys, saveServerKey, removeServerKey, validServerId } from '$lib/server/fleet/server-keys.js';
|
||||
|
||||
export function GET() {
|
||||
return json({ keys: listServerKeys() }, { headers: { 'Cache-Control': 'no-store' } });
|
||||
}
|
||||
|
||||
export async function PUT({ request }: { request: Request }) {
|
||||
const body = await request.json().catch(() => null);
|
||||
try {
|
||||
saveServerKey(body?.serverId, body?.plutoKey);
|
||||
return json({ ok: true });
|
||||
} catch (err) {
|
||||
return json({ ok: false, error: (err as Error).message }, { status: 400 });
|
||||
}
|
||||
}
|
||||
|
||||
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) });
|
||||
}
|
||||
Reference in New Issue
Block a user