Foro: selector para fijar el personaje del autor

- Modal "Cambiar personaje" (diseño de la web) con filtro, avatar de raza,
  nombre en color de clase y subtítulo nivel/raza/clase.
- Barra "Publicas como: X · Cambiar personaje" sobre el formulario de respuesta
  (solo con sesión iniciada).
- Preferencia persistente en acore_web.forum_character (por cuenta), validada.
- resolvePosters usa el personaje fijado si existe; si no, el de más nivel.
- API /api/forum/character (GET lista + actual, POST fijar), gated por sesión.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 08:14:54 +00:00
parent bf9931e042
commit 0f6e0d514f
7 changed files with 311 additions and 4 deletions
+34
View File
@@ -0,0 +1,34 @@
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 })
}