Skip to content

Commit 79d4c64

Browse files
authored
Google drive: adding selection between file URL or path (#15457)
* Fixing typos in Google Drive * pnpm * Adding selection between file URL or path * Adjusting props to required * pnpm * Adjustments to allow updating file metadata only * Fixing file path / file URL duality * pnpm
1 parent e0910d2 commit 79d4c64

File tree

5 files changed

+87
-34
lines changed

5 files changed

+87
-34
lines changed

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

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,36 @@ import {
33
toSingleLineString,
44
getFileStream,
55
} from "../../common/utils.mjs";
6+
import { additionalProps } from "../../common/filePathOrUrl.mjs";
67

78
export default {
89
key: "google_drive-update-file",
910
name: "Update File",
1011
description: "Update a file's metadata and/or content. [See the documentation](https://developers.google.com/drive/api/v3/reference/files/update) for more information",
11-
version: "0.1.7",
12+
version: "1.0.0",
1213
type: "action",
14+
additionalProps,
1315
props: {
1416
googleDrive,
15-
requiredPropsAlert: {
16-
type: "alert",
17-
alertType: "info",
18-
content: "Either `File URL` and `File Path` should be specified.",
17+
updateType: {
18+
type: "string",
19+
label: "Update Type",
20+
description: "Whether to update content or metadata only",
21+
options: [
22+
{
23+
label: "Upload content from File URL",
24+
value: "File URL",
25+
},
26+
{
27+
label: "Upload content from File Path",
28+
value: "File Path",
29+
},
30+
{
31+
label: "Update file metadata only",
32+
value: "File Metadata",
33+
},
34+
],
35+
reloadProps: true,
1936
},
2037
drive: {
2138
propDefinition: [
@@ -40,6 +57,8 @@ export default {
4057
"fileUrl",
4158
],
4259
description: "The URL of the file to use to update content",
60+
optional: false,
61+
hidden: true,
4362
},
4463
filePath: {
4564
propDefinition: [
@@ -51,6 +70,8 @@ export default {
5170
directory](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory)
5271
(e.g., \`/tmp/myFile.csv\`) with which to update content
5372
`),
73+
optional: false,
74+
hidden: true,
5475
},
5576
name: {
5677
propDefinition: [
@@ -128,16 +149,21 @@ export default {
128149
ocrLanguage,
129150
useContentAsIndexableText,
130151
advanced,
152+
updateType,
131153
} = this;
132154

133-
const fileStream =
134-
fileUrl || filePath
135-
? await getFileStream({
136-
$,
137-
fileUrl,
138-
filePath,
139-
})
140-
: undefined;
155+
let fileStream;
156+
if (updateType === "File URL") {
157+
fileStream = await getFileStream({
158+
$,
159+
fileUrl,
160+
});
161+
} else if (updateType === "File Path") {
162+
fileStream = await getFileStream({
163+
$,
164+
filePath,
165+
});
166+
}
141167

142168
// Update file content, if set, separately from metadata to prevent
143169
// multipart upload, which `google-apis-nodejs-client` doesn't seem to

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ import {
55
omitEmptyStringValues,
66
} from "../../common/utils.mjs";
77
import { GOOGLE_DRIVE_UPLOAD_TYPE_MULTIPART } from "../../common/constants.mjs";
8-
import { ConfigurationError } from "@pipedream/platform";
8+
import {
9+
additionalProps, updateType,
10+
} from "../../common/filePathOrUrl.mjs";
911

1012
export default {
1113
key: "google_drive-upload-file",
1214
name: "Upload File",
1315
description: "Upload a file to Google Drive. [See the documentation](https://developers.google.com/drive/api/v3/manage-uploads) for more information",
14-
version: "0.1.10",
16+
version: "1.0.0",
1517
type: "action",
18+
additionalProps,
1619
props: {
1720
googleDrive,
18-
infoAlert: {
19-
type: "alert",
20-
alertType: "info",
21-
content: "Either `File URL` and `File Path` should be specified.",
22-
},
21+
updateType,
2322
drive: {
2423
propDefinition: [
2524
googleDrive,
@@ -44,12 +43,16 @@ export default {
4443
googleDrive,
4544
"fileUrl",
4645
],
46+
optional: false,
47+
hidden: true,
4748
},
4849
filePath: {
4950
propDefinition: [
5051
googleDrive,
5152
"filePath",
5253
],
54+
optional: false,
55+
hidden: true,
5356
},
5457
name: {
5558
propDefinition: [
@@ -94,9 +97,6 @@ export default {
9497
mimeType,
9598
} = this;
9699
let { uploadType } = this;
97-
if (!fileUrl && !filePath) {
98-
throw new ConfigurationError("Either `File URL` and `File Path` should be specified.");
99-
}
100100
const driveId = this.googleDrive.getDriveId(this.drive);
101101

102102
const filename = name || path.basename(fileUrl || filePath);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export const updateType = {
2+
type: "string",
3+
label: "Use File URL or File Path",
4+
description: "Whether to upload a file from a URL or from the `/tmp` folder",
5+
options: [
6+
"File URL",
7+
"File Path",
8+
],
9+
reloadProps: true,
10+
};
11+
12+
export async function additionalProps(previousProps) {
13+
const { updateType } = this;
14+
15+
if (updateType === "File URL") {
16+
previousProps.fileUrl.hidden = false;
17+
previousProps.filePath.hidden = true;
18+
} else if (updateType === "File Path") {
19+
previousProps.fileUrl.hidden = true;
20+
previousProps.filePath.hidden = false;
21+
} else {
22+
previousProps.fileUrl.hidden = true;
23+
previousProps.filePath.hidden = true;
24+
}
25+
26+
return {};
27+
}

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.8.9",
3+
"version": "0.8.10",
44
"description": "Pipedream Google_drive Components",
55
"main": "google_drive.app.mjs",
66
"keywords": [

pnpm-lock.yaml

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)