export type CreateApiV1FilesUploadArgs = {'App-ID': string, 'Auth-Token': string, body: BodyInit}; export type CreateApiV1FilesUploadOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Upload small files * * POST /v1/files/upload/ */ export const createApiV1FilesUpload = async (args: CreateApiV1FilesUploadArgs, options: CreateApiV1FilesUploadOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) if (args['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/files/upload/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };