|
|
@@ -15,6 +15,7 @@
|
|
|
*/
|
|
|
import type { Device } from '@/data/mock'
|
|
|
import { devices as canonDevices } from '@/data/mock'
|
|
|
+import { hostnameLabel, leaseLabel } from '@/lib/clientLabels'
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
// Tipos
|
|
|
@@ -124,48 +125,11 @@ const TYPE_TO_GROUP: Record<Device['type'], FilterGroup> = {
|
|
|
desconocido: 'otros',
|
|
|
}
|
|
|
|
|
|
-function slug(name: string): string {
|
|
|
- return (
|
|
|
- name
|
|
|
- .toLowerCase()
|
|
|
- .normalize('NFD')
|
|
|
- .replace(/[̀-ͯ]/g, '')
|
|
|
- .replace(/[^a-z0-9]+/g, '-')
|
|
|
- .replace(/^-|-$/g, '') || 'cliente'
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
-/** Formatea segundos restantes del lease a "2h 15min" · "1d 4h" · "45min". */
|
|
|
-function formatLeaseRemaining(totalSeconds: number): string {
|
|
|
- const days = Math.floor(totalSeconds / 86400)
|
|
|
- const hours = Math.floor((totalSeconds % 86400) / 3600)
|
|
|
- const minutes = Math.floor((totalSeconds % 3600) / 60)
|
|
|
- const parts: string[] = []
|
|
|
- if (days > 0) parts.push(`${days}d`)
|
|
|
- if (hours > 0) parts.push(`${hours}h`)
|
|
|
- if (minutes > 0 || parts.length === 0) parts.push(`${minutes}min`)
|
|
|
- return parts.join(' ')
|
|
|
-}
|
|
|
-
|
|
|
/** Detalles por defecto para un cliente que la API reporta sin metadatos. */
|
|
|
function defaultDetails(d: Device): Omit<ClientDevice, keyof Device> {
|
|
|
- // #1315: el lease con tiempo restante se muestra aunque el cliente esté
|
|
|
- // desconectado (dnsmasq conserva la concesión hasta su expiración; antes
|
|
|
- // se pintaba "Expired" a TODO lo offline, con tiempo restante o sin él).
|
|
|
- const remaining = d.leaseRemaining
|
|
|
- const leaseActive = remaining != null && remaining > 0
|
|
|
- const leaseText =
|
|
|
- remaining != null && remaining > 0
|
|
|
- ? `renews in ${formatLeaseRemaining(remaining)}`
|
|
|
- : remaining === 0
|
|
|
- ? 'Expired'
|
|
|
- : 'Static IP (reservation)'
|
|
|
return {
|
|
|
- // #1315: cuando el nombre es la propia MAC (sin hostname conocido), el
|
|
|
- // campo Hostname queda vacío: la MAC ya tiene su campo en la vista y el
|
|
|
- // slug en formato guionado ("34-5f-45-...") se leía como hostname.
|
|
|
- hostname: isMACName(d.name) ? '' : slug(d.name),
|
|
|
- dhcpLease: leaseActive || d.online ? leaseText : 'Expired',
|
|
|
+ hostname: hostnameLabel(d.name),
|
|
|
+ dhcpLease: leaseLabel(d.leaseRemaining),
|
|
|
traffic24hRx: '—',
|
|
|
traffic24hTx: '—',
|
|
|
adguard: true,
|
|
|
@@ -173,11 +137,6 @@ function defaultDetails(d: Device): Omit<ClientDevice, keyof Device> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/** #1315: el fallback del server sin hostname es la MAC (colons o dashes). */
|
|
|
-function isMACName(name: string): boolean {
|
|
|
- return /^([0-9a-f]{2}[:-]){5}[0-9a-f]{2}$/i.test(name.trim())
|
|
|
-}
|
|
|
-
|
|
|
/** Metadatos de cliente que pueden venir inline (canon JSON / API demo).
|
|
|
* firstSeen/lastSeen NO van aquí: viajan en Device como epochs (#954), y
|
|
|
* newThisWeek tampoco: es alta de device_seen, no detalle del demo. */
|