export type AccountId = string; export type FilePath = string; export type GetApiAccountIdRawFilePathArgs = {accountId: AccountId, cache?: boolean | undefined, 'cache-ttl'?: number | undefined, 'cache-ttl-404'?: number | undefined, exp?: (number | 'inf') | undefined, filePath: FilePath, version?: string | undefined}; export type GetApiAccountIdRawFilePathOptions = {baseUrl?: string | undefined, authorizationHeader?: string | undefined, fetch?: typeof fetch | undefined}; /** * Downloads a file in its original/unprocessed state. * * GET /{accountId}/raw{filePath} */ export const getApiAccountIdRawFilePath = async (args: GetApiAccountIdRawFilePathArgs, options?: GetApiAccountIdRawFilePathOptions) => { const {baseUrl = "https://upcdn.io", fetch: fetchFn = fetch, authorizationHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "*") if (args.cache != null) query.append("cache", String(args.cache)) if (args['cache-ttl'] != null) query.append("cache-ttl", String(args['cache-ttl'])) if (args['cache-ttl-404'] != null) query.append("cache-ttl-404", String(args['cache-ttl-404'])) if (args.exp != null) query.append("exp", String(args.exp)) if (args.version != null) query.append("version", String(args.version)) if (authorizationHeader !== undefined) headers.set("Authorization", authorizationHeader) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.accountId))}/raw${encodeURIComponent(String(args.filePath))}${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() };