Skip to content

Commit cd649c0

Browse files
committed
[Components] Support file URLS and file paths in a single prop input
1 parent 7851ded commit cd649c0

File tree

153 files changed

+1245
-1336
lines changed

Some content is hidden

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

153 files changed

+1245
-1336
lines changed

.github/workflows/pull-request-checks.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ jobs:
9696
format: 'csv'
9797
# NOTE: These steps are kept in this workflow to avoid re-rerunning the rest of the lint job
9898
# in the Components Checks workflow
99+
- name: Build TypeScript Components
100+
run: pnpm build
99101
- name: Check component keys
100102
run: node scripts/findBadKeys.js ${{ steps.changed_files.outputs.added_modified }} ${{ steps.changed_files.outputs.renamed }}
101103
- name: Check component app prop

components/aws/actions/s3-stream-file/s3-stream-file.mjs

Lines changed: 0 additions & 62 deletions
This file was deleted.

components/aws/actions/s3-upload-file/s3-upload-file.mjs renamed to components/aws/actions/s3-upload-base64-as-file/s3-upload-base64-as-file.mjs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import common from "../../common/common-s3.mjs";
2-
import { toSingleLineString } from "../../common/utils.mjs";
32

43
export default {
54
...common,
6-
key: "aws-s3-upload-file",
7-
name: "S3 - Upload File - Base64",
8-
description: toSingleLineString(`
9-
Accepts a base64-encoded string and a filename, then uploads as a file to S3.
10-
[See the docs](https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html)
11-
`),
12-
version: "0.3.2",
5+
key: "aws-s3-upload-base64-as-file",
6+
name: "S3 - Upload Base64 As File",
7+
description: "Accepts a base64-encoded string and a filename, then uploads as a file to S3. [See the documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html)",
8+
version: "0.0.1",
139
type: "action",
1410
props: {
1511
aws: common.props.aws,

components/aws/actions/s3-upload-file-url/s3-upload-file-url.mjs

Lines changed: 0 additions & 43 deletions
This file was deleted.

components/aws/actions/s3-upload-file-tmp/s3-upload-file-tmp.mjs renamed to components/aws/actions/s3-upload-files/s3-upload-files.mjs

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import common from "../../common/common-s3.mjs";
2-
import fs from "fs";
31
import { join } from "path";
4-
import { toSingleLineString } from "../../common/utils.mjs";
5-
import { ConfigurationError } from "@pipedream/platform";
2+
import fs from "fs";
3+
import {
4+
getFileStreamAndMetadata,
5+
ConfigurationError,
6+
} from "@pipedream/platform";
7+
import common from "../../common/common-s3.mjs";
68

79
export default {
810
...common,
9-
key: "aws-s3-upload-file-tmp",
10-
name: "S3 - Upload Files - /tmp",
11-
description: toSingleLineString(`
12-
Accepts a file path or folder path starting from /tmp, then uploads the contents to S3.
13-
[See the docs](https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html)
14-
`),
15-
version: "1.0.3",
11+
key: "aws-s3-upload-files",
12+
name: "S3 - Upload Files",
13+
description: "Upload files to S3. Accepts either a file URL, a local file path, or a directory path. [See the documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html)",
14+
version: "0.0.1",
1615
type: "action",
1716
props: {
1817
aws: common.props.aws,
@@ -25,8 +24,8 @@ export default {
2524
},
2625
path: {
2726
type: "string",
28-
label: "File Or Folder Path",
29-
description: "Path starting from `/tmp`. If it's a directory, all files will be uploaded.",
27+
label: "File Path, Url, Or Folder Path",
28+
description: "Provide either a file URL, a path to a file in the `/tmp` directory (for example, `/tmp/myFile.pdf`), or a directory path to upload all files.",
3029
},
3130
customFilename: {
3231
type: common.props.key.type,
@@ -37,6 +36,17 @@ export default {
3736
},
3837
methods: {
3938
...common.methods,
39+
streamToBase64(stream) {
40+
return new Promise((resolve, reject) => {
41+
const chunks = [];
42+
stream.on("data", (chunk) => chunks.push(chunk));
43+
stream.on("end", () => {
44+
const buffer = Buffer.concat(chunks);
45+
resolve(buffer.toString("base64"));
46+
});
47+
stream.on("error", reject);
48+
});
49+
},
4050
getFilesRecursive(dir) {
4151
let results = [];
4252
const items = fs.readdirSync(dir);
@@ -59,16 +69,19 @@ export default {
5969
} = this;
6070
const files = this.getFilesRecursive(folderPath);
6171
const response = await Promise.all(files.map(async (filePath) => {
62-
const fileContent = fs.readFileSync(filePath, {
63-
encoding: "base64",
64-
});
72+
const {
73+
stream,
74+
metadata,
75+
} = await getFileStreamAndMetadata(filePath);
6576
const relativePath = filePath.substring(folderPath.length + 1);
6677
const s3Key = join(prefix, relativePath);
6778

6879
await uploadFile({
6980
Bucket: bucket,
7081
Key: s3Key,
71-
Body: Buffer.from(fileContent, "base64"),
82+
Body: stream,
83+
ContentType: metadata.contentType,
84+
ContentLength: metadata.size,
7285
});
7386
return {
7487
filePath,
@@ -87,15 +100,18 @@ export default {
87100
customFilename,
88101
} = this;
89102

90-
const file = fs.readFileSync(filePath, {
91-
encoding: "base64",
92-
});
103+
const {
104+
stream,
105+
metadata,
106+
} = await getFileStreamAndMetadata(filePath);
93107
const filename = customFilename || filePath.split("/").pop();
94108

95109
const response = await uploadFile({
96110
Bucket: bucket,
97111
Key: join(prefix, filename),
98-
Body: Buffer.from(file, "base64"),
112+
Body: stream,
113+
ContentType: metadata.contentType,
114+
ContentLength: metadata.size,
99115
});
100116

101117
$.export("$summary", `Uploaded file ${filename} to S3`);
@@ -108,9 +124,17 @@ export default {
108124
uploadFolderFiles,
109125
path,
110126
} = this;
127+
128+
// If path is a URL, treat it as a single file
129+
if (path.startsWith("http://") || path.startsWith("https://")) {
130+
return await uploadSingleFile($, path);
131+
}
132+
133+
// For local paths, check if it exists
111134
if (!fs.existsSync(path)) {
112135
throw new ConfigurationError(`The file or directory path \`${path}\` does not exist. Please verify the path and include the leading /tmp if needed.`);
113136
}
137+
114138
const stat = fs.statSync(path);
115139
return stat.isDirectory()
116140
? await uploadFolderFiles($, path)

components/aws/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/aws",
3-
"version": "0.7.9",
3+
"version": "1.0.0",
44
"description": "Pipedream Aws Components",
55
"main": "aws.app.mjs",
66
"keywords": [
@@ -29,7 +29,7 @@
2929
"@aws-sdk/s3-request-presigner": "^3.609.0",
3030
"@aws-sdk/signature-v4-crt": "^3.731.0",
3131
"@pipedream/helper_functions": "^0.3.6",
32-
"@pipedream/platform": "^3.0.3",
32+
"@pipedream/platform": "^3.1.0",
3333
"adm-zip": "^0.5.10",
3434
"dedent": "^1.5.1",
3535
"mailparser": "^3.6.6",

components/click2mail2/actions/create-document/create-document.mjs

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
import FormData from "form-data";
2-
import fs from "fs";
2+
import { getFileStreamAndMetadata } from "@pipedream/platform";
33
import click2mail2 from "../../click2mail2.app.mjs";
44
import { FORMATS } from "../../common/constants.mjs";
55

66
export default {
77
key: "click2mail2-create-document",
88
name: "Create Document",
9-
version: "0.0.1",
9+
version: "1.0.0",
1010
description: "Creates a new document in your account from an uploaded file or a URL. [See the documentation for file](https://developers.click2mail.com/reference/createdocument_1). [See the documentation for URL](https://developers.click2mail.com/reference/createdocumentfromurl)",
1111
type: "action",
1212
props: {
1313
click2mail2,
14-
uploadType: {
15-
type: "string",
16-
label: "Upload Type",
17-
description: "The type of the upload.",
18-
reloadProps: true,
19-
options: [
20-
"URL",
21-
"File",
22-
],
23-
},
2414
documentName: {
2515
type: "string",
2616
label: "Document Name",
@@ -39,49 +29,51 @@ export default {
3929
"documentClass",
4030
],
4131
},
42-
},
43-
async additionalProps() {
44-
const props = {};
45-
if (this.uploadType === "URL") {
46-
props.url = {
47-
type: "string",
48-
label: "URL",
49-
description: "Document url",
50-
};
51-
} else {
52-
props.file = {
53-
type: "string",
54-
label: "File",
55-
description: "Path of the file in /tmp folder. 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)",
56-
};
57-
}
58-
return props;
32+
file: {
33+
type: "string",
34+
label: "File Path Or Url",
35+
description: "Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.pdf`).",
36+
},
5937
},
6038
async run({ $ }) {
6139
const {
6240
click2mail2,
63-
uploadType,
6441
file,
6542
...params
6643
} = this;
6744

45+
const isUrl = file.startsWith("http://") || file.startsWith("https://");
6846
let objToSend = {};
6947

70-
if (uploadType === "File") {
48+
if (!isUrl) {
49+
const {
50+
stream, metadata,
51+
} = await getFileStreamAndMetadata(file);
7152
const formData = new FormData();
72-
formData.append("file", fs.createReadStream(file));
53+
formData.append("file", stream, {
54+
contentType: metadata.contentType,
55+
knownLength: metadata.size,
56+
filename: metadata.name,
57+
});
7358

7459
objToSend = {
7560
data: formData,
7661
headers: formData.getHeaders(),
7762
};
63+
} else {
64+
objToSend = {
65+
params: {
66+
...params,
67+
url: file,
68+
},
69+
};
7870
}
71+
7972
const response = await click2mail2.create({
8073
$,
81-
path: `${uploadType === "File"
74+
path: `${!isUrl
8275
? "documents"
8376
: "documents/url"}`,
84-
params,
8577
...objToSend,
8678
});
8779

components/click2mail2/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/click2mail2",
3-
"version": "0.1.0",
3+
"version": "1.0.0",
44
"description": "Pipedream Click2Mail Components",
55
"main": "click2mail2.app.mjs",
66
"keywords": [
@@ -13,9 +13,8 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^1.5.1",
16+
"@pipedream/platform": "^3.1.0",
1717
"form-data": "^4.0.0",
1818
"fs": "^0.0.1-security"
1919
}
2020
}
21-

0 commit comments

Comments
 (0)