fix(ui): подтверждать создание интерфейса и пира WireGuard
This commit is contained in:
1 parent
ec6ec52965
commit
8fff3d7fff
8 files changed
+166
-52
No files matched your search
+11
-3
@@ -1,4 +1,4 @@
|
||||
import { wgImportResponseSchema } from "@mmapp/contracts/wireguard"
|
||||
import { wgIfaceDtoSchema, wgImportResponseSchema } from "@mmapp/contracts/wireguard"
|
||||
import type {
|
||||
WgCreateInterface,
|
||||
WgCreatePeerRequest,
|
||||
@@ -27,10 +27,16 @@ export async function createWireGuardInterface(
|
||||
baseUrl: string,
|
||||
payload: WgCreateInterface,
|
||||
): Promise<unknown> {
|
||||
return requestJson(baseUrl, "/api/wireguard/interfaces", {
|
||||
const result = await requestJson<unknown>(baseUrl, "/api/wireguard/interfaces", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
const iface = wgIfaceDtoSchema.safeParse(result)
|
||||
const confirmed = iface.success
|
||||
? iface.data.name === payload.name && String(iface.data.serverId) === String(payload.serverId)
|
||||
: typeof result === "object" && result !== null && "ok" in result && result.ok === true && "name" in result && result.name === payload.name
|
||||
if (!confirmed) throw new Error("Сервер не подтвердил создание интерфейса")
|
||||
return result
|
||||
}
|
||||
|
||||
export async function patchWireGuardInterface(
|
||||
@@ -59,10 +65,12 @@ export async function createWireGuardPeer(
|
||||
baseUrl: string,
|
||||
payload: WgCreatePeerRequest,
|
||||
): Promise<{ ok: boolean }> {
|
||||
return requestJson(baseUrl, "/api/wireguard/peers", {
|
||||
const result = await requestJson<{ ok: boolean }>(baseUrl, "/api/wireguard/peers", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
if (result?.ok !== true) throw new Error("Сервер не подтвердил создание пира")
|
||||
return result
|
||||
}
|
||||
|
||||
export async function patchWireGuardPeer(
|
||||
|
||||
Reference in new issue
Block a user