jukebox
All repositories: gitoria
2.3 KB
// Browser target: the host handles redirects and credential policy. Network reasons are limited by the host Fetch API.function reason(e, timedOut) {if (timedOut) return 'timed out';const code = e?.cause?.code || e?.code;if (code === 'ECONNREFUSED') return 'connection refused';if (code === 'ENOTFOUND' || code === 'EAI_AGAIN') return 'could not resolve host';if (code === 'ECONNRESET' || code === 'UND_ERR_SOCKET') return 'connection reset by peer';if (code === 'ETIMEDOUT' || code === 'UND_ERR_CONNECT_TIMEOUT') return 'timed out';return e?.cause?.message || e?.message || String(e);}async function exchange(url, options, tolerant) {const o = options || {};const method = o.method || 'GET';const controller = new AbortController();let timedOut = false;const timer = setTimeout(() => { timedOut = true; controller.abort(); }, o.timeoutMs ?? 30000);try {const headers = new Headers(o.headers || {});let body = o.body;if (o.json != null) {body = JSON.stringify(o.json);if (!headers.has('content-type')) headers.set('content-type', 'application/json');}// Generated modules use the runtime's Bytes wrapper; direct JS uses Uint8Array.if (body?._d instanceof Uint8Array) {const { hlIsBytes } = await import('../hl-runtime.js');if (hlIsBytes(body)) body = body._d;}if (body != null && typeof body !== 'string' && !(body instanceof Uint8Array)) {throw new Error('body must be a String or Bytes (use json for JSON)');}// Manual browser redirects hide status and Location (opaqueredirect).// A positive custom hop limit cannot be enforced through browser Fetch.const r = await globalThis.fetch(url, { method, headers, body, signal: controller.signal,redirect: o.maxRedirects === 0 ? 'manual' : 'follow' });const text = await r.text();return { status: r.status, ok: r.ok, url: r.url, headers: Object.fromEntries(r.headers),body: text, tag: o.tag || '', text() { return text; }, json() { return JSON.parse(text); } };} catch (e) {const error = `hl:fetch ${method} ${url}: ${reason(e, timedOut)}`;if (tolerant) return { ok: false, status: 0, error };throw new Error(error);} finally { clearTimeout(timer); }}export function fetch(url, options) { return exchange(url, options, false); }export function tryFetch(url, options) { return exchange(url, options, true); }
Branches
Latest commits
- d7b5e780|||PR Records 2026-11-24 (2): live day72, PR #19 merge, #10 newsmre
- 43b564dbMerge branch 'records-1124b' into mainJukebox
- fa86b08c|||PR Records 2026-11-24: LOG, STATUS, missions 020-023mre
- 0a2ae3daMerge remote-tracking branch 'origin/records-1123' into records-1124mre
- 9a48cfcaMerge branch 'vendor-theme' into mainJukebox
- 170d3735Merge branch 'code-order-2' into mainJukebox
- 3f1918a7|||PR Re-sync layouts theme 4099e64 with Segoe UI firstmre
- 2e7f6a43Vendor virtual-list 489afcf from components.hybrielmre
- 0ba85799Merge branch 'reset-classes' into mainJukebox
- 502eeed5jukebox#20: vendor virtual-list initial resetKey baseline fixmre
- 6d5ce287|||PR jukebox#9 Centralize songs table reads and writes in db.hlmre
- dcca21abjukebox#8 Move copies and queue logic into their topicsmre
- 3b76651cjukebox#20: update virtual-list README pin and resetKey optionsmre
- bc09e1e8|||PR jukebox#20: reset virtual lists through resetKey (partial validation)mre
- a3796dc5Records: live step waits for idlemre
- 3b158e16Records: merges of #9 and #11mre
- 27204167Merge main into records-1123mre
- 10f8a8c8Merge branch 'code-order' into mainJukebox
- 204fc828Merge branch 'day72' into mainJukebox
- 8e8d0e2b|||PR Records: PROCEDURES.md, missions 016-019, GO 2026-11-23mre