@pipedream/google_drive 0.6.9 → 0.6.11

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.
package/README.md CHANGED
@@ -11,6 +11,8 @@ Using the Google Drive API, you can build applications that:
11
11
 
12
12
  ## Troubleshooting
13
13
 
14
- [Google Advanced Protection Program](https://support.google.com/accounts/answer/7539956?hl=en) must be disabled in order to use the Google Drive app on Pipedream.
14
+ **Error: "Google cannot give this app access to your account data because Advanced Protection is turned on for your Google Account"**
15
15
 
16
- If you encounter the error "Google cannot give this app access to your account data because Advanced Protection is turned on for your Google Account", you will need to disable this setting as it blocks third-party apps from accessing Google Drive.
16
+ If you are using a free Google account, [Google Advanced Protection Program](https://support.google.com/accounts/answer/7539956?hl=en) must be disabled in order to use the Google Drive app on Pipedream.
17
+
18
+ For Google Workspace users, your Google Workspace Administrator can manually allow the Pipedream Google Drive app; please follow the instructions [here](https://support.google.com/a/answer/7281227#zippy=%2Cadd-a-new-app).
@@ -1,13 +1,13 @@
1
1
  import googleDrive from "../../google_drive.app.mjs";
2
2
  import fs from "fs";
3
- import got from "got@12.4.1";
3
+ import got from "got@13.0.0";
4
4
  import { toSingleLineString } from "../../common/utils.mjs";
5
5
 
6
6
  export default {
7
7
  key: "google_drive-create-file",
8
8
  name: "Create a New File",
9
9
  description: "Create a new file from a URL or /tmp/filepath. [See the docs](https://developers.google.com/drive/api/v3/reference/files/create) for more information",
10
- version: "0.1.2",
10
+ version: "0.1.3",
11
11
  type: "action",
12
12
  props: {
13
13
  googleDrive,
@@ -10,7 +10,7 @@ export default {
10
10
  key: "google_drive-upload-file",
11
11
  name: "Upload File",
12
12
  description: "Copy an existing file to Google Drive. [See the docs](https://developers.google.com/drive/api/v3/manage-uploads) for more information",
13
- version: "0.1.1",
13
+ version: "0.1.2",
14
14
  type: "action",
15
15
  props: {
16
16
  googleDrive,
@@ -69,6 +69,27 @@ export default {
69
69
  default: GOOGLE_DRIVE_UPLOAD_TYPE_MULTIPART,
70
70
  optional: true,
71
71
  },
72
+ replaceFile: {
73
+ type: "boolean",
74
+ label: "Replace File",
75
+ description: "Whether should replace file case it exists, default: `false`",
76
+ optional: true,
77
+ default: false,
78
+ },
79
+ },
80
+ methods: {
81
+ async getFileIdForReplace(filename, parentId) {
82
+ if (this.replaceFile) {
83
+ const { files } = await this.googleDrive.listFilesInPage(null, {
84
+ q: `name = '${filename}' and '${parentId || "root"}' in parents and trashed = false`,
85
+ fields: "files/id,files/name,files/parents",
86
+ });
87
+ if (files.length) {
88
+ return files[0].id;
89
+ }
90
+ }
91
+ return null;
92
+ },
72
93
  },
73
94
  async run({ $ }) {
74
95
  const {
@@ -83,21 +104,40 @@ export default {
83
104
  throw new Error("One of File URL and File Path is required.");
84
105
  }
85
106
  const driveId = this.googleDrive.getDriveId(this.drive);
107
+
108
+ const filename = name || path.basename(fileUrl || filePath);
109
+ const fileId = await this.getFileIdForReplace(filename, parentId);
110
+
86
111
  const file = await getFileStream({
87
112
  $,
88
113
  fileUrl,
89
114
  filePath,
90
115
  });
91
116
  console.log(`Upload type: ${uploadType}.`);
92
- const resp = await this.googleDrive.createFile(omitEmptyStringValues({
93
- file,
94
- mimeType,
95
- name: name || path.basename(fileUrl || filePath),
96
- parentId,
97
- driveId,
98
- uploadType,
99
- }));
100
- $.export("$summary", `Successfully uploaded a new file, "${resp.name}"`);
101
- return resp;
117
+
118
+ let result = null;
119
+ if (fileId) {
120
+ await this.googleDrive.updateFileMedia(fileId, file, omitEmptyStringValues({
121
+ mimeType,
122
+ uploadType,
123
+ }));
124
+ result = await this.googleDrive.updateFile(fileId, omitEmptyStringValues({
125
+ name: filename,
126
+ mimeType,
127
+ uploadType,
128
+ }));
129
+ $.export("$summary", `Successfully updated file, "${result.name}"`);
130
+ } else {
131
+ result = await this.googleDrive.createFile(omitEmptyStringValues({
132
+ file,
133
+ mimeType,
134
+ name: filename,
135
+ parentId,
136
+ driveId,
137
+ uploadType,
138
+ }));
139
+ $.export("$summary", `Successfully uploaded a new file, "${result.name}"`);
140
+ }
141
+ return result;
102
142
  },
103
143
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/google_drive",
3
- "version": "0.6.9",
3
+ "version": "0.6.11",
4
4
  "description": "Pipedream Google_drive Components",
5
5
  "main": "google_drive.app.mjs",
6
6
  "keywords": [