(req: NextRequest)
| 3 | |
| 4 | /** GET — poll session status (desktop polls this) */ |
| 5 | export async function GET(req: NextRequest) { |
| 6 | const sessionId = req.nextUrl.searchParams.get("sessionId"); |
| 7 | if (!sessionId) return NextResponse.json({ error: "missing sessionId" }, { status: 400 }); |
| 8 | |
| 9 | const session = getSession(sessionId); |
| 10 | if (!session) return NextResponse.json({ status: "waiting" }); |
| 11 | |
| 12 | // Consume the prompt on first read so duplicate polls don't re-trigger |
| 13 | if (session.status === "picked" && session.prompt) { |
| 14 | const prompt = session.prompt; |
| 15 | setSession(sessionId, { status: "picked" }); |
| 16 | return NextResponse.json({ status: "picked", prompt }); |
| 17 | } |
| 18 | |
| 19 | return NextResponse.json(session); |
| 20 | } |
| 21 | |
| 22 | /** PUT — mark session as scanned (mobile calls this on page load) */ |
| 23 | export async function PUT(req: NextRequest) { |
nothing calls this directly
no test coverage detected