import { type NextRequest, NextResponse } from 'next/server' import { getSession } from '@/lib/session' import { getAccountCharactersForForum, getForumCharacterPick, setForumCharacterPick } from '@/lib/forum' export const runtime = 'nodejs' export const dynamic = 'force-dynamic' /** Lista de personajes de la cuenta + el fijado actualmente. */ export async function GET() { const session = await getSession() const accountId = session.accountId ?? 0 if (!accountId) return NextResponse.json({ characters: [], current: null }, { status: 401 }) const [characters, current] = await Promise.all([ getAccountCharactersForForum(accountId), getForumCharacterPick(accountId), ]) return NextResponse.json({ characters, current }) } /** Fija el personaje del foro para la cuenta en sesión. */ export async function POST(req: NextRequest) { const session = await getSession() const accountId = session.accountId ?? 0 if (!accountId) return NextResponse.json({ ok: false }, { status: 401 }) let guid = 0 try { const body = await req.json() guid = Number(body?.guid) || 0 } catch { /* body inválido */ } const ok = await setForumCharacterPick(accountId, guid) return NextResponse.json({ ok }, { status: ok ? 200 : 400 }) }