fix(uptime): сохранить неизвестную скорость и проверить подтверждение теста

This commit is contained in:
Denozordec committed 2026-10-07 14:15:56 +07:00
1 parent 1904c86657
commit 9d5959601f
10 files changed
+160 -58

No files matched your search

+19 -25
View File
@@ -1,5 +1,7 @@
"use client"
import { parseSpeedRunResponse } from "@/lib/speed-run-response"
import { dashboardProbeOverviewSchema } from "@/lib/dashboard-probes"
import { speedHistoryResponseSchema, speedProbesResponseSchema, speedProbesWriteSchema, speedProbesSavedSchema, pingProbesWriteSchema, probeCatalogSavedSchema } from "@mmapp/contracts"
@@ -1736,8 +1738,8 @@ function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId
protocol: probe.protocol,
direction: probe.direction,
durationSec,
txAvgMbps: 0,
rxAvgMbps: 0,
txAvgMbps: null,
rxAvgMbps: null,
status: "running" as const,
command: buildSpeedCommand(probe),
lines: ["status: running..."],
@@ -1755,26 +1757,18 @@ function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId
direction: probe.direction,
durationSec,
}
const res = await apiFetch<{
result: {
txAvgMbps: number
rxAvgMbps: number
raw?: Array<Record<string, string>>
afterBtPing?: { rttMs: number | null; lossPct: number | null; error: string | null }
srcAddress?: string | null
dstAddress?: string | null
srcInterfaceAddress?: string | null
dstInterfaceAddress?: string | null
}
}>("/api/uptime/speed-test", {
const res = await apiFetch<unknown>("/api/uptime/speed-test", {
method: "POST",
// Includes interface lookups, bandwidth-test, post-test pause and Ping.
signal: AbortSignal.timeout(120_000),
body: JSON.stringify(payload),
})
if (context !== saveContext.current) return
const ap = res.result.afterBtPing
const lines = (res.result.raw ?? []).flatMap((row) =>
const result = parseSpeedRunResponse(res, runId)
const tx = result.txAvgMbps === null ? null : Math.round(result.txAvgMbps)
const rx = result.rxAvgMbps === null ? null : Math.round(result.rxAvgMbps)
const ap = result.afterBtPing
const lines = (result.raw ?? []).flatMap((row) =>
Object.entries(row).map(([k, v]) => `${k}: ${String(v)}`),
)
const pingNote = ap
@@ -1784,16 +1778,16 @@ function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId
: ""
setSpeedRuns((prev) => prev.map((r) => r.id === runId ? ({
...r,
txAvgMbps: Math.round(res.result.txAvgMbps),
rxAvgMbps: Math.round(res.result.rxAvgMbps),
txAvgMbps: tx,
rxAvgMbps: rx,
status: "done",
afterBtPing: ap ?? null,
srcAddress: res.result.srcAddress ?? null,
dstAddress: res.result.dstAddress ?? null,
srcInterfaceAddress: res.result.srcInterfaceAddress ?? null,
dstInterfaceAddress: res.result.dstInterfaceAddress ?? null,
srcAddress: result.srcAddress ?? null,
dstAddress: result.dstAddress ?? null,
srcInterfaceAddress: result.srcInterfaceAddress ?? null,
dstInterfaceAddress: result.dstInterfaceAddress ?? null,
lines: [
...(lines.length ? lines : [`tx-total-average: ${Math.round(res.result.txAvgMbps)}Mbps`, `rx-total-average: ${Math.round(res.result.rxAvgMbps)}Mbps`]),
...(lines.length ? lines : [`tx-total-average: ${tx === null ? "—" : `${tx}Mbps`}`, `rx-total-average: ${rx === null ? "—" : `${rx}Mbps`}`]),
...(pingNote ? [pingNote] : []),
],
}) : r))
@@ -1801,8 +1795,8 @@ function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId
setSpeedProbes((prev) => prev.map((p) => p.id === probe.id ? ({
...p,
lastRunAt: ts,
lastTxAvgMbps: Math.round(res.result.txAvgMbps),
lastRxAvgMbps: Math.round(res.result.rxAvgMbps),
lastTxAvgMbps: tx,
lastRxAvgMbps: rx,
lastStatus: "done",
lastError: "",
lastPingRttMs: ap?.rttMs ?? null,