import api from "./client"; import type { HostPathResult, VolumeInfo } from "@/types"; // Base path for the local host or, when agentId is given, a remote agent. const base = (agentId?: number) => agentId != null ? `/api/agents/${agentId}/volumes` : "/api/volumes"; export const volumesApi = { list: (agentId?: number) => api.get(base(agentId)).then((r) => r.data), sizes: (force = false, agentId?: number) => api .get>(`${base(agentId)}/sizes`, { params: { force } }) .then((r) => r.data), remove: (name: string, force = false, agentId?: number) => api.delete(`${base(agentId)}/${name}?force=${force}`).then((r) => r.data), prune: (agentId?: number) => api.post<{ VolumesDeleted: string[] | null }>(`${base(agentId)}/prune`).then((r) => r.data), generateYaml: (spec: Record) => api .post<{ yaml: string }>("/api/volumes/generate-yaml", spec) .then((r) => r.data.yaml), hostPaths: (path: string, showHidden = false) => api .get( `/api/host/paths?path=${encodeURIComponent(path)}&show_hidden=${showHidden}` ) .then((r) => r.data), };