fix(ui): сохранять данные IPsec при сбоях опроса
This commit is contained in:
1 parent
8fab2f7fd2
commit
b8923d075d
7 files changed
+191
-48
No files matched your search
+15
-2
@@ -1,4 +1,4 @@
|
||||
import { ipsecServerSummaryDtoSchema, ipsecUserCreatedSchema, ipsecCertBundleSchema } from "@mmapp/contracts/ipsec"
|
||||
import { ipsecListResponseSchema, ipsecServerSummaryDtoSchema, ipsecUserCreatedSchema, ipsecCertBundleSchema } from "@mmapp/contracts/ipsec"
|
||||
import { requestJson } from "@/shared/api/http-client"
|
||||
import type {
|
||||
IpsecCertBundle,
|
||||
@@ -18,7 +18,20 @@ export async function listIpsec(
|
||||
const q = new URLSearchParams()
|
||||
if (opts?.serverId) q.set("serverId", opts.serverId)
|
||||
const suffix = q.size > 0 ? `?${q.toString()}` : ""
|
||||
return requestJson<IpsecListResponse>(baseUrl, `/api/ipsec${suffix}`, { method: "GET" })
|
||||
const response = await requestJson<unknown>(baseUrl, `/api/ipsec${suffix}`, { method: "GET" })
|
||||
const result = ipsecListResponseSchema.safeParse(response)
|
||||
if (!result.success) throw new Error("Некорректный ответ загрузки IPsec")
|
||||
const data = result.data
|
||||
const serverIds = data.servers.map(s => s.serverId)
|
||||
const clientIds = data.clients.map(c => c.id)
|
||||
const failedIds = (data.failures ?? []).map(f => f.serverId)
|
||||
if (new Set(serverIds).size !== serverIds.length || new Set(clientIds).size !== clientIds.length ||
|
||||
new Set(failedIds).size !== failedIds.length || serverIds.some(id => failedIds.includes(id)) ||
|
||||
data.clients.some(c => failedIds.includes(c.serverId)) ||
|
||||
(opts?.serverId && [...serverIds, ...failedIds, ...data.clients.map(c => c.serverId)].some(id => id !== opts.serverId))) {
|
||||
throw new Error("Несогласованный ответ загрузки IPsec")
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
export async function initIpsecServer(
|
||||
|
||||
Reference in new issue
Block a user