Spaces:
Sleeping
Sleeping
Download src/utils/storage.js from lewtun/running-dashboard: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/lewtun/running-dashboard/resolve/main/src/utils/storage.js
- Command line
-
hf download hf://spaces/lewtun/running-dashboard/src/utils/storage.js
-
curl -L -o storage.js https://huggingface.co/spaces/lewtun/running-dashboard/resolve/main/src/utils/storage.js
1.45 kB
| async function request(path, options = {}) { | |
| const response = await fetch(path, { | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| ...(options.headers || {}), | |
| }, | |
| ...options, | |
| }); | |
| if (!response.ok) { | |
| let message = `API ${response.status}: ${response.statusText}`; | |
| const contentType = response.headers.get('content-type') || ''; | |
| try { | |
| if (contentType.includes('application/json')) { | |
| const payload = await response.json(); | |
| if (payload && typeof payload.error === 'string' && payload.error.trim()) { | |
| message = payload.error.trim(); | |
| } | |
| } else { | |
| const text = await response.text(); | |
| if (text.trim()) { | |
| message = text.trim(); | |
| } | |
| } | |
| } catch { | |
| // Fall back to the HTTP status message when the error body is unreadable. | |
| } | |
| throw new Error(message); | |
| } | |
| if (response.status === 204) return null; | |
| return response.json(); | |
| } | |
| export async function loadRuns() { | |
| return request('/api/runs'); | |
| } | |
| export async function createRun(run) { | |
| return request('/api/runs', { | |
| method: 'POST', | |
| body: JSON.stringify(run), | |
| }); | |
| } | |
| export async function updateRun(id, changes) { | |
| return request(`/api/runs/${encodeURIComponent(id)}`, { | |
| method: 'PUT', | |
| body: JSON.stringify(changes), | |
| }); | |
| } | |
| export async function deleteRun(id) { | |
| return request(`/api/runs/${encodeURIComponent(id)}`, { | |
| method: 'DELETE', | |
| }); | |
| } | |