fix(ui): проверять данные трафика без подстановки нулей в серии
This commit is contained in:
1 parent
f0eaa94e02
commit
a28f871fd4
7 files changed
+49
-39
No files matched your search
@@ -32,6 +32,7 @@ import type { FiltersRulesetRow, RouteOptimizerSpeedProbe } from "@/lib/route-op
|
||||
import { updateDashboardSource, type DashboardSource, type DashboardSources } from "@/lib/dashboard-source-state"
|
||||
|
||||
import {can,ensureAuthConfig} from "@/lib/auth"
|
||||
import {parseDashboardTraffic,type DashboardTraffic} from "@/lib/dashboard-traffic"
|
||||
import {parseDashboardBgp,type DashboardBgp} from "@/lib/dashboard-bgp"
|
||||
import {dashboardRequestPermission} from "@/lib/dashboard-permissions"
|
||||
async function dashboardRequest<T>(path:string,work:()=>Promise<T>,method="GET"):Promise<T>{
|
||||
@@ -117,14 +118,6 @@ interface InternetPathSnapshotPayload {
|
||||
wanRuntimeByHomeId: Record<string, HomeWanRuntime | null>
|
||||
}
|
||||
|
||||
interface TrafficServerRow {
|
||||
id: string
|
||||
rxNow: number
|
||||
txNow: number
|
||||
rxSeries: number[]
|
||||
txSeries: number[]
|
||||
}
|
||||
|
||||
export type OverlayKind = "gre" | "wg" | "vxlan"
|
||||
|
||||
export interface OverlayItem {
|
||||
@@ -204,18 +197,6 @@ function mapBackendToServer(s: BackendServerRow): Server {
|
||||
}
|
||||
}
|
||||
|
||||
function sumSeries(rows: TrafficServerRow[], key: "rxSeries" | "txSeries"): number[] {
|
||||
const len = Math.max(60, ...rows.map((r) => r[key].length), 0)
|
||||
const out = Array.from({ length: len }, () => 0)
|
||||
for (const row of rows) {
|
||||
const series = row[key]
|
||||
for (let i = 0; i < len; i++) {
|
||||
out[i] += series[i] ?? 0
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function mockOverlayItems(): OverlayItem[] {
|
||||
const gre: OverlayItem[] = mockGreTunnels.map((t) => ({
|
||||
id: JSON.stringify(["gre", t.serverId, t.id]),
|
||||
@@ -253,12 +234,7 @@ export function useDashboardLive() {
|
||||
const [liveServers, setLiveServers] = useState<Server[] | null>(null)
|
||||
const [overlayItems, setOverlayItems] = useState<OverlayItem[] | null>(null)
|
||||
const [bgp, setBgp] = useState<DashboardBgp | null>(null)
|
||||
const [trafficSeries, setTrafficSeries] = useState<{
|
||||
rx: number[]
|
||||
tx: number[]
|
||||
rxNow: number
|
||||
txNow: number
|
||||
} | null>(null)
|
||||
const [trafficSeries, setTrafficSeries] = useState<DashboardTraffic | null>(null)
|
||||
const [recentEvents, setRecentEvents] = useState<EventItem[]>([])
|
||||
const [eventsError, setEventsError] = useState<string | null>(null)
|
||||
const [eventsLoading, setEventsLoading] = useState(false)
|
||||
@@ -298,7 +274,7 @@ export function useDashboardLive() {
|
||||
apiFetch<{ snapshot: InternetPathSnapshotPayload | null }>("/api/internet-path/latest"),
|
||||
apiFetch<{ tunnels?: ApiGreTunnelRow[] }>("/api/filters/gre-tunnels"),
|
||||
dashboardRequest("/api/wireguard",()=>listWireGuard(backendUrl)),
|
||||
apiFetch<{ servers?: TrafficServerRow[] }>("/api/traffic/servers?range=1h"),
|
||||
apiFetch<unknown>("/api/traffic/servers?range=1h").then(parseDashboardTraffic),
|
||||
apiFetch<{ tunnels?: Array<{ id: string; serverId: string; name: string; status: OverlayItem["status"] }> }>("/api/vxlan"),
|
||||
])
|
||||
|
||||
@@ -359,15 +335,7 @@ export function useDashboardLive() {
|
||||
...(vxRes.status === "fulfilled" ? vxItems : previous?.filter(item => item.kind === "vxlan") ?? []),
|
||||
])
|
||||
|
||||
if (trafficRes.status === "fulfilled") {
|
||||
const rows = trafficRes.value.servers ?? []
|
||||
setTrafficSeries({
|
||||
rx: sumSeries(rows, "rxSeries"),
|
||||
tx: sumSeries(rows, "txSeries"),
|
||||
rxNow: rows.reduce((n, r) => n + (r.rxNow ?? 0), 0),
|
||||
txNow: rows.reduce((n, r) => n + (r.txNow ?? 0), 0),
|
||||
})
|
||||
}
|
||||
if (trafficRes.status === "fulfilled") setTrafficSeries(trafficRes.value)
|
||||
|
||||
const greMapped =
|
||||
greRes.status === "fulfilled" ? (greRes.value.tunnels ?? []).map(apiGreToGreTunnel) : []
|
||||
|
||||
Reference in new issue
Block a user