api: GET /api/system + POST /api/explore, OpenAPI spec updated in code

This commit is contained in:
2026-09-28 22:11:01 +00:00
parent 3aa27ffd89
commit 8153007668
4 changed files with 194 additions and 1 deletions
+28
View File
@@ -0,0 +1,28 @@
import { getGameDb } from '@/lib/db/client'
import { ExploreError, explorePlanet } from '@/lib/game/save'
// Scan one body of the current system. Body: { "planetId": number }. Returns the fresh
// system state plus what this scan found. Costs a turn; each body can only be scanned once.
export async function POST(req: Request) {
let body: unknown
try {
body = await req.json()
} catch {
return Response.json({ error: 'Invalid JSON body' }, { status: 400 })
}
const planetId = (body as { planetId?: unknown }).planetId
if (typeof planetId !== 'number' || !Number.isInteger(planetId)) {
return Response.json({ error: 'planetId must be an integer' }, { status: 400 })
}
try {
const db = await getGameDb()
return Response.json(await explorePlanet(db, planetId))
} catch (err) {
if (err instanceof ExploreError) {
return Response.json({ error: err.message }, { status: err.status })
}
throw err
}
}