export type CreateApiUploadArgs = {'Upload-Length': number, 'Upload-Metadata': string, 'Tus-Resumable': string}; export type CreateApiUploadOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Upload file * * POST /upload */ export const createApiUpload = async (args: CreateApiUploadArgs, options?: CreateApiUploadOptions) => { const {baseUrl = "https://docs.bimtrackapp.co", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args['Upload-Length'] != null) headers.set("Upload-Length", String(args['Upload-Length'])) if (args['Upload-Metadata'] != null) headers.set("Upload-Metadata", String(args['Upload-Metadata'])) if (args['Tus-Resumable'] != null) headers.set("Tus-Resumable", String(args['Tus-Resumable'])) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/upload${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };