refactor: replace custom API fetch logic with requestJson utility across multiple pages
Updated the API fetching mechanism in various components to utilize the new requestJson function for improved consistency and error handling. This change affects the alerts, dashboard, data collection, filters, gre, network map, probes, recursive routes, route optimizer, servers, settings, traffic, and uptime pages.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import type { ServerRead } from "@/packages/contracts/src/servers"
|
||||
import type { Server } from "@/lib/data"
|
||||
|
||||
export function toFrontendServer(server: ServerRead): Server {
|
||||
return {
|
||||
id: String(server.id),
|
||||
name: server.name || server.host,
|
||||
host: server.host,
|
||||
type: server.type,
|
||||
site: server.site,
|
||||
country: server.country,
|
||||
asn: server.asn,
|
||||
model: server.model ?? "—",
|
||||
os: server.os ?? "—",
|
||||
enabled: server.enabled,
|
||||
status: server.status ?? "offline",
|
||||
latency: server.latency != null ? Math.round(server.latency) : null,
|
||||
sessions: server.sessions ?? 0,
|
||||
comment: server.comment || undefined,
|
||||
lanSubnet: server.lanSubnet || undefined,
|
||||
wanUplinks: Array.isArray(server.wanUplinks) && server.wanUplinks.length ? server.wanUplinks : undefined,
|
||||
uptime: server.uptime ?? undefined,
|
||||
cpuLoad: server.cpuLoad ?? undefined,
|
||||
freeMemory: server.freeMemory ?? undefined,
|
||||
totalMemory: server.totalMemory ?? undefined,
|
||||
polledAt: server.polledAt ?? undefined,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user