Skip to content

Commit 3741b91

Browse files
authored
Part 2 - applying File URL or Path improvements (#17091)
* pnpm * Updating _2markdown and mapbox * Akeneo and LLMWhisperer apps * pnpm * add: askyourpdf * add: fileforge * adjusting existing descriptions and platform versions * Description updates * add: microsoft_onedrive, mistral_ai, onlyoffice_docspace * add: slack * add: stannp, zamzar, zoho_desk * add box upload-file * add: monday, nyckel * add: ocrspace * add: onlinecheckwriter, pandadoc, pdf4me * Onedrive adjustment * pnpm * adjusting Slack and Pandadoc * updates to include metadata in all formdatas * pnpm * fix * pnpm * CodeRabbit fixes * Fixing box and nyckel * fix mapbox * add: autodesk, cradl_ai, docsbot_ai * pnpm * add: egnyte, flippingbook * add: happy_scribe, ilovepdf * add: lokalise, podio, zoho_crm * add: openai, imagga * add: google_drive * add: openai (remaining actions) * add: airparser, alttext_ai * add: azure_storage, boldsign * add: canva * add: claid_ai * update package.json * pdf4me: readding std filename check to action * Adjusting zoho_desk formdata building * Merge branch 'master' into 16977-applying-fileurl-paths-improvement * pnpm * fix: alttext_ai, box * description improvements: docsbot_ai, lokalise * fix: openai * Improving OpenAI image handling * openai-chat fixes
1 parent 68fd17d commit 3741b91

File tree

136 files changed

+946
-1289
lines changed

Some content is hidden

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

136 files changed

+946
-1289
lines changed

components/_2markdown/_2markdown.app.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default {
66
propDefinitions: {
77
filePath: {
88
type: "string",
9-
label: "File Path",
10-
description: "The path to an HTML file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
9+
label: "File Path or URL",
10+
description: "An HTML file. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.html`)",
1111
},
1212
},
1313
methods: {

components/_2markdown/actions/html-file-to-markdown/html-file-to-markdown.mjs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import _2markdown from "../../_2markdown.app.mjs";
2-
import fs from "fs";
2+
import { getFileStreamAndMetadata } from "@pipedream/platform";
33
import FormData from "form-data";
44

55
export default {
66
key: "_2markdown-html-file-to-markdown",
77
name: "HTML File to Markdown",
88
description: "Convert an HTML file to Markdown format. [See the documentation](https://2markdown.com/docs#file2md)",
9-
version: "0.0.1",
9+
version: "0.1.0",
1010
type: "action",
1111
props: {
1212
_2markdown,
@@ -20,9 +20,14 @@ export default {
2020
async run({ $ }) {
2121
const form = new FormData();
2222

23-
form.append("document", fs.createReadStream(this.filePath.includes("tmp/")
24-
? this.filePath
25-
: `/tmp/${this.filePath}`));
23+
const {
24+
stream, metadata,
25+
} = await getFileStreamAndMetadata(this.filePath);
26+
form.append("document", stream, {
27+
contentType: metadata.contentType,
28+
knownLength: metadata.size,
29+
filename: metadata.name,
30+
});
2631

2732
const response = await this._2markdown.htmlFileToMarkdown({
2833
$,

components/_2markdown/actions/pdf-to-markdown/pdf-to-markdown.mjs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import _2markdown from "../../_2markdown.app.mjs";
2-
import fs from "fs";
2+
import { getFileStreamAndMetadata } from "@pipedream/platform";
33
import FormData from "form-data";
44

55
export default {
66
key: "_2markdown-pdf-to-markdown",
77
name: "PDF to Markdown",
88
description: "Convert a PDF document to Markdown format. [See the documentation](https://2markdown.com/docs#pdf2md)",
9-
version: "0.0.1",
9+
version: "0.1.0",
1010
type: "action",
1111
props: {
1212
_2markdown,
@@ -15,7 +15,7 @@ export default {
1515
_2markdown,
1616
"filePath",
1717
],
18-
description: "The path to a PDF file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
18+
description: "A PDF file. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.pdf`)",
1919
},
2020
waitForCompletion: {
2121
type: "boolean",
@@ -27,9 +27,14 @@ export default {
2727
async run({ $ }) {
2828
const form = new FormData();
2929

30-
form.append("document", fs.createReadStream(this.filePath.includes("tmp/")
31-
? this.filePath
32-
: `/tmp/${this.filePath}`));
30+
const {
31+
stream, metadata,
32+
} = await getFileStreamAndMetadata(this.filePath);
33+
form.append("document", stream, {
34+
contentType: metadata.contentType,
35+
knownLength: metadata.size,
36+
filename: metadata.name,
37+
});
3338

3439
let response = await this._2markdown.pdfToMarkdown({
3540
$,

components/_2markdown/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/_2markdown",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream 2markdown Components",
55
"main": "_2markdown.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
"form-data": "^4.0.1"
1818
}
1919
}

components/airparser/actions/upload-document-parse/upload-document-parse.mjs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import airparser from "../../airparser.app.mjs";
2-
import fs from "fs";
2+
import { getFileStreamAndMetadata } from "@pipedream/platform";
33
import FormData from "form-data";
44

55
export default {
66
key: "airparser-upload-document-parse",
77
name: "Upload Document and Parse",
88
description: "Uploads a document into the inbox for data extraction. [See the documentation](https://help.airparser.com/public-api/public-api)",
9-
version: "0.0.1",
9+
version: "0.1.0",
1010
type: "action",
1111
props: {
1212
airparser,
@@ -18,8 +18,8 @@ export default {
1818
},
1919
filePath: {
2020
type: "string",
21-
label: "File Path",
22-
description: "The path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp).",
21+
label: "File Path or URL",
22+
description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
2323
},
2424
metadata: {
2525
type: "object",
@@ -29,11 +29,15 @@ export default {
2929
},
3030
},
3131
async run({ $ }) {
32-
const fileStream = fs.createReadStream(this.filePath.includes("tmp/")
33-
? this.filePath
34-
: `/tmp/${this.filePath}`);
32+
const {
33+
stream, metadata,
34+
} = await getFileStreamAndMetadata(this.filePath);
3535
const data = new FormData();
36-
data.append("file", fileStream);
36+
data.append("file", stream, {
37+
contentType: metadata.contentType,
38+
knownLength: metadata.size,
39+
filename: metadata.name,
40+
});
3741
if (this.metadata) {
3842
data.append("meta", JSON.stringify(this.metadata));
3943
}

components/airparser/package.json

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

components/akeneo/actions/create-a-new-product-media-file/create-a-new-product-media-file.mjs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import app from "../../akeneo.app.mjs";
2-
import utils from "../../common/utils.mjs";
3-
import { ConfigurationError } from "@pipedream/platform";
2+
import {
3+
ConfigurationError, getFileStreamAndMetadata,
4+
} from "@pipedream/platform";
45
import FormData from "form-data";
5-
import fs from "fs";
66

77
export default {
88
type: "action",
99
key: "akeneo-create-a-new-product-media-file",
10-
version: "0.0.1",
10+
version: "0.1.0",
1111
name: "Create A New Product Media File",
1212
description: "Allows you to create a new media file and associate it to an attribute value of a given product or product model. [See the docs](https://api.akeneo.com/api-reference.html#post_media_files)",
1313
props: {
@@ -32,18 +32,15 @@ export default {
3232
},
3333
filename: {
3434
type: "string",
35-
label: "File",
36-
description: "The file to be uploaded, please provide a file from `/tmp`. To upload a file to `/tmp` folder, please follow the doc [here](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
35+
label: "File Path or URL",
36+
description: "The file to be uploaded. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
3737
},
3838
},
3939
async run ({ $ }) {
4040
if (!this.productId && !this.productModelCode) {
4141
throw new ConfigurationError("Either `Product Identifier` or `Product Model Code` should be set!");
4242
}
43-
const path = utils.checkTmp(this.filename);
44-
if (!fs.existsSync(path)) {
45-
throw new ConfigurationError("File does not exist!");
46-
}
43+
4744
const payload = {
4845
attribute: this.mediaFileAttributeCode,
4946
scope: null,
@@ -57,9 +54,15 @@ export default {
5754
payload.code = this.productModelCode;
5855
data.append("product_model", JSON.stringify(payload));
5956
}
60-
const file = fs.readFileSync(path);
61-
const fileParts = path.split("/");
62-
data.append("file", file, fileParts[fileParts.length - 1]);
57+
58+
const {
59+
stream, metadata,
60+
} = await getFileStreamAndMetadata(this.filename);
61+
data.append("file", stream, {
62+
contentType: metadata.contentType,
63+
knownLength: metadata.size,
64+
filename: metadata.name,
65+
});
6366
const contentLength = data.getLengthSync();
6467
await this.app.createProductMediaFile({
6568
$,

components/akeneo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/akeneo",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream Akeneo Components",
55
"main": "akeneo.app.mjs",
66
"keywords": [
@@ -10,7 +10,7 @@
1010
"homepage": "https://pipedream.com/apps/akeneo",
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"dependencies": {
13-
"@pipedream/platform": "^1.3.0",
13+
"@pipedream/platform": "^3.1.0",
1414
"form-data": "^4.0.0"
1515
},
1616
"publishConfig": {

components/alttext_ai/actions/generate-alt-text/generate-alt-text.mjs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
import alttextAi from "../../alttext_ai.app.mjs";
2-
import fs from "fs";
2+
import {
3+
ConfigurationError, getFileStream,
4+
} from "@pipedream/platform";
35
import { LANGUAGE_OPTIONS } from "../../commons/constants.mjs";
4-
import { ConfigurationError } from "@pipedream/platform";
56

67
export default {
78
key: "alttext_ai-generate-alt-text",
89
name: "Generate Alt Text",
910
description:
1011
"Generates a descriptive alt text for a given image. [See the documentation](https://alttext.ai/apidocs#tag/Images/operation/create-image)",
11-
version: "0.0.1",
12+
version: "0.1.0",
1213
type: "action",
1314
props: {
1415
alttextAi,
16+
fileInfo: {
17+
type: "alert",
18+
alertType: "warning",
19+
content: "Either `Image Data` or `Image File Path or URL` should be provided. If both are provided, `Image Data` will be used.",
20+
},
1521
imageData: {
1622
type: "string",
1723
label: "Image Data",
1824
description:
19-
"The image data in base64 format. Only one of `Image Data`, `Image File Path` or `Image URL` should be specified.",
20-
optional: true,
21-
},
22-
imageUrl: {
23-
type: "string",
24-
label: "Image URL",
25-
description:
26-
"The public URL to an image. Only one of `Image URL`, `Image Data` or `Image File Path` should be specified.",
25+
"The image data in base64 format",
2726
optional: true,
2827
},
2928
imageFilePath: {
3029
type: "string",
31-
label: "Image File Path",
30+
label: "Image File Path or URL",
3231
description:
33-
"The path to an image file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#the-tmp-directory). Only one of `Image File Path`, `Image URL` or `Image Data` should be specified.",
32+
"The image to process. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myImage.jpg`)",
3433
optional: true,
3534
},
3635
keywords: {
@@ -64,31 +63,29 @@ export default {
6463
},
6564
},
6665
async run({ $ }) {
67-
if (
68-
(!this.imageData && !this.imageFilePath && !this.imageUrl)
69-
|| (this.imageData && this.imageFilePath)
70-
|| (this.imageData && this.imageUrl)
71-
|| (this.imageFilePath && this.imageUrl)
72-
) {
73-
throw new ConfigurationError("Only one of `Image Data`, `Image File Path` or `Image URL` should be specified.");
66+
const {
67+
imageData, imageFilePath,
68+
} = this;
69+
if (!imageData && !imageFilePath) {
70+
throw new ConfigurationError("Either `Image Data` or `Image File Path or URL` should be specified.");
71+
}
72+
73+
let rawData = imageData;
74+
if (!rawData) {
75+
const stream = await getFileStream(imageFilePath);
76+
const chunks = [];
77+
for await (const chunk of stream) {
78+
chunks.push(chunk);
79+
}
80+
const buffer = Buffer.concat(chunks);
81+
rawData = buffer.toString("base64");
7482
}
7583

7684
const response = await this.alttextAi.generateAltText({
7785
$,
7886
data: {
7987
image: {
80-
url: this.imageUrl,
81-
raw:
82-
this.imageData ??
83-
(this.imageFilePath &&
84-
fs.readFileSync(
85-
this.imageFilePath.includes("tmp/")
86-
? this.imageFilePath
87-
: `/tmp/${this.imageFilePath}`,
88-
{
89-
encoding: "base64",
90-
},
91-
)),
88+
raw: rawData,
9289
},
9390
keywords: this.keywords,
9491
negative_keywords: this.negativeKeywords,

components/alttext_ai/package.json

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

components/askyourpdf/actions/add-document-via-file-upload/add-document-via-file-upload.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export default {
66
name: "Add Document Via File Upload",
77
description: "Add a document via file upload. [See the documentation](https://docs.askyourpdf.com/askyourpdf-docs/#2.-adding-document-via-file-upload)",
88
type: "action",
9-
version: "0.0.2",
9+
version: "0.1.0",
1010
props: {
1111
app,
1212
file: {
1313
type: "string",
14-
label: "File Path",
15-
description: "File path of a file previously downloaded in Pipedream E.g. (`/tmp/my-file.txt`). [Download a file to the `/tmp` directory](https://pipedream.com/docs/code/nodejs/http-requests/#download-a-file-to-the-tmp-directory)",
14+
label: "File Path or URL",
15+
description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
1616
},
1717
},
1818
methods: {

components/askyourpdf/askyourpdf.app.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ export default {
2727
...headers,
2828
};
2929
},
30-
getConfig({
30+
async getConfig({
3131
headers, data: preData, ...args
3232
} = {}) {
3333
const contentType = constants.CONTENT_TYPE_KEY_HEADER;
3434
const hasMultipartHeader = utils.hasMultipartHeader(headers);
35-
const data = hasMultipartHeader && utils.getFormData(preData) || preData;
35+
const data = hasMultipartHeader && await utils.getFormData(preData) || preData;
3636
const currentHeaders = this.getHeaders(headers);
3737

3838
return {
@@ -49,7 +49,7 @@ export default {
4949
async makeRequest({
5050
step = this, path, headers, data, summary, ...args
5151
} = {}) {
52-
const config = this.getConfig({
52+
const config = await this.getConfig({
5353
url: this.getUrl(path),
5454
headers,
5555
data,

0 commit comments

Comments
 (0)