ban-history: alcance y estado multiidioma

getSanctions devuelve claves (scopeKey account/battlenet/character + scopeName;
statusKey active/activePermanent/expired) en vez de español. La página traduce
alcance ("Character: {name}") y estado; "Permanente" ya usaba clave. Motivo y
autor son datos del GM (no se traducen). Nuevas claves History.ban.scope/status.
Verificado con sanciones de prueba (todos los combos resuelven en es y en).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-14 19:44:09 +00:00
parent 16ae9f0db8
commit 1d2aae5df2
4 changed files with 46 additions and 20 deletions
+6 -6
View File
@@ -20,10 +20,6 @@ function fmt(d: Date): string {
return `${p(d.getDate())}-${p(d.getMonth() + 1)}-${d.getFullYear()} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}` return `${p(d.getDate())}-${p(d.getMonth() + 1)}-${d.getFullYear()} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`
} }
function StatusCell({ s }: { s: Sanction }) {
return <span className={s.active ? 'red-info2' : 'green-info2'}>{s.status}</span>
}
/** Caja con la tabla de sanciones (baneos o muteos), o el vacío del diseño. */ /** Caja con la tabla de sanciones (baneos o muteos), o el vacío del diseño. */
async function SanctionBox({ async function SanctionBox({
title, title,
@@ -68,7 +64,11 @@ async function SanctionBox({
<tr key={i}> <tr key={i}>
{showScope && ( {showScope && (
<td> <td>
<span>{s.scope}</span> <span>
{s.scopeKey === 'character'
? t('ban.scope.character', { name: s.scopeName })
: t(`ban.scope.${s.scopeKey}`)}
</span>
</td> </td>
)} )}
<td> <td>
@@ -84,7 +84,7 @@ async function SanctionBox({
<span>{s.expires ? fmt(s.expires) : t('ban.permanent')}</span> <span>{s.expires ? fmt(s.expires) : t('ban.permanent')}</span>
</td> </td>
<td> <td>
<StatusCell s={s} /> <span className={s.active ? 'red-info2' : 'green-info2'}>{t(`ban.status.${s.statusKey}`)}</span>
</td> </td>
</tr> </tr>
))} ))}
+18 -12
View File
@@ -1,26 +1,31 @@
import type { RowDataPacket } from 'mysql2' import type { RowDataPacket } from 'mysql2'
import { db, DB } from './db' import { db, DB } from './db'
/** Una sanción (baneo o muteo) de la cuenta. */ /** Una sanción (baneo o muteo) de la cuenta. Textos visibles como claves i18n. */
export interface Sanction { export interface Sanction {
scope: string // 'Cuenta' | 'Battle.net' | 'Personaje: Nombre' scopeKey: 'account' | 'battlenet' | 'character'
reason: string scopeName: string // nombre del personaje (solo para scopeKey='character')
by: string reason: string // motivo escrito por el GM (dato, no se traduce)
by: string // quién sancionó (dato)
date: Date date: Date
expires: Date | null // null = permanente expires: Date | null // null = permanente
active: boolean active: boolean
status: string // etiqueta: Activo / Activo (permanente) / Expirado statusKey: 'active' | 'activePermanent' | 'expired'
} }
/** Estado de un baneo a partir de sus timestamps UNIX (segundos) y el flag active. */ /** Estado de un baneo a partir de sus timestamps UNIX (segundos) y el flag active. */
function banState(bandate: number, unbandate: number, active?: number): { active: boolean; status: string; expires: Date | null } { function banState(
bandate: number,
unbandate: number,
active?: number,
): { active: boolean; statusKey: Sanction['statusKey']; expires: Date | null } {
const now = Math.floor(Date.now() / 1000) const now = Math.floor(Date.now() / 1000)
const permanent = unbandate === 0 || unbandate <= bandate const permanent = unbandate === 0 || unbandate <= bandate
const flagActive = active === undefined ? true : active === 1 const flagActive = active === undefined ? true : active === 1
const stillActive = flagActive && (permanent || unbandate > now) const stillActive = flagActive && (permanent || unbandate > now)
return { return {
active: stillActive, active: stillActive,
status: stillActive ? (permanent ? 'Activo (permanente)' : 'Activo') : 'Expirado', statusKey: stillActive ? (permanent ? 'activePermanent' : 'active') : 'expired',
expires: permanent ? null : new Date(unbandate * 1000), expires: permanent ? null : new Date(unbandate * 1000),
} }
} }
@@ -46,7 +51,7 @@ export async function getSanctions(accountId: number, bnetId?: number): Promise<
) )
for (const r of rows) { for (const r of rows) {
const s = banState(Number(r.bandate), Number(r.unbandate), Number(r.active)) const s = banState(Number(r.bandate), Number(r.unbandate), Number(r.active))
bans.push({ scope: 'Cuenta', reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s }) bans.push({ scopeKey: 'account', scopeName: '', reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s })
} }
} catch { } catch {
/* AC no poblado */ /* AC no poblado */
@@ -61,7 +66,7 @@ export async function getSanctions(accountId: number, bnetId?: number): Promise<
) )
for (const r of rows) { for (const r of rows) {
const s = banState(Number(r.bandate), Number(r.unbandate)) const s = banState(Number(r.bandate), Number(r.unbandate))
bans.push({ scope: 'Battle.net', reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s }) bans.push({ scopeKey: 'battlenet', scopeName: '', reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s })
} }
} catch { } catch {
/* AC no poblado */ /* AC no poblado */
@@ -80,7 +85,7 @@ export async function getSanctions(accountId: number, bnetId?: number): Promise<
) )
for (const r of rows) { for (const r of rows) {
const s = banState(Number(r.bandate), Number(r.unbandate), Number(r.active)) const s = banState(Number(r.bandate), Number(r.unbandate), Number(r.active))
bans.push({ scope: `Personaje: ${nameByGuid.get(Number(r.guid)) ?? '?'}`, reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s }) bans.push({ scopeKey: 'character', scopeName: nameByGuid.get(Number(r.guid)) ?? '?', reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s })
} }
} }
} catch { } catch {
@@ -98,13 +103,14 @@ export async function getSanctions(accountId: number, bnetId?: number): Promise<
const end = Number(r.mutetime) const end = Number(r.mutetime)
const active = end > now const active = end > now
mutes.push({ mutes.push({
scope: 'Cuenta', scopeKey: 'account',
scopeName: '',
reason: String(r.mutereason || '—'), reason: String(r.mutereason || '—'),
by: String(r.mutedby || '—'), by: String(r.mutedby || '—'),
date: new Date(Number(r.mutedate) * 1000), date: new Date(Number(r.mutedate) * 1000),
expires: end > 0 ? new Date(end * 1000) : null, expires: end > 0 ? new Date(end * 1000) : null,
active, active,
status: active ? 'Activo' : 'Expirado', statusKey: active ? 'active' : 'expired',
}) })
} }
} catch { } catch {
+11 -1
View File
@@ -1040,7 +1040,17 @@
"thDate": "Date", "thDate": "Date",
"thExpires": "Expires", "thExpires": "Expires",
"thStatus": "Status", "thStatus": "Status",
"permanent": "Permanent" "permanent": "Permanent",
"scope": {
"account": "Account",
"battlenet": "Battle.net",
"character": "Character: {name}"
},
"status": {
"active": "Active",
"activePermanent": "Active (permanent)",
"expired": "Expired"
}
}, },
"security": { "security": {
"pageTitle": "Security history", "pageTitle": "Security history",
+11 -1
View File
@@ -1040,7 +1040,17 @@
"thDate": "Fecha", "thDate": "Fecha",
"thExpires": "Expira", "thExpires": "Expira",
"thStatus": "Estado", "thStatus": "Estado",
"permanent": "Permanente" "permanent": "Permanente",
"scope": {
"account": "Cuenta",
"battlenet": "Battle.net",
"character": "Personaje: {name}"
},
"status": {
"active": "Activo",
"activePermanent": "Activo (permanente)",
"expired": "Expirado"
}
}, },
"security": { "security": {
"pageTitle": "Historial de seguridad", "pageTitle": "Historial de seguridad",