/** * @node ocr-job-stats * @name OCR Job Stats * @category ocr * @version 1.0.1 * @description Get OCR job queue statistics * @icon bar-chart-2 */ const configSchema = { type: 'object', properties: { baseUrl: { type: 'string', title: 'API Base URL', default: 'http://localhost:3000', description: 'Base URL of the OCR API' }, credentialId: { type: 'string', title: 'Credential', description: 'Bearer or API Key credential for authentication', dynamicOptions: { source: 'credentials', filter: { type: 'api_key' } } } }, required: ['baseUrl'] }; const inputSchema = { type: 'object', properties: {} }; const outputSchema = { type: 'object', properties: { stats: { type: 'object', properties: { pending: { type: 'number' }, processing: { type: 'number' }, completed: { type: 'number' }, failed: { type: 'number' } } } } }; const outputs = [ { name: 'main', displayName: 'Stats', type: 'object', color: '#f59e0b' } ]; module.exports = { configSchema, inputSchema, outputSchema, outputs, async execute(config, input, context) { const baseUrl = (config.baseUrl || 'http://localhost:3000').replace(/\/$/, ''); // Build headers const headers = {}; smartbotic.log.info(`OCR Job Stats - credentialId: ${config.credentialId || 'NOT SET'}`); if (config.credentialId) { const auth = smartbotic.credentials.get(config.credentialId); smartbotic.log.info(`Credential lookup result: ${JSON.stringify(auth)}`); if (!auth.success) { throw new Error(`Failed to load credential: ${auth.error}`); } headers[auth.headerName] = auth.headerValue; smartbotic.log.info(`Auth header set: ${auth.headerName}`); } else { smartbotic.log.warn('No credential selected'); } smartbotic.log.info(`OCR Get Job Stats from ${baseUrl}`); const response = smartbotic.http.request({ method: 'GET', url: `${baseUrl}/api/jobs/stats`, headers: headers, timeout: 30000 }); if (response.status < 200 || response.status >= 300) { const errorMsg = typeof response.data === 'string' ? response.data : JSON.stringify(response.data); if (response.status === 401 && !config.credentialId) { throw new Error('Authentication required - please select a credential in node settings'); } throw new Error(`OCR API error (${response.status}): ${errorMsg}`); } const data = typeof response.data === 'string' ? JSON.parse(response.data) : response.data; return { stats: data.stats || data }; } };