Skip to content
2 changes: 1 addition & 1 deletion components/action1/action1.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/buddy/buddy.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
15 changes: 13 additions & 2 deletions components/google_drive/actions/upload-file/upload-file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from "path";
import {
getFileStream,
omitEmptyStringValues,
parseObjectEntries,
} from "../../common/utils.mjs";
import { GOOGLE_DRIVE_UPLOAD_TYPE_MULTIPART } from "../../common/constants.mjs";
import {
Expand All @@ -13,7 +14,7 @@ export default {
key: "google_drive-upload-file",
name: "Upload File",
description: "Upload a file to Google Drive. [See the documentation](https://developers.google.com/drive/api/v3/manage-uploads) for more information",
version: "1.0.3",
version: "1.1.0",
type: "action",
additionalProps,
props: {
Expand Down Expand Up @@ -84,7 +85,13 @@ export default {
"fileId",
],
label: "File to replace",
description: "Id of the file to replace. Leave it empty to upload a new file.",
description: "ID of the file to replace. Leave it empty to upload a new file.",
optional: true,
},
metadata: {
type: "object",
label: "Metadata",
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\" }`",
optional: true,
},
},
Expand All @@ -110,6 +117,8 @@ export default {
});
console.log(`Upload type: ${uploadType}.`);

const metadata = parseObjectEntries(this.metadata);

let result = null;
if (this.fileId) {
await this.googleDrive.updateFileMedia(this.fileId, file, omitEmptyStringValues({
Expand All @@ -120,6 +129,7 @@ export default {
name: filename,
mimeType,
uploadType,
requestBody: metadata,
}));
$.export("$summary", `Successfully updated file, "${result.name}"`);
} else {
Expand All @@ -130,6 +140,7 @@ export default {
parentId,
driveId,
uploadType,
requestBody: metadata,
}));
$.export("$summary", `Successfully uploaded a new file, "${result.name}"`);
}
Expand Down
35 changes: 34 additions & 1 deletion components/google_drive/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import fs from "fs";
import { axios } from "@pipedream/platform";
import {
axios, ConfigurationError,
} from "@pipedream/platform";
import {
MY_DRIVE_VALUE,
LEGACY_MY_DRIVE_VALUE,
Expand Down Expand Up @@ -257,6 +259,36 @@ function toSingleLineString(multiLineString) {
.replace(/\s{2,}/g, " ");
}

function optionalParseAsJSON(value) {
try {
return JSON.parse(value);
} catch (e) {
return value;
}
}

function parseObjectEntries(value = {}) {
let obj;
if (typeof value === "string") {
try {
obj = JSON.parse(value);
} catch (e) {
throw new ConfigurationError(`Invalid JSON string provided: ${e.message}`);
}
} else {
obj = value;
}
return Object.fromEntries(
Object.entries(obj).map(([
key,
value,
]) => [
key,
optionalParseAsJSON(value),
]),
);
}

export {
MY_DRIVE_VALUE,
isMyDrive,
Expand All @@ -269,4 +301,5 @@ export {
getFilePaths,
streamToBuffer,
byteToMB,
parseObjectEntries,
};
2 changes: 1 addition & 1 deletion components/google_drive/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/google_drive",
"version": "0.9.2",
"version": "0.10.0",
"description": "Pipedream Google_drive Components",
"main": "google_drive.app.mjs",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion components/guardrails/guardrails.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/local_reviews/local_reviews.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
6 changes: 4 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading