Skip to content

Commit 154a090

Browse files
committed
updates to use getFileStream
1 parent 5a605a0 commit 154a090

File tree

71 files changed

+717
-655
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+717
-655
lines changed

components/api4ai/actions/alcohol-label-recognition/alcohol-label-recognition.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "Alcohol Label Recognition",
66
description: "Accurately identifies alcohol labels using advanced intelligent technologies. Powered by API4AI.",
77
key: "api4ai-alcohol-label-recognition",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
app,

components/api4ai/actions/background-removal/background-removal.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
description:
99
"Automatically and quickly remove image background with high accuracy. Powered by API4AI.",
1010
key: "api4ai-background-removal",
11-
version: "0.0.1",
11+
version: "0.0.2",
1212
type: "action",
1313
props: {
1414
app,

components/api4ai/actions/brand-recognition/brand-recognition.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "Brand Recognition",
66
description: "The service processes input image and responds with a list of found brand logos. Powered by API4AI.",
77
key: "api4ai-brand-recognition",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
app,

components/api4ai/actions/car-image-background-removal/car-image-background-removal.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
description:
99
"Remove Background for car images. Powered by API4AI.",
1010
key: "api4ai-car-image-background-removal",
11-
version: "0.0.1",
11+
version: "0.0.2",
1212
type: "action",
1313
props: {
1414
app,

components/api4ai/actions/furniture-and-household-item-recognition/furniture-and-household-item-recognition.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "Furniture & Household Item Recognition",
66
description: "This API provides identification of furniture & household items with advanced intelligent detection, categorization, and counting technologies. Powered by API4AI.",
77
key: "api4ai-furniture-and-household-item-recognition",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
app,

components/api4ai/actions/image-anonymization/image-anonymization.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
name: "Image Anonymization",
88
description: "Performs actual image anonymization. Powered by API4AI.",
99
key: "api4ai-image-anonymization",
10-
version: "0.0.1",
10+
version: "0.0.2",
1111
type: "action",
1212
props: {
1313
app,

components/api4ai/actions/nsfw-image-recognition/nsfw-image-recognition.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
description:
77
"Content moderation solution for NSFW (Not Safe For Work) sexual images identification. Powered by API4AI.",
88
key: "api4ai-nsfw-image-recognition",
9-
version: "0.0.1",
9+
version: "0.0.2",
1010
type: "action",
1111
props: {
1212
app,

components/api4ai/api4ai.app.mjs

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { axios } from "@pipedream/platform";
1+
import {
2+
axios, getFileStreamAndMetadata,
3+
} from "@pipedream/platform";
24
import FormData from "form-data";
3-
import fs from "node:fs";
45

56
export default {
67
type: "app",
@@ -9,63 +10,32 @@ export default {
910
image: {
1011
type: "string",
1112
label: "Image",
12-
description: "Input image. Various types are accepted:\n * a **path** to a file\n * a **URL** to a file\n * a file's content encoded as a **base64** string\n * a file's content as a **Buffer** encoded in JSON\n * a file's content as an **Array** of bytes",
13+
description: "Input image. Provide either a file URL or a path to a file in the /tmp directory (for example, /tmp/myFlie.pdf).",
1314
},
1415
},
1516
methods: {
16-
// this.$auth contains connected account data
17-
authKeys() {
18-
console.log(Object.keys(this.$auth));
19-
},
17+
streamToBuffer(stream) {
18+
return new Promise((resolve, reject) => {
19+
const chunks = [];
2020

21-
/**
22-
* Make HTTP request.
23-
*
24-
* @param {Object} $ - Pipedream.
25-
* @param {string} url - API Endpoint URL.
26-
* @param {*} image - Input image.
27-
* Various types are accepted:
28-
* - a path to a file
29-
* - a URL to a file
30-
* - a file's content encoded as a base64 string
31-
* - a file's content as a Buffer encoded in JSON
32-
* - a file's content as an Array of bytes
33-
* @param {Object} params - Query parameters.
34-
* @returns Axios response.
35-
*/
21+
stream.on("data", (chunk) => chunks.push(chunk));
22+
stream.on("end", () => resolve(Buffer.concat(chunks)));
23+
stream.on("error", reject);
24+
});
25+
},
3626
async makeRequest($, url, image, params = {}) {
3727
// Prepare form data.
38-
const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
39-
const urlregex = /^(http|ftp)s?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
4028
const form = new FormData();
41-
if (urlregex.test(image)) {
42-
console.log("Input image considered as URL");
43-
form.append("url", image);
44-
}
45-
else {
46-
let buf;
47-
if (image instanceof Buffer) {
48-
console.log("Input image considered as Buffer");
49-
buf = image;
50-
}
51-
else if ((image instanceof Object) && image.type === "Buffer") {
52-
console.log("Input image considered as JSON object with Buffer");
53-
buf = Buffer.from(image);
54-
}
55-
else if (image instanceof Array) {
56-
console.log("Input image considered as Array");
57-
buf = Buffer.from(image);
58-
}
59-
else if (base64regex.test(image)) {
60-
console.log("Input image considered as base64 string");
61-
buf = Buffer.from(image, "base64");
62-
}
63-
else {
64-
console.log("Input image considered as file path");
65-
buf = fs.readFileSync(image);
66-
}
67-
form.append("image", buf);
68-
}
29+
const {
30+
stream, metadata,
31+
} = await getFileStreamAndMetadata(image);
32+
33+
const buffer = await this.streamToBuffer(stream);
34+
form.append("image", buffer, {
35+
contentType: metadata.contentType,
36+
knownLength: metadata.size,
37+
filename: metadata.name,
38+
});
6939

7040
// Prepare headers.
7141
const headers = {

components/api4ai/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/api4ai",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Pipedream API4AI Components",
55
"main": "api4ai.app.mjs",
66
"keywords": [
@@ -27,7 +27,7 @@
2727
"homepage": "https://pipedream.com/apps/api4ai",
2828
"author": "API4AI Team <[email protected]> (https://api4.ai/)",
2929
"dependencies": {
30-
"@pipedream/platform": "^1.6.2",
30+
"@pipedream/platform": "^3.1.0",
3131
"form-data": "^4.0.0"
3232
},
3333
"publishConfig": {

components/dropbox/actions/upload-file/upload-file.mjs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import { ConfigurationError } from "@pipedream/platform";
2-
import fs from "fs";
3-
import got from "got";
1+
import { getFileStream } from "@pipedream/platform";
42
import consts from "../../common/consts.mjs";
53
import dropbox from "../../dropbox.app.mjs";
64

75
export default {
86
name: "Upload a File",
97
description: "Uploads a file to a selected folder. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesUpload__anchor)",
108
key: "dropbox-upload-file",
11-
version: "0.0.14",
9+
version: "0.0.15",
1210
type: "action",
1311
props: {
1412
dropbox,
@@ -27,17 +25,10 @@ export default {
2725
label: "File Name",
2826
description: "The name of your new file (make sure to include the file extension).",
2927
},
30-
fileUrl: {
28+
file: {
3129
type: "string",
32-
label: "File URL",
33-
description: "The URL of the file you want to upload to Dropbox. Must specify either File URL or File Path.",
34-
optional: true,
35-
},
36-
filePath: {
37-
type: "string",
38-
label: "File Path",
39-
description: "The path to the file, e.g. /tmp/myFile.csv . Must specify either File URL or File Path.",
40-
optional: true,
30+
label: "File",
31+
description: "Provide either a file URL or a path to a file in the /tmp directory (for example, /tmp/myFlie.pdf).",
4132
},
4233
autorename: {
4334
type: "boolean",
@@ -67,8 +58,7 @@ export default {
6758
},
6859
async run({ $ }) {
6960
const {
70-
fileUrl,
71-
filePath,
61+
file,
7262
path,
7363
name,
7464
autorename,
@@ -78,13 +68,7 @@ export default {
7868
clientModified,
7969
} = this;
8070

81-
if (!fileUrl && !filePath) {
82-
throw new ConfigurationError("Must specify either File URL or File Path.");
83-
}
84-
85-
const contents = fileUrl
86-
? await got.stream(fileUrl)
87-
: fs.createReadStream(filePath);
71+
const contents = await getFileStream(file);
8872

8973
let normalizedPath = this.dropbox.getNormalizedPath(path, true);
9074

0 commit comments

Comments
 (0)