Download web/js/space-media.js from githubtailscaleduplicity342/RL-Explorer: direct link, hf CLI and curl.
- Browser
- Download file 869 Bytes
-
https://huggingface.co/spaces/githubtailscaleduplicity342/RL-Explorer/resolve/main/web/js/space-media.js
- Command line
-
hf download hf://spaces/githubtailscaleduplicity342/RL-Explorer/web/js/space-media.js
-
curl -L -o space-media.js https://huggingface.co/spaces/githubtailscaleduplicity342/RL-Explorer/resolve/main/web/js/space-media.js
869 Bytes
| // Asset paths are relative to the Space, never the explorer. Resolve only | |
| // same-origin HTTPS paths; arbitrary URL schemes and foreign hosts are rejected. | |
| export function spaceMedia(data, host) { | |
| if (!data || typeof data !== "object") return data; | |
| if (Array.isArray(data)) return data.map((v) => spaceMedia(v, host)); | |
| const out = Object.fromEntries(Object.entries(data).map(([k, v]) => [k, spaceMedia(v, host)])); | |
| if (typeof out.asset_path === "string" && out.asset_path.startsWith("/assets/") && /^(audio|image|video)\//.test(out.mime || "")) { | |
| try { | |
| const base = new URL(host), asset = new URL(out.asset_path, base); | |
| if (base.protocol === "https:" && asset.origin === base.origin && !asset.username && !asset.password) | |
| out.media_url = asset.href; | |
| } catch { /* malformed source: keep its metadata visible */ } | |
| } | |
| return out; | |
| } | |