Skip to content

Commit 070d248

Browse files
authored
Add optional file download URL to file-related source emits (#18269)
* add includeLink * pnpm-lock.yaml * versions * pnpm-lock.yaml * updates * pnpm-lock.yaml * updates * updates * versions * versions
1 parent 6634864 commit 070d248

File tree

103 files changed

+781
-136
lines changed

Some content is hidden

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

103 files changed

+781
-136
lines changed

components/aws/.upm/store.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":2,"languages":{"nodejs-npm":{"guessedImports":["aws-sdk","axios","shortid"],"guessedImportsHash":"08190b61ee0169fd35ea81dce6f4754d"}}}
1+
{"version":2, "languages":{"nodejs-npm":{"guessedImports":["aws-sdk", "axios", "shortid"], "guessedImportsHash":"08190b61ee0169fd35ea81dce6f4754d"}}}

components/aws/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/aws",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Pipedream Aws Components",
55
"main": "aws.app.mjs",
66
"keywords": [
@@ -34,6 +34,7 @@
3434
"@pipedream/platform": "^3.1.0",
3535
"adm-zip": "^0.5.10",
3636
"dedent": "^1.5.1",
37+
"file-type": "^21.0.0",
3738
"mailparser": "^3.6.6",
3839
"mailparser-mit": "^1.0.0",
3940
"nanoid": "^5.0.4",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Readable } from "stream";
2+
import { fileTypeFromBuffer } from "file-type";
3+
4+
export default {
5+
props: {
6+
includeLink: {
7+
label: "Include Link",
8+
type: "boolean",
9+
description: "Upload file to your File Stash and emit temporary download link to the file. See [the docs](https://pipedream.com/docs/connect/components/files) to learn more about working with files in Pipedream.",
10+
default: false,
11+
optional: true,
12+
},
13+
dir: {
14+
type: "dir",
15+
accessMode: "write",
16+
optional: true,
17+
},
18+
},
19+
methods: {
20+
async streamToBuffer(stream) {
21+
const chunks = [];
22+
for await (const chunk of stream) {
23+
chunks.push(chunk);
24+
}
25+
return Buffer.concat(chunks);
26+
},
27+
async stashFile(item) {
28+
const { Body } = await this.getObject({
29+
Bucket: item.bucket.name,
30+
Key: item.object.key.replace(/\+/g, " "),
31+
});
32+
const filepath = `${item.bucket.name}/${item.object.key}`;
33+
const buffer = await this.streamToBuffer(Body);
34+
const type = await fileTypeFromBuffer(buffer);
35+
// Upload the attachment to the configured directory (File Stash) so it
36+
// can be accessed later.
37+
const file = await this.dir.open(filepath).fromReadableStream(
38+
Readable.from(buffer),
39+
type?.mime,
40+
buffer.length,
41+
);
42+
// Return file details and temporary download link:
43+
// { path, get_url, s3Key, type }
44+
return await file.withoutPutUrl().withGetUrl();
45+
},
46+
async processEvent(event) {
47+
const { Message: rawMessage } = event.body;
48+
const {
49+
Records: s3Events = [],
50+
Event: eventType,
51+
} = JSON.parse(rawMessage);
52+
53+
if (eventType === "s3:TestEvent") {
54+
console.log("Received initial test event. Skipping...");
55+
return;
56+
}
57+
58+
for (const s3Event of s3Events) {
59+
const meta = this.generateMeta(s3Event);
60+
let { s3: item } = s3Event;
61+
if (this.includeLink) {
62+
item.file = await this.stashFile(item);
63+
}
64+
this.$emit(item, meta);
65+
}
66+
},
67+
},
68+
};

components/aws/sources/s3-new-file/s3-new-file.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import base from "../common/s3.mjs";
2+
import includeLink from "../common/include-link.mjs";
23

34
export default {
45
...base,
56
type: "source",
67
key: "aws-s3-new-file",
78
name: "New S3 File",
89
description: "Emit new event when a file is added to an S3 bucket",
9-
version: "0.1.4",
10+
version: "0.2.0",
1011
dedupe: "unique",
12+
props: {
13+
...base.props,
14+
...includeLink.props,
15+
},
1116
methods: {
1217
...base.methods,
18+
...includeLink.methods,
1319
getEvents() {
1420
return [
1521
"s3:ObjectCreated:*",

components/aws/sources/s3-restored-file/s3-restored-file.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
import base from "../common/s3.mjs";
2+
import includeLink from "../common/include-link.mjs";
23

34
export default {
45
...base,
56
type: "source",
67
key: "aws-s3-restored-file",
78
name: "New Restored S3 File",
8-
description: "Emit new event when an file is restored into a S3 bucket",
9-
version: "0.1.4",
9+
description: "Emit new event when a file is restored into an S3 bucket",
10+
version: "0.2.0",
1011
dedupe: "unique",
1112
props: {
13+
info: {
14+
type: "alert",
15+
alertType: "info",
16+
content: "Allows receipt of notifications for event initiation and completion when restoring objects from the **S3 Glacier Flexible Retrieval** storage class, **S3 Glacier Deep Archive** storage class, **S3 Intelligent-Tiering Archive Access tier**, and **S3 Intelligent-Tiering Deep Archive Access tier**.",
17+
},
1218
...base.props,
1319
detectRestoreInitiation: {
1420
type: "boolean",
1521
label: "Detect Restore Initiation",
1622
description: "When enabled, this event source will also emit events whenever a restore is initiated",
1723
default: false,
1824
},
25+
...includeLink.props,
1926
},
2027
methods: {
2128
...base.methods,
29+
...includeLink.methods,
2230
getEvents() {
2331
return [
2432
this.detectRestoreInitiation

components/box/actions/create-sign-request/create-sign-request.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
name: "Create Box Sign Request",
77
description: "Creates a signature request. This involves preparing a document for signing and sending the signature request to signers. [See the documentation](https://developer.box.com/reference/post-sign-requests/).",
88
key: "box-create-sign-request",
9-
version: "0.0.1",
9+
version: "0.0.2",
1010
type: "action",
1111
props: {
1212
app,

components/box/actions/download-file/download-file.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
name: "Download File",
88
description: "Downloads a file from Box to your workflow's `/tmp` directory. [See the documentation](https://developer.box.com/reference/get-files-id-content/)",
99
key: "box-download-file",
10-
version: "0.0.4",
10+
version: "0.0.5",
1111
type: "action",
1212
props: {
1313
app,

components/box/actions/get-comments/get-comments.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "Get Comments",
66
description: "Fetches comments for a file. [See the documentation](https://developer.box.com/reference/get-files-id-comments/).",
77
key: "box-get-comments",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
app,

components/box/actions/search-content/search-content.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
name: "Search Content",
77
description: "Searches for files, folders, web links, and shared files across the users content or across the entire enterprise. [See the documentation](https://developer.box.com/reference/get-search/).",
88
key: "box-search-content",
9-
version: "0.0.4",
9+
version: "0.0.5",
1010
type: "action",
1111
props: {
1212
app,

components/box/actions/upload-file-version/upload-file-version.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "Upload File Version",
66
description: "Update a file's content. [See the documentation](https://developer.box.com/reference/post-files-id-content/).",
77
key: "box-upload-file-version",
8-
version: "0.1.1",
8+
version: "0.1.2",
99
type: "action",
1010
props: {
1111
app,

0 commit comments

Comments
 (0)