UNPKG

@activadee/n8n-nodes-gradio-client

Version:
45 lines (44 loc) 1.59 kB
"use strict"; // Gradio Client Utility Functions Object.defineProperty(exports, "__esModule", { value: true }); exports.generateSessionHash = generateSessionHash; exports.sleep = sleep; exports.cleanUrl = cleanUrl; exports.handleGradioFile = handleGradioFile; exports.convertToGradioFile = convertToGradioFile; // Helper functions function generateSessionHash() { const chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; let hash = ''; for (let i = 0; i < 11; i++) { hash += chars.charAt(Math.floor(Math.random() * chars.length)); } return hash; } function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } function cleanUrl(url) { url = url.trim(); if (!url.startsWith('http://') && !url.startsWith('https://')) { url = 'https://' + url; } // Remove trailing slash return url.replace(/\/$/, ''); } // Enhanced file handling following Gradio patterns async function handleGradioFile(executeFunctions, propertyName, filename) { const buffer = await executeFunctions.helpers.getBinaryDataBuffer(0, propertyName); const binaryData = executeFunctions.getInputData()[0].binary[propertyName]; return { path: filename, meta: { _type: 'gradio.FileData' }, orig_name: filename, size: buffer.length, mime_type: binaryData.mimeType || 'application/octet-stream', }; } // Legacy function for backward compatibility async function convertToGradioFile(executeFunctions, propertyName, filename) { return handleGradioFile(executeFunctions, propertyName, filename); }