Skip to content

Commit 4448b2a

Browse files
committed
add: platerecognizer, printautopilot, printify
1 parent bd3923b commit 4448b2a

File tree

3 files changed

+17
-39
lines changed

3 files changed

+17
-39
lines changed

components/platerecognizer/actions/run-recognition/run-recognition.mjs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { getFileStream } from "@pipedream/platform";
2-
import { checkTmp } from "../../common/utils.mjs";
32
import platerecognizer from "../../platerecognizer.app.mjs";
43

54
export default {
@@ -12,8 +11,8 @@ export default {
1211
platerecognizer,
1312
imageFileOrUrl: {
1413
type: "string",
15-
label: "Image File or URL",
16-
description: "The image file or URL to be recognized. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myImage.jpg`)",
14+
label: "Image Path or URL",
15+
description: "The image to be recognized. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myImage.jpg`)",
1716
},
1817
regions: {
1918
type: "string[]",
@@ -41,24 +40,18 @@ export default {
4140
},
4241
},
4342
async run({ $ }) {
44-
const fileObj = {};
4543

46-
if (this.imageFileOrUrl.startsWith("http")) {
47-
fileObj.upload_url = this.imageFileOrUrl;
48-
} else {
49-
const { stream } = getFileStream(checkTmp(this.imageFileOrUrl));
50-
const chunks = [];
51-
for await (const chunk of stream) {
52-
chunks.push(chunk);
53-
}
54-
const buffer = Buffer.concat(chunks);
55-
fileObj.upload = buffer.toString("base64");
44+
const stream = getFileStream(this.imageFileOrUrl);
45+
const chunks = [];
46+
for await (const chunk of stream) {
47+
chunks.push(chunk);
5648
}
49+
const buffer = Buffer.concat(chunks);
5750

5851
const response = await this.platerecognizer.runRecognition({
5952
$,
6053
data: {
61-
...fileObj,
54+
upload: buffer.toString("base64"),
6255
regions: this.regions,
6356
camera_id: this.cameraId,
6457
mmc: this.mmc,

components/printautopilot/actions/add-pdf-to-queue/add-pdf-to-queue.mjs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ export default {
2727
},
2828
},
2929
async run({ $ }) {
30-
const filePath = this.filePath.includes("/tmp")
31-
? this.filePath
32-
: `/tmp/${this.filePath}`;
33-
34-
const { stream } = getFileStream(filePath);
30+
const stream = getFileStream(this.filePath);
3531
const chunks = [];
3632
for await (const chunk of stream) {
3733
chunks.push(chunk);

components/printify/actions/create-product/create-product.mjs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { getFileStream } from "@pipedream/platform";
2-
import {
3-
checkTmp, isValidHttpUrl,
4-
} from "../../common/utils.mjs";
2+
import { checkTmp } from "../../common/utils.mjs";
53
import printify from "../../printify.app.mjs";
64

75
export default {
@@ -119,7 +117,7 @@ export default {
119117
props[`imagePath_${i}`] = {
120118
type: "string",
121119
label: `Image Path or URL ${i}`,
122-
description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myImage.jpg`).",
120+
description: `The file to upload for image ${i}. Provide either a file URL or a path to a file in the \`/tmp\` directory (for example, \`/tmp/myImage.jpg\`).`,
123121
};
124122
props[`imageX_${i}`] = {
125123
type: "string",
@@ -157,22 +155,13 @@ export default {
157155
}
158156
for (let i = 1; i <= this.imageCount; i++) {
159157
const imageString = this[`imagePath_${i}`];
160-
161-
let file = "";
162-
let fieldName = "";
163-
164-
if (isValidHttpUrl(imageString)) {
165-
file = imageString;
166-
fieldName = "url";
167-
} else {
168-
const { stream } = getFileStream(checkTmp(imageString));
169-
const chunks = [];
170-
for await (const chunk of stream) {
171-
chunks.push(chunk);
172-
}
173-
file = Buffer.concat(chunks).toString("base64");
174-
fieldName = "contents";
158+
const stream = getFileStream(checkTmp(imageString));
159+
const chunks = [];
160+
for await (const chunk of stream) {
161+
chunks.push(chunk);
175162
}
163+
const file = Buffer.concat(chunks).toString("base64");
164+
const fieldName = "contents";
176165

177166
const responseImage = await this.printify.uploadImage({
178167
data: {

0 commit comments

Comments
 (0)