Skip to content

Commit 4218008

Browse files
committed
Incrementing 'upload file' action with new metadata prop
1 parent 60f9c80 commit 4218008

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from "path";
33
import {
44
getFileStream,
55
omitEmptyStringValues,
6+
parseObjectEntries,
67
} from "../../common/utils.mjs";
78
import { GOOGLE_DRIVE_UPLOAD_TYPE_MULTIPART } from "../../common/constants.mjs";
89
import {
@@ -13,7 +14,7 @@ export default {
1314
key: "google_drive-upload-file",
1415
name: "Upload File",
1516
description: "Upload a file to Google Drive. [See the documentation](https://developers.google.com/drive/api/v3/manage-uploads) for more information",
16-
version: "1.0.2",
17+
version: "1.1.0",
1718
type: "action",
1819
additionalProps,
1920
props: {
@@ -84,7 +85,13 @@ export default {
8485
"fileId",
8586
],
8687
label: "File to replace",
87-
description: "Id of the file to replace. Leave it empty to upload a new file.",
88+
description: "ID of the file to replace. Leave it empty to upload a new file.",
89+
optional: true,
90+
},
91+
metadata: {
92+
type: "object",
93+
label: "Metadata",
94+
description: "Additional metadata to supply in the upload. [See the documentation](https://developers.google.com/workspace/drive/api/reference/rest/v3/files) for information on availabl efields. Values will be parsed as JSON where applicable. Example: `{ \"description\": \"my file description\" }`",
8895
optional: true,
8996
},
9097
},
@@ -110,6 +117,8 @@ export default {
110117
});
111118
console.log(`Upload type: ${uploadType}.`);
112119

120+
const metadata = parseObjectEntries(this.metadata);
121+
113122
let result = null;
114123
if (this.fileId) {
115124
await this.googleDrive.updateFileMedia(this.fileId, file, omitEmptyStringValues({
@@ -120,6 +129,7 @@ export default {
120129
name: filename,
121130
mimeType,
122131
uploadType,
132+
requestBody: metadata,
123133
}));
124134
$.export("$summary", `Successfully updated file, "${result.name}"`);
125135
} else {
@@ -130,6 +140,7 @@ export default {
130140
parentId,
131141
driveId,
132142
uploadType,
143+
requestBody: metadata,
133144
}));
134145
$.export("$summary", `Successfully uploaded a new file, "${result.name}"`);
135146
}

components/google_drive/common/utils.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,29 @@ function toSingleLineString(multiLineString) {
257257
.replace(/\s{2,}/g, " ");
258258
}
259259

260+
function optionalParseAsJSON(value) {
261+
try {
262+
return JSON.parse(value);
263+
} catch (e) {
264+
return value;
265+
}
266+
}
267+
268+
function parseObjectEntries(value = {}) {
269+
const obj = typeof value === "string"
270+
? JSON.parse(value)
271+
: value;
272+
return Object.fromEntries(
273+
Object.entries(obj).map(([
274+
key,
275+
value,
276+
]) => [
277+
key,
278+
optionalParseAsJSON(value),
279+
]),
280+
);
281+
}
282+
260283
export {
261284
MY_DRIVE_VALUE,
262285
isMyDrive,
@@ -269,4 +292,5 @@ export {
269292
getFilePaths,
270293
streamToBuffer,
271294
byteToMB,
295+
parseObjectEntries,
272296
};

components/google_drive/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/google_drive",
3-
"version": "0.9.1",
3+
"version": "0.9.2",
44
"description": "Pipedream Google_drive Components",
55
"main": "google_drive.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)