UNPKG

@wiro-ai/n8n-nodes-wiroai

Version:

n8n community node for Wiro AI's Generative AI APIs.

120 lines 4.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EasyOcr = void 0; const n8n_workflow_1 = require("n8n-workflow"); const auth_1 = require("../utils/auth"); const polling_1 = require("../utils/polling"); class EasyOcr { constructor() { this.description = { displayName: 'Wiro - Extract Text From Image', name: 'easyOcr', icon: { light: 'file:wiro.svg', dark: 'file:wiro.svg' }, group: ['transform'], version: 1, description: 'Extracts text from images using AI', defaults: { name: 'Wiro - Extract Text From Image', }, inputs: ["main"], outputs: ["main"], usableAsTool: true, credentials: [ { name: 'wiroApi', required: true, }, ], properties: [ { displayName: 'Enter Image URL', name: 'inputImageUrl', type: 'string', default: '', required: true, description: 'Enter an image URL to extract text from', }, { displayName: 'Language', name: 'language', type: 'options', default: 'English', required: true, options: [ { name: 'Arabic', value: 'Arabic' }, { name: 'Chinese', value: 'Chinese' }, { name: 'Czech', value: 'Czech' }, { name: 'Dutch', value: 'Dutch' }, { name: 'English', value: 'English' }, { name: 'French', value: 'French' }, { name: 'German', value: 'German' }, { name: 'Hindi', value: 'Hindi' }, { name: 'Hungarian', value: 'Hungarian' }, { name: 'Italian', value: 'Italian' }, { name: 'Japanese', value: 'Japanese' }, { name: 'Korean', value: 'Korean' }, { name: 'Polish', value: 'Polish' }, { name: 'Portuguese', value: 'Portuguese' }, { name: 'Russian', value: 'Russian' }, { name: 'Spanish', value: 'Spanish' }, { name: 'Turkish', value: 'Turkish' }, ], description: 'Select the language used in the image text', }, ], }; } async execute() { const returnData = []; const inputImageUrl = this.getNodeParameter('inputImageUrl', 0); const language = this.getNodeParameter('language', 0); const credentials = await this.getCredentials('wiroApi'); const apiKey = credentials.apiKey; const apiSecret = credentials.apiSecret; const headers = (0, auth_1.generateWiroAuthHeaders)(apiKey, apiSecret); const response = await this.helpers.request({ method: 'POST', url: 'https://api.wiro.ai/v1/Run/wiro/easy_ocr', headers: { ...headers, 'Content-Type': 'application/json', }, body: { inputImageUrl, language, }, json: true, }); if (!(response === null || response === void 0 ? void 0 : response.taskid) || !(response === null || response === void 0 ? void 0 : response.socketaccesstoken)) { throw new n8n_workflow_1.NodeApiError(this.getNode(), { message: 'Wiro API did not return a valid task ID or socket access token ' + JSON.stringify(response), }); } const taskid = response.taskid; const socketaccesstoken = response.socketaccesstoken; const result = await polling_1.pollTaskUntilComplete.call(this, socketaccesstoken, headers); const responseJSON = { taskid: taskid, url: '', status: '', }; switch (result) { case '-1': case '-2': case '-3': case '-4': responseJSON.status = 'failed'; break; default: responseJSON.status = 'completed'; responseJSON.url = result !== null && result !== void 0 ? result : ''; } returnData.push({ json: responseJSON, }); return [returnData]; } } exports.EasyOcr = EasyOcr; //# sourceMappingURL=EasyOcr.node.js.map