ocr-limitations.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * @node ocr-limitations
  3. * @name OCR Limitations
  4. * @category ocr
  5. * @version 1.0.1
  6. * @description Get user limitations and quotas for OCR API
  7. * @icon info
  8. */
  9. const configSchema = {
  10. type: 'object',
  11. properties: {
  12. baseUrl: {
  13. type: 'string',
  14. title: 'API Base URL',
  15. default: 'http://localhost:3000',
  16. description: 'Base URL of the OCR API'
  17. },
  18. credentialId: {
  19. type: 'string',
  20. title: 'Credential',
  21. description: 'Bearer or API Key credential for authentication',
  22. dynamicOptions: {
  23. source: 'credentials',
  24. filter: { type: 'api_key' }
  25. }
  26. }
  27. },
  28. required: ['baseUrl']
  29. };
  30. const inputSchema = {
  31. type: 'object',
  32. properties: {}
  33. };
  34. const outputSchema = {
  35. type: 'object',
  36. properties: {
  37. limitations: {
  38. type: 'object',
  39. properties: {
  40. allowedFileTypes: {
  41. type: 'array',
  42. items: { type: 'string' }
  43. },
  44. maxFileSizeMb: { type: 'number' },
  45. maxPdfPages: { type: 'number' },
  46. maxConcurrentJobs: { type: 'number' },
  47. dailyLimit: { type: 'number' },
  48. monthlyLimit: { type: 'number' }
  49. }
  50. }
  51. }
  52. };
  53. const outputs = [
  54. { name: 'main', displayName: 'Limitations', type: 'object', color: '#14b8a6' }
  55. ];
  56. module.exports = {
  57. configSchema,
  58. inputSchema,
  59. outputSchema,
  60. outputs,
  61. async execute(config, input, context) {
  62. const baseUrl = (config.baseUrl || 'http://localhost:3000').replace(/\/$/, '');
  63. const headers = {};
  64. if (config.credentialId) {
  65. const auth = smartbotic.credentials.get(config.credentialId);
  66. if (!auth.success) {
  67. throw new Error(`Failed to load credential: ${auth.error}`);
  68. }
  69. headers[auth.headerName] = auth.headerValue;
  70. }
  71. smartbotic.log.info(`OCR Get Limitations from ${baseUrl}`);
  72. const response = smartbotic.http.request({
  73. method: 'GET',
  74. url: `${baseUrl}/api/ocr/limitations`,
  75. headers: headers,
  76. timeout: 30000
  77. });
  78. if (response.status < 200 || response.status >= 300) {
  79. const errorMsg = typeof response.data === 'string' ? response.data : JSON.stringify(response.data);
  80. 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}`);
  81. }
  82. const data = typeof response.data === 'string' ? JSON.parse(response.data) : response.data;
  83. return {
  84. limitations: data.limitations || data
  85. };
  86. }
  87. };