| 45637 | var blobs_js_1 = require_blobs(); |
| 45638 | var streams_js_1 = require_streams(); |
| 45639 | async function filesUpload(client, request3, options) { |
| 45640 | const parsed = (0, schemas_js_1.safeParse)(request3, (value) => operations.FilesApiRoutesUploadFileMultiPartBodyParams$outboundSchema.parse(value), "Input validation failed"); |
| 45641 | if (!parsed.ok) { |
| 45642 | return parsed; |
| 45643 | } |
| 45644 | const payload = parsed.value; |
| 45645 | const body = new FormData(); |
| 45646 | if ((0, blobs_js_1.isBlobLike)(payload.file)) { |
| 45647 | body.append("file", payload.file); |
| 45648 | } else if ((0, streams_js_1.isReadableStream)(payload.file.content)) { |
| 45649 | const buffer = await (0, files_js_1.readableStreamToArrayBuffer)(payload.file.content); |
| 45650 | const blob = new Blob([buffer], { type: "application/octet-stream" }); |
| 45651 | body.append("file", blob); |
| 45652 | } else { |
| 45653 | body.append("file", new Blob([payload.file.content], { type: "application/octet-stream" }), payload.file.fileName); |
| 45654 | } |
| 45655 | if (payload.purpose !== void 0) { |
| 45656 | body.append("purpose", payload.purpose); |
| 45657 | } |
| 45658 | const path5 = (0, url_js_1.pathToFunc)("/v1/files")(); |
| 45659 | const headers = new Headers({ |
| 45660 | Accept: "application/json" |
| 45661 | }); |
| 45662 | const secConfig = await (0, security_js_1.extractSecurity)(client._options.apiKey); |
| 45663 | const securityInput = secConfig == null ? {} : { apiKey: secConfig }; |
| 45664 | const requestSecurity = (0, security_js_1.resolveGlobalSecurity)(securityInput); |
| 45665 | const context = { |
| 45666 | operationID: "files_api_routes_upload_file", |
| 45667 | oAuth2Scopes: [], |
| 45668 | resolvedSecurity: requestSecurity, |
| 45669 | securitySource: client._options.apiKey, |
| 45670 | retryConfig: (options === null || options === void 0 ? void 0 : options.retries) || client._options.retryConfig || { strategy: "none" }, |
| 45671 | retryCodes: (options === null || options === void 0 ? void 0 : options.retryCodes) || ["429", "500", "502", "503", "504"] |
| 45672 | }; |
| 45673 | const requestRes = client._createRequest(context, { |
| 45674 | security: requestSecurity, |
| 45675 | method: "POST", |
| 45676 | path: path5, |
| 45677 | headers, |
| 45678 | body, |
| 45679 | timeoutMs: (options === null || options === void 0 ? void 0 : options.timeoutMs) || client._options.timeoutMs || -1 |
| 45680 | }, options); |
| 45681 | if (!requestRes.ok) { |
| 45682 | return requestRes; |
| 45683 | } |
| 45684 | const req = requestRes.value; |
| 45685 | const doResult = await client._do(req, { |
| 45686 | context, |
| 45687 | errorCodes: ["4XX", "5XX"], |
| 45688 | retryConfig: context.retryConfig, |
| 45689 | retryCodes: context.retryCodes |
| 45690 | }); |
| 45691 | if (!doResult.ok) { |
| 45692 | return doResult; |
| 45693 | } |
| 45694 | const response = doResult.value; |
| 45695 | const [result] = await M5.match(M5.json(200, components.UploadFileOut$inboundSchema), M5.fail(["4XX", "5XX"]))(response); |
| 45696 | if (!result.ok) { |