Files
uconsole_asw_game/data/commander/js/net/request.js
T
db9979andClaude Opus 5.5 4dd23bc242 Web client: CIC redesign with ES modules and bundled fonts
- Remote Crew browser client rebuilt as a dark combat-information-centre layout
  for large desktop monitors: slim status bar (stations, mission, clocks, UTC,
  link state), pulsing alert band, the instrument as centrepiece and
  collapsible docks (contacts, station, contact detail, log drawer; keys , . L).
  Four columns from 2400 px, fluid type up to 4K; guide, lookout and contact
  library open as overlays (Esc closes).
- app.js split into native ES modules under data/commander/js; the transport
  (net/*) no longer touches the DOM and talks to the views through synchronous
  topics (core/events.js, app/bindings.js); redraws share one frame scheduler.
- style.css replaced by a token-based design system in data/commander/css.
- Inter 4.1 and JetBrains Mono 2.304 bundled unmodified (OFL-1.1) with
  provenance in THIRD_PARTY_NOTICES.md; CSP allows font-src 'self'.
- Server serves the css/js/fonts trees from one asset manifest
  (src/commander/assets.py); packaging, capture tool, help, manual and docs
  updated; tests share tests/commander_web.py and import modules directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 12:02:01 +02:00

43 lines
1.8 KiB
JavaScript

import { S } from "../state/store.js";
// All requests, including commands and language changes, share one lane. The
// deadline covers JSON consumption as well as headers, including stalled bodies.
export function request(path, { method = "GET", body, auth = true, expected = 200, guard, csrf } = {}) {
const cookieSession = auth ? S.session : null;
const requestGeneration = S.generation;
const run = async () => {
if (auth && (!cookieSession || requestGeneration !== S.generation)) throw new Error("cancelled");
if (guard && !guard()) throw new Error("cancelled");
const controller = new AbortController();
S.activeRequest = controller;
const timeout = setTimeout(() => controller.abort(), 4000);
let response;
try {
const headers = { Accept: "application/json" };
if (csrf) headers["X-U-Jagd-CSRF"] = csrf;
if (body !== undefined) headers["Content-Type"] = "application/json";
response = await fetch(`/api/v2${path}`, {
method, headers, body: body === undefined ? undefined : JSON.stringify(body),
signal: controller.signal, cache: "no-store", credentials: "same-origin", redirect: "error", mode: "same-origin",
});
if (response.status !== expected) {
const error = new Error("http");
error.status = response.status;
throw error;
}
// A queued command acknowledgement need not contain a JSON body.
if (expected === 202) { await response.text(); return null; }
return await response.json();
} catch (error) {
if (response) error.endpointAvailable = true;
throw error;
} finally {
clearTimeout(timeout);
if (S.activeRequest === controller) S.activeRequest = null;
}
};
const result = S.requestQueue.then(run, run);
S.requestQueue = result.catch(() => {});
return result;
}