@pipedream/google_drive 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -18,7 +18,7 @@ export default {
|
|
|
18
18
|
key: "google_drive-download-file",
|
|
19
19
|
name: "Download File",
|
|
20
20
|
description: "Download a file. [See the documentation](https://developers.google.com/drive/api/v3/manage-downloads) for more information",
|
|
21
|
-
version: "0.1.
|
|
21
|
+
version: "0.1.12",
|
|
22
22
|
type: "action",
|
|
23
23
|
props: {
|
|
24
24
|
googleDrive,
|
|
@@ -47,6 +47,7 @@ export default {
|
|
|
47
47
|
directory](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory)
|
|
48
48
|
(e.g., \`/tmp/myFile.csv\`)
|
|
49
49
|
`),
|
|
50
|
+
optional: true,
|
|
50
51
|
},
|
|
51
52
|
mimeType: {
|
|
52
53
|
type: "string",
|
|
@@ -93,8 +94,19 @@ export default {
|
|
|
93
94
|
accessMode: "write",
|
|
94
95
|
sync: true,
|
|
95
96
|
},
|
|
97
|
+
getBufferResponse: {
|
|
98
|
+
type: "boolean",
|
|
99
|
+
label: "Get Buffer Response",
|
|
100
|
+
description: "Whether to return the file content as a buffer instead of writing to a file path",
|
|
101
|
+
optional: true,
|
|
102
|
+
},
|
|
96
103
|
},
|
|
97
104
|
async run({ $ }) {
|
|
105
|
+
// Validate that filePath is provided when not getting raw response
|
|
106
|
+
if (!this.getBufferResponse && !this.filePath) {
|
|
107
|
+
throw new Error("File Path is required when not using Get Buffer Response");
|
|
108
|
+
}
|
|
109
|
+
|
|
98
110
|
// Get file metadata to get file's MIME type
|
|
99
111
|
const fileMetadata = await this.googleDrive.getFile(this.fileId, {
|
|
100
112
|
fields: "name,mimeType",
|
|
@@ -118,6 +130,22 @@ export default {
|
|
|
118
130
|
alt: "media",
|
|
119
131
|
});
|
|
120
132
|
|
|
133
|
+
if (this.getBufferResponse) {
|
|
134
|
+
$.export("$summary", `Successfully retrieved raw content for file "${fileMetadata.name}"`);
|
|
135
|
+
|
|
136
|
+
// Convert stream to buffer
|
|
137
|
+
const chunks = [];
|
|
138
|
+
for await (const chunk of file) {
|
|
139
|
+
chunks.push(chunk);
|
|
140
|
+
}
|
|
141
|
+
const buffer = Buffer.concat(chunks);
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
fileMetadata,
|
|
145
|
+
content: buffer,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
121
149
|
// Stream file to `filePath`
|
|
122
150
|
const pipeline = promisify(stream.pipeline);
|
|
123
151
|
const filePath = this.filePath.includes("tmp/")
|
|
@@ -125,7 +153,7 @@ export default {
|
|
|
125
153
|
: `/tmp/${this.filePath}`;
|
|
126
154
|
await pipeline(file, fs.createWriteStream(filePath));
|
|
127
155
|
$.export("$summary", `Successfully downloaded the file, "${fileMetadata.name}"`);
|
|
128
|
-
return
|
|
156
|
+
return {
|
|
129
157
|
fileMetadata,
|
|
130
158
|
filePath,
|
|
131
159
|
};
|