0247c6cc38
- lib/data/zone-names.json: ZONE_NAMES (9156 zonas) exportado de zone_definitions.py. - lib/character-info.ts: getZoneName, getClassCss/getClassName, getRaceName y getCharacterImage (raza/clase/género -> /races/big-*.webp, con validación de compatibilidad clase-raza y fallback unknown), portado de account.py. - lib/account.ts: Character enriquecido (race, class, zone, imageUrl, class/raceName). - account page: tarjetas con imagen de raza, color de clase WoW, nivel, raza/clase, 📍 zona y oro. globals.css: colores de clase (.class-*). - public/races: 20 imágenes de raza del tema + unknown.webp. Verificado: build OK, imágenes 200, /account 307→login. El JSON de zonas se usa solo en servidor (no infla el bundle cliente). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
106 lines
2.7 KiB
TypeScript
106 lines
2.7 KiB
TypeScript
import type { RowDataPacket } from 'mysql2'
|
|
import { db, DB } from './db'
|
|
import type { SessionData } from './session'
|
|
import { getZoneName, getClassCss, getCharacterImage, getRaceName, getClassName } from './character-info'
|
|
|
|
export interface Character {
|
|
name: string
|
|
level: number
|
|
gold: number
|
|
silver: number
|
|
copper: number
|
|
race: number
|
|
classId: number
|
|
className: string
|
|
raceName: string
|
|
classCss: string
|
|
zone: string
|
|
imageUrl: string
|
|
}
|
|
|
|
export interface AccountDashboard {
|
|
bnetEmail: string
|
|
gameAccount: string
|
|
dp: number
|
|
vp: number
|
|
battlepayCredits: number
|
|
securityTokenDate: string | null
|
|
characters: Character[]
|
|
}
|
|
|
|
/** Datos del panel de cuenta. Resiliente si las BD de AzerothCore no están pobladas. */
|
|
export async function getAccountDashboard(session: SessionData): Promise<AccountDashboard> {
|
|
const accountId = session.accountId ?? 0
|
|
|
|
let dp = 0
|
|
let vp = 0
|
|
try {
|
|
const [p] = await db(DB.default).query<RowDataPacket[]>(
|
|
'SELECT dp, vp FROM home_api_points WHERE accountID = ?',
|
|
[accountId],
|
|
)
|
|
if (p[0]) {
|
|
dp = p[0].dp
|
|
vp = p[0].vp
|
|
}
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
|
|
let battlepayCredits = 0
|
|
try {
|
|
const [c] = await db(DB.auth).query<RowDataPacket[]>(
|
|
'SELECT battlePayCredits FROM battlenet_accounts WHERE id = ?',
|
|
[session.bnetId ?? 0],
|
|
)
|
|
if (c[0]?.battlePayCredits != null) battlepayCredits = c[0].battlePayCredits
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
|
|
let securityTokenDate: string | null = null
|
|
try {
|
|
const [s] = await db(DB.default).query<RowDataPacket[]>(
|
|
'SELECT created_at FROM home_securitytoken WHERE user_id = ? ORDER BY created_at DESC LIMIT 1',
|
|
[accountId],
|
|
)
|
|
if (s[0]) securityTokenDate = new Date(s[0].created_at).toISOString()
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
|
|
let characters: Character[] = []
|
|
try {
|
|
const [ch] = await db(DB.characters).query<RowDataPacket[]>(
|
|
'SELECT name, level, money, race, class, zone, gender FROM characters WHERE account = ?',
|
|
[accountId],
|
|
)
|
|
characters = ch.map((r) => ({
|
|
name: r.name,
|
|
level: r.level,
|
|
gold: Math.floor(r.money / 10000),
|
|
silver: Math.floor((r.money % 10000) / 100),
|
|
copper: r.money % 100,
|
|
race: r.race,
|
|
classId: r.class,
|
|
className: getClassName(r.class),
|
|
raceName: getRaceName(r.race),
|
|
classCss: getClassCss(r.class),
|
|
zone: getZoneName(r.zone),
|
|
imageUrl: getCharacterImage(r.class, r.race, r.gender),
|
|
}))
|
|
} catch {
|
|
/* la BD de personajes puede no estar poblada */
|
|
}
|
|
|
|
return {
|
|
bnetEmail: session.bnetEmail ?? '',
|
|
gameAccount: session.username ?? '',
|
|
dp,
|
|
vp,
|
|
battlepayCredits,
|
|
securityTokenDate,
|
|
characters,
|
|
}
|
|
}
|