fix(ui): проверять подтверждение импорта WireGuard
This commit is contained in:
1 parent
f980619046
commit
efc6da1249
6 files changed
+60
-5
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { wgImportResponseSchema } from "@mmapp/contracts/wireguard"
|
||||
import type {
|
||||
WgCreateInterface,
|
||||
WgCreatePeerRequest,
|
||||
@@ -90,10 +91,17 @@ export async function importWireGuard(
|
||||
baseUrl: string,
|
||||
payload: WgImportRequest,
|
||||
): Promise<WgImportResponse> {
|
||||
return requestJson(baseUrl, "/api/wireguard/import", {
|
||||
const response = await requestJson<unknown>(baseUrl, "/api/wireguard/import", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
const parsed = wgImportResponseSchema.safeParse(response)
|
||||
if (!parsed.success) throw new Error("Некорректный ответ импорта WireGuard")
|
||||
const result = parsed.data
|
||||
if (result.dryRun !== (payload.dryRun ?? false) || (!result.dryRun && !result.applied)) {
|
||||
throw new Error("Сервер не подтвердил применение конфигурации")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export async function exportWireGuard(
|
||||
|
||||
Reference in new issue
Block a user