api: GET /api/world + POST /api/jump, OpenAPI spec updated in code
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { getGameDb } from '@/lib/db/client'
|
||||
import { JumpError, jumpToSystem } from '@/lib/game/save'
|
||||
|
||||
// Jump to an adjacent solar system. Body: { "systemId": number }. Returns the fresh world state.
|
||||
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 systemId = (body as { systemId?: unknown }).systemId
|
||||
if (typeof systemId !== 'number' || !Number.isInteger(systemId)) {
|
||||
return Response.json({ error: 'systemId must be an integer' }, { status: 400 })
|
||||
}
|
||||
|
||||
try {
|
||||
const db = await getGameDb()
|
||||
return Response.json(await jumpToSystem(db, systemId))
|
||||
} catch (err) {
|
||||
if (err instanceof JumpError) {
|
||||
return Response.json({ error: err.message }, { status: err.status })
|
||||
}
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { getGameDb } from '@/lib/db/client'
|
||||
import { getWorldState } from '@/lib/game/save'
|
||||
|
||||
// The full world state for the single active save; auto-initializes on first hit.
|
||||
export async function GET() {
|
||||
const db = await getGameDb()
|
||||
return Response.json(await getWorldState(db))
|
||||
}
|
||||
Reference in New Issue
Block a user