Spaces:
Sleeping
Sleeping
Download frontend/src/lib/api.ts from gui-sparim/mp_tpu_TESTES: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/spaces/gui-sparim/mp_tpu_TESTES/resolve/main/frontend/src/lib/api.ts
- Command line
-
hf download hf://spaces/gui-sparim/mp_tpu_TESTES/frontend/src/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/gui-sparim/mp_tpu_TESTES/resolve/main/frontend/src/lib/api.ts
2.04 kB
| import type { AppDocument, Space, StateResponse, Tpu } from "../types"; | |
| async function request(path: string, init?: RequestInit): Promise<StateResponse> { | |
| const response = await fetch(path, { | |
| ...init, | |
| headers: { "Content-Type": "application/json", ...(init?.headers || {}) }, | |
| }); | |
| const body = await response.json().catch(() => ({})); | |
| if (!response.ok) { | |
| const detail = typeof body.detail === "string" ? body.detail : body.detail?.message; | |
| throw new Error(detail || "Não foi possível concluir a operação."); | |
| } | |
| return body; | |
| } | |
| export const api = { | |
| state: () => request("/api/state"), | |
| updateSpace: (revision: number, id: string, changes: Partial<Space>) => | |
| request(`/api/spaces/${encodeURIComponent(id)}`, { method: "PATCH", body: JSON.stringify({ expected_revision: revision, changes }) }), | |
| updateSpaces: (revision: number, updates: Array<{ id: string; changes: Partial<Space> }>) => | |
| request("/api/spaces", { method: "PATCH", body: JSON.stringify({ expected_revision: revision, updates }) }), | |
| createSpace: (revision: number, space: Space) => | |
| request("/api/spaces", { method: "POST", body: JSON.stringify({ expected_revision: revision, space }) }), | |
| deleteSpace: (revision: number, id: string) => | |
| request(`/api/spaces/${encodeURIComponent(id)}?expected_revision=${revision}`, { method: "DELETE" }), | |
| updateTpu: (revision: number, id: string, changes: Partial<Tpu>) => | |
| request(`/api/tpus/${encodeURIComponent(id)}`, { method: "PATCH", body: JSON.stringify({ expected_revision: revision, changes }) }), | |
| createTpu: (revision: number, tpu: Tpu) => | |
| request("/api/tpus", { method: "POST", body: JSON.stringify({ expected_revision: revision, tpu }) }), | |
| deleteTpu: (revision: number, id: string) => | |
| request(`/api/tpus/${encodeURIComponent(id)}?expected_revision=${revision}`, { method: "DELETE" }), | |
| importState: (revision: number, document: AppDocument) => | |
| request("/api/import", { method: "POST", body: JSON.stringify({ expected_revision: revision, document }) }), | |
| }; | |