( req: NextRequest, deps: FreebuffSessionDeps, )
| 271 | * caller's instance id (via X-Freebuff-Instance-Id) is used to detect |
| 272 | * takeover by another CLI on the same account. */ |
| 273 | export async function getFreebuffSession( |
| 274 | req: NextRequest, |
| 275 | deps: FreebuffSessionDeps, |
| 276 | ): Promise<NextResponse> { |
| 277 | const auth = await resolveUser(req, deps) |
| 278 | if ('error' in auth) return auth.error |
| 279 | |
| 280 | try { |
| 281 | const countryAccess = await getCountryAccess(auth.userId, req, deps) |
| 282 | logCountryAccess('GET', auth.userId, countryAccess, deps) |
| 283 | if (shouldHardBlockFreeModeAccess(countryAccess)) { |
| 284 | await endSessionForHardBlock(auth, deps) |
| 285 | return hardBlockedResponse(countryAccess) |
| 286 | } |
| 287 | const accessTier = getFreeModeAccessTier(countryAccess) |
| 288 | |
| 289 | const claimedInstanceId = |
| 290 | req.headers.get(FREEBUFF_INSTANCE_HEADER) ?? undefined |
| 291 | const state = await getSessionState({ |
| 292 | userId: auth.userId, |
| 293 | accessTier, |
| 294 | userEmail: auth.userEmail, |
| 295 | userBanned: auth.userBanned, |
| 296 | claimedInstanceId, |
| 297 | deps: deps.sessionDeps, |
| 298 | }) |
| 299 | if (state.status === 'none') { |
| 300 | return NextResponse.json( |
| 301 | { |
| 302 | status: 'none', |
| 303 | accessTier: state.accessTier, |
| 304 | message: 'Call POST to join the waiting room.', |
| 305 | queueDepthByModel: state.queueDepthByModel, |
| 306 | rateLimitsByModel: state.rateLimitsByModel, |
| 307 | ...toLimitedModeReason(countryAccess), |
| 308 | }, |
| 309 | { status: 200 }, |
| 310 | ) |
| 311 | } |
| 312 | // banned is terminal; 403 for the same reason as country_blocked — older |
| 313 | // CLIs that don't know this status treat it as a generic error. |
| 314 | const status = state.status === 'banned' ? 403 : 200 |
| 315 | return NextResponse.json(state, { status }) |
| 316 | } catch (error) { |
| 317 | return serverError(deps, 'GET', auth.userId, error) |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /** DELETE /api/v1/freebuff/session — end session / leave queue immediately. */ |
| 322 | export async function deleteFreebuffSession( |
no test coverage detected