INNER CODE UNIT · JavaScript

HttpApi

LeyckerS/moondownloader · web/app.js:220

class HttpApi {
  constructor() { this.token = new URLSearchParams(location.search).get("t") || ""; }

  async _call(name, args = []) {
    try {
      const res = await fetch(`api/${name}`, {
        method: "POST",
        headers: { "Content-Type": "application/json", "X-Moon-Token": this.token },
        body: JSON.stringify({ args }),
        cache: "no-store",
      });
      if (!res.ok) return { error: `HTTP ${res.status} on ${name}` };
      return await res.json();
    } catch (err) {
      return { error: `${name}: ${err}` };
    }
  }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…