Download frontend/js/api.js from NOT-OMEGA/AutoForge: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/spaces/NOT-OMEGA/AutoForge/resolve/main/frontend/js/api.js
- Command line
-
hf download hf://spaces/NOT-OMEGA/AutoForge/frontend/js/api.js
-
curl -L -o api.js https://huggingface.co/spaces/NOT-OMEGA/AutoForge/resolve/main/frontend/js/api.js
1.44 kB
| /** | |
| * AutoForge API Client | |
| * | |
| * Wraps fetch() with JWT injection, error handling, and base URL management. | |
| */ | |
| const API = (() => { | |
| const BASE_URL = ''; | |
| /** | |
| * Make an authenticated API request. | |
| */ | |
| async function request(method, path, body = null) { | |
| const headers = { 'Content-Type': 'application/json' }; | |
| const token = localStorage.getItem('autoforge_token'); | |
| if (token) { | |
| headers['Authorization'] = `Bearer ${token}`; | |
| } | |
| const options = { method, headers }; | |
| if (body) { | |
| options.body = JSON.stringify(body); | |
| } | |
| const response = await fetch(`${BASE_URL}${path}`, options); | |
| if (response.status === 401) { | |
| localStorage.removeItem('autoforge_token'); | |
| localStorage.removeItem('autoforge_user'); | |
| window.location.href = '/login.html'; | |
| throw new Error('Session expired'); | |
| } | |
| const data = await response.json(); | |
| if (!response.ok) { | |
| const message = data.detail || `Request failed (${response.status})`; | |
| throw new Error(message); | |
| } | |
| return data; | |
| } | |
| return { | |
| get: (path) => request('GET', path), | |
| post: (path, body) => request('POST', path, body), | |
| put: (path, body) => request('PUT', path, body), | |
| delete: (path) => request('DELETE', path), | |
| }; | |
| })(); | |