Skip to content

Commit a051253

Browse files
committed
feat: allow raw response
1 parent 39e9dfe commit a051253

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default {
1818
key: "google_drive-download-file",
1919
name: "Download File",
2020
description: "Download a file. [See the documentation](https://developers.google.com/drive/api/v3/manage-downloads) for more information",
21-
version: "0.1.10",
21+
version: "0.1.11",
2222
type: "action",
2323
props: {
2424
googleDrive,
@@ -47,6 +47,7 @@ export default {
4747
directory](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory)
4848
(e.g., \`/tmp/myFile.csv\`)
4949
`),
50+
optional: true,
5051
},
5152
mimeType: {
5253
type: "string",
@@ -88,8 +89,19 @@ export default {
8889
});
8990
},
9091
},
92+
getRawResponse: {
93+
type: "boolean",
94+
label: "Get Raw Response",
95+
description: "Whether to return the file content directly in the response instead of writing to a file path",
96+
optional: true,
97+
},
9198
},
9299
async run({ $ }) {
100+
// Validate that filePath is provided when not getting raw response
101+
if (!this.getRawResponse && !this.filePath) {
102+
throw new Error("File Path is required when not using Get Raw Response");
103+
}
104+
93105
// Get file metadata to get file's MIME type
94106
const fileMetadata = await this.googleDrive.getFile(this.fileId, {
95107
fields: "name,mimeType",
@@ -113,14 +125,22 @@ export default {
113125
alt: "media",
114126
});
115127

128+
if (this.getRawResponse) {
129+
$.export("$summary", `Successfully retrieved raw content for file "${fileMetadata.name}"`);
130+
return {
131+
fileMetadata,
132+
content: file,
133+
};
134+
}
135+
116136
// Stream file to `filePath`
117137
const pipeline = promisify(stream.pipeline);
118138
const filePath = this.filePath.includes("tmp/")
119139
? this.filePath
120140
: `/tmp/${this.filePath}`;
121141
await pipeline(file, fs.createWriteStream(filePath));
122142
$.export("$summary", `Successfully downloaded the file, "${fileMetadata.name}"`);
123-
return {
143+
return {
124144
fileMetadata,
125145
filePath,
126146
};

0 commit comments

Comments
 (0)