| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- /**
- * @node ocr-delete-job
- * @name OCR Delete Job
- * @category ocr
- * @version 1.0.1
- * @description Delete an OCR job
- * @icon trash-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' }
- }
- },
- jobId: {
- type: 'string',
- title: 'Job ID',
- description: 'The ID of the job to delete (can be provided from input)'
- }
- },
- required: ['baseUrl']
- };
- const inputSchema = {
- type: 'object',
- properties: {
- jobId: {
- type: 'string',
- description: 'Job ID to delete (overrides config)'
- }
- }
- };
- const outputSchema = {
- type: 'object',
- properties: {
- jobId: { type: 'string' },
- deleted: { type: 'boolean' }
- }
- };
- const outputs = [
- { name: 'main', displayName: 'Deleted', type: 'object', color: '#ef4444' }
- ];
- module.exports = {
- configSchema,
- inputSchema,
- outputSchema,
- outputs,
- async execute(config, input, context) {
- const baseUrl = (config.baseUrl || 'http://localhost:3000').replace(/\/$/, '');
- const jobId = input.jobId || config.jobId;
- if (!jobId) {
- throw new Error('Job ID is required');
- }
- const headers = {};
- if (config.credentialId) {
- const auth = smartbotic.credentials.get(config.credentialId);
- if (!auth.success) {
- throw new Error(`Failed to load credential: ${auth.error}`);
- }
- headers[auth.headerName] = auth.headerValue;
- }
- smartbotic.log.info(`OCR Delete Job: ${jobId}`);
- const response = smartbotic.http.request({
- method: 'DELETE',
- url: `${baseUrl}/api/jobs/${encodeURIComponent(jobId)}`,
- headers: headers,
- timeout: 30000
- });
- if (response.status === 404) {
- throw new Error(`Job not found: ${jobId}`);
- }
- 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}`);
- }
- return {
- jobId: jobId,
- deleted: true
- };
- }
- };
|