export type GetApiDamFilesFileIdStreamArgs = {file_id: string}; export type GetApiDamFilesFileIdStreamOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * Returns a single file stream * * GET /dam/files/{file_id}/stream */ export const getApiDamFilesFileIdStream = async (args: GetApiDamFilesFileIdStreamArgs, options: GetApiDamFilesFileIdStreamOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "∗/∗") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/dam/files/${encodeURIComponent(String(args.file_id))}/stream${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };