|  | 
|  | 1 | +import { axios } from "@pipedream/platform"; | 
|  | 2 | +import { | 
|  | 3 | +  IMAGE_FILETYPE_OPTIONS, | 
|  | 4 | +  LANGUAGE_OPTIONS, | 
|  | 5 | +  OCR_ENGINE_OPTIONS, | 
|  | 6 | +} from "./common/constants.mjs"; | 
|  | 7 | + | 
| 1 | 8 | export default { | 
| 2 | 9 |   type: "app", | 
| 3 | 10 |   app: "ocrspace", | 
| 4 |  | -  propDefinitions: {}, | 
|  | 11 | +  propDefinitions: { | 
|  | 12 | +    file: { | 
|  | 13 | +      type: "string", | 
|  | 14 | +      label: "Image", | 
|  | 15 | +      description: "The URL of the image or the path to the file saved to the `/tmp` directory  (e.g. `/tmp/example.jpg`)  to process. [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory).", | 
|  | 16 | +    }, | 
|  | 17 | +    language: { | 
|  | 18 | +      type: "string", | 
|  | 19 | +      label: "Language", | 
|  | 20 | +      description: "Language setting for image OCR processing.", | 
|  | 21 | +      options: LANGUAGE_OPTIONS, | 
|  | 22 | +      optional: true, | 
|  | 23 | +    }, | 
|  | 24 | +    isOverlayRequired: { | 
|  | 25 | +      type: "boolean", | 
|  | 26 | +      label: "Is Overlay Required", | 
|  | 27 | +      description: "If true, returns the coordinates of the bounding boxes for each word. If false, the OCR'ed text is returned only as a text block (this makes the JSON reponse smaller). Overlay data can be used, for example, to show [text over the image](https://ocr.space/english).", | 
|  | 28 | +      optional: true, | 
|  | 29 | +    }, | 
|  | 30 | +    filetype: { | 
|  | 31 | +      type: "string", | 
|  | 32 | +      label: "File Type", | 
|  | 33 | +      description: "Overwrites the automatic file type detection based on content-type. Supported image file formats are png, jpg (jpeg), gif, tif (tiff) and bmp. For document ocr, the api supports the Adobe PDF format. Multi-page TIFF files are supported.", | 
|  | 34 | +      options: IMAGE_FILETYPE_OPTIONS, | 
|  | 35 | +      optional: true, | 
|  | 36 | +    }, | 
|  | 37 | +    detectOrientation: { | 
|  | 38 | +      type: "boolean", | 
|  | 39 | +      label: "Detect Orientation", | 
|  | 40 | +      description: "If set to true, the api autorotates the image correctly and sets the TextOrientation parameter in the JSON response. If the image is not rotated, then TextOrientation=0, otherwise it is the degree of the rotation, e. g. \"270\".", | 
|  | 41 | +      optional: true, | 
|  | 42 | +    }, | 
|  | 43 | +    scale: { | 
|  | 44 | +      type: "boolean", | 
|  | 45 | +      label: "Scale", | 
|  | 46 | +      description: "If set to true, the api does some internal upscaling. This can improve the OCR result significantly, especially for low-resolution PDF scans. Note that the front page demo uses scale=true, but the API uses scale=false by default. See also this OCR forum post.", | 
|  | 47 | +      optional: true, | 
|  | 48 | +    }, | 
|  | 49 | +    isTable: { | 
|  | 50 | +      type: "boolean", | 
|  | 51 | +      label: "Is Table", | 
|  | 52 | +      description: "If set to true, the OCR logic makes sure that the parsed text result is always returned line by line. This switch is recommended for [table OCR](https://ocr.space/tablerecognition), [receipt OCR](https://ocr.space/receiptscanning), invoice processing and all other type of input documents that have a table like structure.", | 
|  | 53 | +      optional: true, | 
|  | 54 | +    }, | 
|  | 55 | +    ocrEngine: { | 
|  | 56 | +      type: "string", | 
|  | 57 | +      label: "OCR Engine", | 
|  | 58 | +      description: "Engine 1 is default. [See OCR Engines](https://ocr.space/OCRAPI#ocrengine).", | 
|  | 59 | +      options: OCR_ENGINE_OPTIONS, | 
|  | 60 | +      optional: true, | 
|  | 61 | +    }, | 
|  | 62 | +  }, | 
| 5 | 63 |   methods: { | 
| 6 |  | -    // this.$auth contains connected account data | 
| 7 |  | -    authKeys() { | 
| 8 |  | -      console.log(Object.keys(this.$auth)); | 
|  | 64 | +    _baseUrl() { | 
|  | 65 | +      return "https://api.ocr.space"; | 
|  | 66 | +    }, | 
|  | 67 | +    _headers(headers = {}) { | 
|  | 68 | +      return { | 
|  | 69 | +        "apikey": this.$auth.apikey, | 
|  | 70 | +        ...headers, | 
|  | 71 | +      }; | 
|  | 72 | +    }, | 
|  | 73 | +    _makeRequest({ | 
|  | 74 | +      $ = this, path, headers, ...opts | 
|  | 75 | +    }) { | 
|  | 76 | +      return axios($, { | 
|  | 77 | +        url: this._baseUrl() + path, | 
|  | 78 | +        headers: this._headers(headers), | 
|  | 79 | +        ...opts, | 
|  | 80 | +      }); | 
|  | 81 | +    }, | 
|  | 82 | +    processImage(opts = {}) { | 
|  | 83 | +      return this._makeRequest({ | 
|  | 84 | +        method: "POST", | 
|  | 85 | +        path: "/parse/image", | 
|  | 86 | +        ...opts, | 
|  | 87 | +      }); | 
| 9 | 88 |     }, | 
| 10 | 89 |   }, | 
| 11 | 90 | }; | 
0 commit comments