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:
@@ -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 })
|
||||
}
|
||||
Reference in New Issue
Block a user