UNPKG

n8n-nodes-coze

Version:

n8n node for Coze(扣子), supporting AI chat, workflow automation, file processing, and text-to-speech.

54 lines 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeFile = executeFile; const stream_1 = require("stream"); async function executeFile(i) { const operation = this.getNodeParameter('operation', i); const authentication = this.getNodeParameter('authentication', i); if (operation === 'upload') { const credentials = await this.getCredentials(authentication); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const item = this.getInputData(i)[0]; if (item.binary === undefined || item.binary[binaryPropertyName] === undefined) { throw new Error('No binary data found to upload!'); } const binaryData = item.binary[binaryPropertyName]; const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const stream = stream_1.Readable.from(buffer); const options = { baseURL: credentials.baseUrl, method: 'POST', url: `/v1/files/upload`, headers: { 'Content-Type': 'multipart/form-data', }, formData: { file: { value: stream, options: { filename: binaryData.fileName, contentType: binaryData.mimeType, }, }, }, json: true, }; return this.helpers.requestWithAuthentication.call(this, authentication, options); } else if (operation === 'retrieve') { const credentials = await this.getCredentials(authentication); const fileId = this.getNodeParameter('fileId', i); const qs = { file_id: fileId, }; const options = { baseURL: credentials.baseUrl, method: 'GET', url: `/v1/files/retrieve`, qs, json: true, }; return this.helpers.requestWithAuthentication.call(this, authentication, options); } } //# sourceMappingURL=file.js.map