import { createRouter } from '../../create-router'; import { sessionStatus, startSession, stopSession } from './session'; /** * Session control. The pixels do not come through here — they come through the websocket relay; this * is only "is it up, bring it up, take it down", plus the window size the panel needs to size its * canvas. */ export const minesweeperRouter = createRouter(); minesweeperRouter.get('/status', async (c) => c.json(await sessionStatus())); minesweeperRouter.post('/start', async (c) => { const status = await sessionStatus(); if (!status.installed) { return c.json({ error: 'Minesweeper is not installed on this server (wine-minesweeper is missing)' }, 501); } if (status.running) return c.json(status); const result = await startSession(); if (!result.ok) return c.json({ error: `Could not start the session: ${result.out.trim()}` }, 500); return c.json(await sessionStatus()); }); minesweeperRouter.post('/stop', async (c) => { await stopSession(); return c.json(await sessionStatus()); });