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:
Denozordec
2026-05-07 13:35:41 +07:00
parent 5f31bb47fb
commit 6d8379501c
42 changed files with 1336 additions and 631 deletions
+28
View File
@@ -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,
}
}