23 lines
1000 B
TypeScript
23 lines
1000 B
TypeScript
import { json } from '@sveltejs/kit';
|
|
import { getServer } from '$lib/server/fleet/servers.js';
|
|
import { gameLogKey, resolveLogPath } from '$lib/server/fleet/logs.js';
|
|
import { readServerChat } from '$lib/server/fleet/chat.js';
|
|
|
|
export async function GET({ params }: { params: { name: string } }) {
|
|
const headers = { 'Cache-Control': 'no-store' };
|
|
const server = getServer(params.name);
|
|
if (!server || server.destroyed_at) {
|
|
return json({ ok: false, reason: 'Server not found' }, { status: 404, headers });
|
|
}
|
|
const path = resolveLogPath(server.name, gameLogKey(server.name));
|
|
if (!path)
|
|
return json({ ok: false, reason: 'Path traversal rejected' }, { status: 400, headers });
|
|
|
|
try {
|
|
return json({ ok: true, ...(await readServerChat(server)) }, { headers });
|
|
} catch (error) {
|
|
console.error('Could not read server chat', error);
|
|
return json({ ok: false, reason: 'Could not read server chat' }, { status: 500, headers });
|
|
}
|
|
}
|