fix(ui): подтверждать команды контейнеров ответом API

This commit is contained in:
Denozordec committed 2026-10-01 10:53:07 +07:00
1 parent 860add8edf
commit c419a46955
7 files changed
+125 -25

No files matched your search

+7 -1
View File
@@ -1,5 +1,11 @@
import { containersStateSchema } from "@mmapp/contracts/containers"
import { containersStateSchema, containerMutationAckSchema } from "@mmapp/contracts/containers"
import { requestJson } from "./http-client"
export async function readContainersState(baseUrl: string, options?: RequestInit) {
return containersStateSchema.parse(await requestJson<unknown>(baseUrl, "/api/containers/state", options))
}
export type ContainerAction = "start" | "stop" | "restart" | "remove"
export async function mutateContainer(baseUrl: string, serverId: string, rosId: string, action: ContainerAction, options?: RequestInit) {
if (!/^[1-9]\d*$/.test(serverId) || !Number.isSafeInteger(Number(serverId)) || !rosId.trim()) throw new Error("Неверный контекст контейнера")
return containerMutationAckSchema.parse(await requestJson<unknown>(baseUrl, `/api/servers/${encodeURIComponent(serverId)}/containers/${action}`, { ...options, method: "POST", body: JSON.stringify({ rosId }) }))
}