UNPKG

@activadee/n8n-nodes-gradio-client

Version:
68 lines (67 loc) 2.94 kB
"use strict"; // Minimal n8n Node Definition - Entry Point Only Object.defineProperty(exports, "__esModule", { value: true }); exports.GradioClient = void 0; const n8n_workflow_1 = require("n8n-workflow"); const nodeDefinition_1 = require("./nodeDefinition"); const loadOptions_1 = require("./loadOptions"); const operations_1 = require("./operations"); const utils_1 = require("./utils"); class GradioClient { constructor() { this.description = nodeDefinition_1.nodeDescription; this.methods = { loadOptions: loadOptions_1.loadOptionsMethods }; } async execute() { const items = this.getInputData(); const returnData = []; const operation = this.getNodeParameter('operation', 0); for (let i = 0; i < items.length; i++) { try { const spaceUrl = this.getNodeParameter('spaceUrl', i); const authentication = this.getNodeParameter('authentication', i); const requiresAuth = authentication === 'huggingface'; const cleanedUrl = (0, utils_1.cleanUrl)(spaceUrl); // Set up headers const headers = { 'Content-Type': 'application/json', }; if (requiresAuth) { const credentials = await this.getCredentials('huggingFaceApi'); if (!credentials || !credentials.apiKey) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'HuggingFace API credentials not found or invalid'); } const apiKey = credentials.apiKey; console.log('HuggingFace API Key present:', !!apiKey); headers['Authorization'] = `Bearer ${apiKey}`; } let result; if (operation === 'getSpaceInfo') { result = await (0, operations_1.executeGetSpaceInfo)(this, i, cleanedUrl, headers); } else if (operation === 'callFunction') { result = await (0, operations_1.executeCallFunction)(this, i, cleanedUrl, headers); } else { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`); } returnData.push(result); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error instanceof Error ? error.message : String(error), success: false, }, pairedItem: { item: i }, }); continue; } throw error; } } return [returnData]; } } exports.GradioClient = GradioClient;