// Helpers for resolving DANDI asset URLs and locating LINDI indexes. // This mirrors what neurosift does in src/pages/NwbPage/hdf5Interface.ts. export const extractAssetId = (downloadUrl: string): string | undefined => { // e.g. https://api.dandiarchive.org/api/assets//download/ const m = downloadUrl.match(/\/assets\/([^/]+)\/download/); return m ? m[1] : undefined; }; // DANDI download URLs are 302-redirected to a (signed) S3 object URL. // We follow the redirect with a GET and then abort, because a HEAD request is // rejected by CORS on the DANDI S3 bucket. We only want `response.url`. export const resolveDandiDownloadUrl = async (url: string): Promise => { const controller = new AbortController(); try { const response = await fetch(url, { signal: controller.signal }); const resolved = response.url || url; controller.abort(); return resolved; } catch { controller.abort(); return url; } }; // neurosift hosts precomputed LINDI indexes for published dandisets here. export const lindiUrlForAsset = (dandisetId: string, assetId: string): string => `https://lindi.neurosift.org/dandi/dandisets/${dandisetId}/assets/${assetId}/nwb.lindi.json`; export const lindiIndexExists = async (lindiUrl: string): Promise => { try { const resp = await fetch(lindiUrl, { method: "HEAD" }); return resp.ok; } catch { return false; } };