export type UploadRequest = {channel: string, name: string, server_temp_path: string, server_sha256: string, server_md5: string, server_size: number, client_fields: Record}; export type CreateApiRepoUploadArgs = {body: UploadRequest}; export type CreateApiRepoUploadOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Used by repo-proxy to handle upload artifact flow * * POST /repo/upload */ export const createApiRepoUpload = async (args: CreateApiRepoUploadArgs, options?: CreateApiRepoUploadOptions) => { const {baseUrl = "https://api.anaconda.cloud/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/repo/upload${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };