(session: EncodedSession, token: string)
| 180 | } |
| 181 | |
| 182 | function establishSession(session: EncodedSession, token: string): Response { |
| 183 | if (sessionExpired(session.expiresAt)) { |
| 184 | return passwordShellResponse( |
| 185 | "Session expired", |
| 186 | "<p>This SimDeck CI session has expired. Re-run the workflow to create a new link.</p>", |
| 187 | 410, |
| 188 | ); |
| 189 | } |
| 190 | |
| 191 | const cookie: SessionCookie = { |
| 192 | upstream: session.upstream, |
| 193 | token, |
| 194 | device: session.device, |
| 195 | expiresAt: session.expiresAt, |
| 196 | }; |
| 197 | const target = new URL("https://simdeck.local/"); |
| 198 | if (session.device) { |
| 199 | target.searchParams.set("device", session.device); |
| 200 | } |
| 201 | target.searchParams.set("remoteStream", "1"); |
| 202 | |
| 203 | return new Response(null, { |
| 204 | status: 303, |
| 205 | headers: { |
| 206 | Location: `${target.pathname}${target.search}`, |
| 207 | "Set-Cookie": sessionCookie(cookie), |
| 208 | "Cache-Control": "no-store", |
| 209 | }, |
| 210 | }); |
| 211 | } |
| 212 | |
| 213 | async function proxyToSimDeck( |
| 214 | request: Request, |
no test coverage detected