UNPKG

n8n-walichat

Version:

n8n plugin for WaliChat

74 lines (73 loc) 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UploadFile = void 0; const BaseNode_1 = require("../Base/BaseNode"); const globalProperties_1 = require("../globalProperties"); class UploadFile extends BaseNode_1.BaseNode { constructor() { super(...arguments); this.description = { displayName: 'Upload file', name: 'walichatUploadFile', group: ['Files'], version: 1, description: 'Upload a file from a remote URL using the WaliChat API', icon: 'file:../../../icon.png', defaults: { name: 'Upload File', color: '#1A82e2', }, inputs: ["main" /* NodeConnectionType.Main */], outputs: ["main" /* NodeConnectionType.Main */], credentials: [ { name: 'WaliChatApiKey', required: true, }, ], properties: [ ...globalProperties_1.globalProperties, { displayName: 'File URL', name: 'fileUrl', type: 'string', default: '', placeholder: 'Enter the file URL...', description: 'The URL of the file to upload.', required: true, }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { const apiKey = this.getNodeParameter('apiKey', i); const fileUrl = this.getNodeParameter('fileUrl', i); try { const response = await super.request({ path: '/files', method: 'POST', body: { url: fileUrl }, headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json', }, }); returnData.push({ json: response, }); } catch (error) { returnData.push({ json: { error: error.message, }, }); } } return [returnData]; } } exports.UploadFile = UploadFile;