Yihua7's picture
Build Tripo SimReady Explorer with live dataset and joint previews
91425b8 verified
Raw History Blame Contribute Delete
828 Bytes
import type { Catalog, Preview } from './types';
async function request<T>(url: string, signal?: AbortSignal): Promise<T> {
const response = await fetch(url, { signal, headers: { Accept: 'application/json' } });
if (!response.ok) {
let message = `Request failed (${response.status})`;
try {
const body = await response.json();
message = typeof body.detail === 'string' ? body.detail : body.message || message;
} catch { /* A proxy may return a non-JSON error page. */ }
throw new Error(message);
}
return response.json() as Promise<T>;
}
export const getCatalog = (refresh = false) => request<Catalog>(`/api/catalog${refresh ? '?refresh=true' : ''}`);
export const getPreview = (id: string, signal?: AbortSignal) => request<Preview>(`/api/assets/${encodeURIComponent(id)}/preview`, signal);