|
import { WebBlob } from "./WebBlob"; |
|
import { isFrontend } from "./isFrontend"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function createBlob(url: URL, opts?: { fetch?: typeof fetch; accessToken?: string }): Promise<Blob> { |
|
if (url.protocol === "http:" || url.protocol === "https:") { |
|
return WebBlob.create(url, { fetch: opts?.fetch, accessToken: opts?.accessToken }); |
|
} |
|
|
|
if (isFrontend) { |
|
throw new TypeError(`Unsupported URL protocol "${url.protocol}"`); |
|
} |
|
|
|
if (url.protocol === "file:") { |
|
const { FileBlob } = await import("./FileBlob"); |
|
|
|
return FileBlob.create(url); |
|
} |
|
|
|
throw new TypeError(`Unsupported URL protocol "${url.protocol}"`); |
|
} |
|
|