fix(ui): защитить экспорт WireGuard от устаревших ответов

This commit is contained in:
Denozordec committed 2026-09-29 08:37:53 +07:00
1 parent d3ae2598fb
commit 4aa4726c6b
6 files changed
+105 -8

No files matched your search

+18 -2
View File
@@ -217,6 +217,9 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
peerConf?: string
} | null>(null)
const [exportBusy, setExportBusy] = useState(false)
const exportEpoch = useRef(0)
const exportPending = useRef<number | null>(null)
useEffect(() => () => { exportEpoch.current += 1 }, [])
const loadLive = useCallback(async () => {
if (!isLive) return
@@ -593,7 +596,9 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
}
async function handleLiveExport(format: "rsc" | "conf" | "peer-conf") {
if (!exportIface || !isLive) return
if (!exportIface || !isLive || exportPending.current !== null) return
const epoch = exportEpoch.current
exportPending.current = epoch
setExportBusy(true)
try {
const res = await exportWireGuard(backendUrl, {
@@ -603,6 +608,7 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
includePrivateKey: format !== "peer-conf",
peerId: format === "peer-conf" ? (exportPeerId ?? undefined) : undefined,
})
if (epoch !== exportEpoch.current) return
setLiveExport((prev) => ({
...prev,
...(format === "rsc"
@@ -613,13 +619,20 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
}))
toast.success("Конфиг загружен с роутера")
} catch (e) {
if (epoch !== exportEpoch.current) return
toast.error(e instanceof Error ? e.message : "Ошибка экспорта")
} finally {
setExportBusy(false)
if (epoch === exportEpoch.current) {
exportPending.current = null
setExportBusy(false)
}
}
}
function openExport(iface: WgIfaceWithServer, tab: "rsc" | "conf" | "peer" = "rsc", peerId?: string) {
exportEpoch.current += 1
exportPending.current = null
setExportBusy(false)
setLiveExport(null)
setExportInitialTab(tab)
setExportPeerId(peerId ?? null)
@@ -927,6 +940,9 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
initialTab={exportInitialTab}
peerId={exportPeerId}
onClose={() => {
exportEpoch.current += 1
exportPending.current = null
setExportBusy(false)
setExportIface(null)
setExportPeerId(null)
setExportInitialTab("rsc")