fix(ui): сохранять подтверждённый снимок пути при ошибке API

This commit is contained in:
Denozordec committed 2026-10-04 00:07:21 +07:00
1 parent 55c9349677
commit 5fdd6ef58c
9 files changed
+85 -53

No files matched your search

+8 -21
View File
@@ -19,15 +19,14 @@ import type { EventItem } from "@mmapp/contracts/events"
import { buildLatencySeriesByProbeSource } from "@/lib/dashboard-latency"
import {
buildDashboardInternetPath,
type HomeWanRuntime,
resolveDefaultRouteLookup,
type InternetPathViewModel,
} from "@/lib/dashboard-internet-path"
import type { FiltersRulesetRow, RouteOptimizerSpeedProbe } from "@/lib/route-optimizer-data"
import { updateDashboardSource, type DashboardSource, type DashboardSources } from "@/lib/dashboard-source-state"
import {can,ensureAuthConfig} from "@/lib/auth"
import {parseDashboardPath,parseDashboardFilters,parseDashboardSpeedProbes,parseDashboardWanRuntime} from "@/lib/dashboard-path-response"
import {parseDashboardGre,parseDashboardWireGuard,parseDashboardVxlan,type DashboardGreTunnel} from "@/lib/dashboard-overlays"
import type {DashboardProbe} from "@/lib/dashboard-probes"
import {parseDashboardServers,parseDashboardProbes,type DashboardServerRow} from "@/lib/dashboard-readers"
@@ -65,16 +64,6 @@ type BackendServerRow=DashboardServerRow
type ApiGreTunnelRow=DashboardGreTunnel
interface InternetPathSnapshotPayload {
sampledAt: string
servers: BackendServerRow[]
greTunnels: ApiGreTunnelRow[]
filtersRulesets: FiltersRulesetRow[]
speedProbes: RouteOptimizerSpeedProbe[]
routeLookupByServerId: Record<string, { gateway: string | null; routingMark: string | null } | null>
wanRuntimeByHomeId: Record<string, HomeWanRuntime | null>
}
export type OverlayKind = "gre" | "wg" | "vxlan"
export interface OverlayItem {
@@ -226,9 +215,9 @@ export function useDashboardLive() {
const [overviewRes, serversRes, fr, br, ipRes, greRes, wgRes, trafficRes, vxRes] = await Promise.allSettled([
apiFetch<unknown>("/api/uptime/overview?range=1h").then(parseDashboardProbes),
apiFetch<unknown>("/api/servers").then(parseDashboardServers),
apiFetch<{ rulesets: Array<{ rules?: unknown[] }> }>("/api/filters/rules"),
apiFetch<unknown>("/api/filters/rules").then(parseDashboardFilters),
apiFetch<unknown>("/api/bgp/catalog").then(parseDashboardBgp),
apiFetch<{ snapshot: InternetPathSnapshotPayload | null }>("/api/internet-path/latest"),
apiFetch<unknown>("/api/internet-path/latest").then(parseDashboardPath),
apiFetch<unknown>("/api/filters/gre-tunnels").then(parseDashboardGre),
apiFetch<unknown>("/api/wireguard").then(parseDashboardWireGuard),
apiFetch<unknown>("/api/traffic/servers?range=1h").then(parseDashboardTraffic),
@@ -321,9 +310,8 @@ export function useDashboardLive() {
try { return await apiFetch(path, init) }
catch (error) { lookupFailed = true; throw error }
}
const filterRulesets: FiltersRulesetRow[] =
fr.status === "fulfilled" ? ((fr.value.rulesets as FiltersRulesetRow[]) ?? []) : []
const homes = serversMapped.filter((s) => s.type === "home-router")
const filterRulesets = fr.status === "fulfilled" ? fr.value.rulesets : []
const homes = serversMapped.filter((s) => s.type === "home-router" && s.enabled)
const lookups = await Promise.all(
homes.map(async (h) => ({
id: h.id,
@@ -334,17 +322,16 @@ export function useDashboardLive() {
const wanRuntimeRows = await Promise.all(
homes.map(async (h) => {
try {
const rt = await checkedFetch<HomeWanRuntime>(`/api/servers/${h.id}/wan-runtime`)
const rt = await checkedFetch<unknown>(`/api/servers/${h.id}/wan-runtime`).then(parseDashboardWanRuntime)
return { id: h.id, runtime: rt }
} catch {
lookupFailed=true
return { id: h.id, runtime: null }
}
}),
)
if (!current()) return
const speedRes = await checkedFetch<{ probes?: RouteOptimizerSpeedProbe[] }>("/api/uptime/speed-probes").catch(
() => ({ probes: [] }),
)
const speedRes = await checkedFetch<unknown>("/api/uptime/speed-probes").then(parseDashboardSpeedProbes).catch(error=>{lookupFailed=true;throw Error("Не удалось обновить все данные Internet path: "+(error instanceof Error?error.message:String(error)))})
if (!current()) return
if (lookupFailed) throw new Error("Не удалось обновить все данные Internet path")
const lookupById = Object.fromEntries(lookups.map((x) => [x.id, x.lookup]))