2025-09-16 00:05:16 -05:00
|
|
|
// frontend/src/api.ts
|
2025-09-16 04:32:16 -05:00
|
|
|
import 'tus-js-client'
|
|
|
|
|
|
|
|
|
|
import type { UrlStorage } from 'tus-js-client'
|
|
|
|
|
|
|
|
|
|
declare module 'tus-js-client' {
|
|
|
|
|
interface UploadOptions {
|
|
|
|
|
/** Send cookies on CORS requests */
|
|
|
|
|
withCredentials?: boolean
|
|
|
|
|
/** Disable reading/writing resume URLs (older defs may miss this) */
|
|
|
|
|
resume?: boolean
|
|
|
|
|
/** Do not store fingerprints for resuming */
|
|
|
|
|
storeFingerprintForResuming?: boolean
|
|
|
|
|
/** Remove any stored fingerprint after a successful upload */
|
|
|
|
|
removeFingerprintOnSuccess?: boolean
|
|
|
|
|
/** Allow providing a no-op storage to fully disable resuming */
|
|
|
|
|
urlStorage?: UrlStorage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-08 00:48:47 -05:00
|
|
|
export async function api<T=any>(path: string, init?: RequestInit): Promise<T> {
|
|
|
|
|
const r = await fetch(path, { credentials:'include', ...init });
|
|
|
|
|
if (!r.ok) throw new Error(await r.text());
|
|
|
|
|
const ct = r.headers.get('content-type') || '';
|
2025-09-16 04:32:16 -05:00
|
|
|
if (ct.includes('json')) return r.json() as Promise<T>;
|
|
|
|
|
// Fallback: try to parse body as JSON; otherwise return text
|
|
|
|
|
const txt = await r.text();
|
|
|
|
|
try { return JSON.parse(txt) as T } catch { return txt as any as T }
|
2025-09-08 00:48:47 -05:00
|
|
|
}
|
2025-09-16 04:32:16 -05:00
|
|
|
|
2025-09-08 00:48:47 -05:00
|
|
|
export type WhoAmI = { username: string; root: string };
|