MHRN-Space / src /dashboard /static /api-client.js
ThomasHeisig's picture
Sync GitHub main 4645f4137666463023fa501984a14336dd2fc666 (part 11)
31226fd verified
Raw History Blame Contribute Delete
693 Bytes
/**
* Shared dashboard API helpers for browser and Hugging Face Space deployments.
*/
"use strict";
const isHuggingFaceHost = () => /\.hf\.space$/i.test(window.location.hostname);
export const isHuggingFaceSpace = isHuggingFaceHost();
export function pollInterval(milliseconds) {
return isHuggingFaceSpace ? milliseconds * 4 : milliseconds;
}
export async function readJson(response) {
const contentType = response.headers.get("content-type") || "unknown";
const body = await response.text();
if (!body) return {};
try {
return JSON.parse(body);
} catch {
throw new Error(
`API returned non-JSON data (HTTP ${response.status}, ${contentType})`,
);
}
}