export type GetApiResourcesDownloadArgs = {'ev-api-key': string, 'ev-access-token': string, 'resources[]': Array, downloadArchiveName?: string | undefined}; export type GetApiResourcesDownloadOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download a file * * GET /resources/download */ export const getApiResourcesDownload = async (args: GetApiResourcesDownloadArgs, options?: GetApiResourcesDownloadOptions) => { const {baseUrl = "https://accountname.exavault.com/api/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/octet-stream") if (args['ev-api-key'] != null) headers.set("ev-api-key", String(args['ev-api-key'])) if (args['ev-access-token'] != null) headers.set("ev-access-token", String(args['ev-access-token'])) for (const item of args['resources[]'] ?? []) query.append("resources[]", String(item)) if (args.downloadArchiveName != null) query.append("downloadArchiveName", String(args.downloadArchiveName)) const url = `${baseUrl.replace(/\/+$/, '')}/resources/download${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() };