Files
Noel Sabia 233fdbf66c feat: live SSE stage, phone view and presenter control
- proxy Go /api/stream through Nitro; drive /stage, /live, /plan and /forecast from scenario events
- fall back to 5 s polling after SSE failures or heartbeat silence; show Live/Polling/Offline
- authenticate /control and POST /api/scenario in Nitro with server-side control credentials
- add big-screen stage with local QR and a no-login phone recommendation view
- add SSE unit tests and a live smoke test; refresh README/Makefile
2026-11-14 06:59:07 +01:00

36 lines
1.0 KiB
TypeScript

import QRCode from 'qrcode'
/**
* Generate the /stage QR code locally. No third-party QR image service is
* called at runtime, so the big screen keeps working without internet access.
*/
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const text = typeof query.text === 'string' ? query.text.trim() : ''
if (!text) {
throw createError({ statusCode: 400, statusMessage: 'text is required' })
}
if (text.length > 1024) {
throw createError({ statusCode: 400, statusMessage: 'text is too long for a QR code' })
}
let svg: string
try {
svg = await QRCode.toString(text, {
type: 'svg',
margin: 1,
width: 320,
errorCorrectionLevel: 'M',
color: { dark: '#0f172a', light: '#ffffff' },
})
} catch {
throw createError({ statusCode: 400, statusMessage: 'could not encode text as a QR code' })
}
setResponseHeaders(event, {
'content-type': 'image/svg+xml; charset=utf-8',
'cache-control': 'public, max-age=300',
})
return svg
})