Skip to content

Commit 04ae59a

Browse files
committed
add: ocrspace
1 parent b560b05 commit 04ae59a

File tree

6 files changed

+14
-23
lines changed

6 files changed

+14
-23
lines changed

components/ocrspace/actions/common/process-base.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ export default {
4545
},
4646
async run({ $ }) {
4747
const data = new FormData();
48-
const {
49-
url, file,
50-
} = getUrlOrFile(this.file);
48+
const file = await getUrlOrFile(this.file);
5149

52-
if (url) data.append("url", url);
5350
if (file) data.append("base64Image", file);
5451
if (this.imageLanguage) data.append("language", this.imageLanguage);
5552
if (this.isOverlayRequired) data.append("isOverlayRequired", `${this.isOverlayRequired}`);

components/ocrspace/actions/process-image/process-image.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "ocrspace-process-image",
66
name: "Process Image",
77
description: "Submits an image file for OCR processing using OCR.space. [See the documentation](https://ocr.space/ocrapi)",
8-
version: "0.0.1",
8+
version: "0.1.0",
99
type: "action",
1010
props: {
1111
...common.props,

components/ocrspace/actions/process-pdf/process-pdf.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "ocrspace-process-pdf",
66
name: "Process PDF for OCR",
77
description: "Submit a PDF for OCR processing. [See the documentation](https://ocr.space/ocrapi)",
8-
version: "0.0.1",
8+
version: "0.1.0",
99
type: "action",
1010
props: {
1111
...common.props,
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import fs from "fs";
2-
import mime from "mime";
1+
import { getFileStreamAndMetadata } from "@pipedream/platform";
32

43
export const isValidUrl = (urlString) => {
54
var urlPattern = new RegExp("^(https?:\\/\\/)?" + // validate protocol
@@ -18,17 +17,12 @@ export const checkTmp = (filename) => {
1817
return filename;
1918
};
2019

21-
export const getUrlOrFile = (url) => {
22-
if (!isValidUrl(url)) {
23-
const filePath = checkTmp(url);
24-
const data = fs.readFileSync(filePath);
25-
const mimeType = mime.getType(filePath);
26-
const base64Image = Buffer.from(data, "binary").toString("base64");
27-
return {
28-
file: `data:${mimeType};base64,${base64Image}`,
29-
};
30-
}
20+
export const getUrlOrFile = async (url) => {
21+
const {
22+
stream, metadata: { contentType },
23+
} = await getFileStreamAndMetadata(url);
24+
const base64Image = Buffer.from(stream, "binary").toString("base64");
3125
return {
32-
url,
26+
file: `data:${contentType};base64,${base64Image}`,
3327
};
3428
};

components/ocrspace/ocrspace.app.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export default {
1111
propDefinitions: {
1212
file: {
1313
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).",
14+
label: "File Path or URL",
15+
description: "The file to process. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.jpg`)",
1616
},
1717
language: {
1818
type: "string",

components/ocrspace/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/ocrspace",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream OCRSpace Components",
55
"main": "ocrspace.app.mjs",
66
"keywords": [
@@ -13,7 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^3.0.3",
16+
"@pipedream/platform": "^3.1.0",
1717
"mime": "^4.0.6"
1818
}
1919
}

0 commit comments

Comments
 (0)