File size: 692 Bytes
5e0b58b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
 * 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})`,
    );
  }
}