fix(ui): проверять подтверждение восстановления WireGuard
This commit is contained in:
1 parent
425a77a1ca
commit
221d6db10c
5 files changed
+51
-6
No files matched your search
@@ -211,6 +211,7 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
|
||||
const [historyOpen, setHistoryOpen] = useState(false)
|
||||
const [revisions, setRevisions] = useState<ConfigRevisionDto[]>([])
|
||||
const [historyLoading, setHistoryLoading] = useState(false)
|
||||
const restoreLock = useRef(false)
|
||||
const [historyRestoring, setHistoryRestoring] = useState(false)
|
||||
const [liveExport, setLiveExport] = useState<{
|
||||
rsc?: string
|
||||
@@ -287,20 +288,23 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
|
||||
}, [isLive, historyServerId, backendUrl])
|
||||
|
||||
const restoreRevision = useCallback(async (id: string) => {
|
||||
if (!isLive || !historyServerId) return
|
||||
if (!isLive || !historyServerId || restoreLock.current) return
|
||||
restoreLock.current = true
|
||||
setHistoryRestoring(true)
|
||||
try {
|
||||
await requestJson(
|
||||
const result = await requestJson<{ ok: boolean }>(
|
||||
backendUrl,
|
||||
`/api/wireguard/revisions/${encodeURIComponent(id)}/restore`,
|
||||
{ method: "POST", body: JSON.stringify({ serverId: historyServerId }) },
|
||||
)
|
||||
if (result?.ok !== true) throw new Error("Сервер не подтвердил восстановление")
|
||||
toast.success("Версия применена на роутер")
|
||||
await loadLive()
|
||||
await loadRevisions()
|
||||
} catch (err) {
|
||||
toast.error("Не удалось откатить", { description: String(err) })
|
||||
} finally {
|
||||
restoreLock.current = false
|
||||
setHistoryRestoring(false)
|
||||
}
|
||||
}, [isLive, historyServerId, backendUrl, loadLive, loadRevisions])
|
||||
|
||||
Reference in new issue
Block a user