export type GetApiV1DefaultFilesDownloadKeyArgs = {key: string, authorization?: (string | null) | undefined}; export type GetApiV1DefaultFilesDownloadKeyOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Download a stored file (async export archive) * * GET /v1/default/files/download/{key} */ export const getApiV1DefaultFilesDownloadKey = async (args: GetApiV1DefaultFilesDownloadKeyArgs, options: GetApiV1DefaultFilesDownloadKeyOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/zip") if (args.authorization != null) headers.set("authorization", String(args.authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/default/files/download/${encodeURIComponent(String(args.key))}${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() };