Files
stackpilot/frontend/src/api/volumes.ts
T
menzeljandClaude Opus 4.8 56450efd82 Volumes page: on-demand volume sizes (0.18.0)
Docker's volume list has no size, so add a "Compute sizes" button that runs
`docker system df` (via client.df()) and shows per-volume size in a new Size
column. The df walk is expensive (seconds), so results are cached ~60s and
loaded on demand instead of on every poll.

- volume_service.volume_sizes(force) with a 60s TTL cache; GET /api/volumes/sizes
  + agent /agent/volumes/sizes + proxy /api/agents/{id}/volumes/sizes.
- Frontend: volumesApi.sizes(force, agentId); Volumes page gained a Size column
  and a Compute sizes button (per host) that triggers the lookup.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 13:07:07 +00:00

30 lines
1.2 KiB
TypeScript

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<VolumeInfo[]>(base(agentId)).then((r) => r.data),
sizes: (force = false, agentId?: number) =>
api
.get<Record<string, number | null>>(`${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<string, unknown>) =>
api
.post<{ yaml: string }>("/api/volumes/generate-yaml", spec)
.then((r) => r.data.yaml),
hostPaths: (path: string, showHidden = false) =>
api
.get<HostPathResult>(
`/api/host/paths?path=${encodeURIComponent(path)}&show_hidden=${showHidden}`
)
.then((r) => r.data),
};