@pipedream/google_drive 0.6.10 → 0.6.12

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
@@ -9,7 +9,7 @@ Using the Google Drive API, you can build applications that:
9
9
  - Track changes to files
10
10
  - And much more!
11
11
 
12
- ## Troubleshooting
12
+ # Troubleshooting
13
13
 
14
14
  **Error: "Google cannot give this app access to your account data because Advanced Protection is turned on for your Google Account"**
15
15
 
@@ -10,8 +10,8 @@ export default {
10
10
  key: "google_drive-add-file-sharing-preference",
11
11
  name: "Add File Sharing Preference",
12
12
  description:
13
- "Add a [sharing](https://support.google.com/drive/answer/7166529) permission to the sharing preferences of a file and provide a sharing URL. [See the docs](https://developers.google.com/drive/api/v3/reference/permissions/create) for more information",
14
- version: "0.1.1",
13
+ "Add a [sharing](https://support.google.com/drive/answer/7166529) permission to the sharing preferences of a file or folder and provide a sharing URL. [See the docs](https://developers.google.com/drive/api/v3/reference/permissions/create) for more information",
14
+ version: "0.1.2",
15
15
  type: "action",
16
16
  props: {
17
17
  googleDrive,
@@ -22,16 +22,16 @@ export default {
22
22
  ],
23
23
  optional: true,
24
24
  },
25
- fileId: {
25
+ fileOrFolderId: {
26
26
  propDefinition: [
27
27
  googleDrive,
28
- "fileId",
28
+ "fileOrFolderId",
29
29
  (c) => ({
30
30
  drive: c.drive,
31
31
  }),
32
32
  ],
33
33
  optional: false,
34
- description: "The file to share",
34
+ description: "The file or folder to share",
35
35
  },
36
36
  role: {
37
37
  propDefinition: [
@@ -60,14 +60,14 @@ export default {
60
60
  },
61
61
  async run({ $ }) {
62
62
  const {
63
- fileId,
63
+ fileOrFolderId,
64
64
  role,
65
65
  type,
66
66
  domain,
67
67
  emailAddress,
68
68
  } = this;
69
69
  // Create the permission for the file
70
- await this.googleDrive.createPermission(fileId, {
70
+ await this.googleDrive.createPermission(fileOrFolderId, {
71
71
  role,
72
72
  type,
73
73
  domain,
@@ -75,7 +75,7 @@ export default {
75
75
  });
76
76
 
77
77
  // Get the file to get the `webViewLink` sharing URL
78
- const resp = await this.googleDrive.getFile(this.fileId);
78
+ const resp = await this.googleDrive.getFile(this.fileOrFolderId);
79
79
  const webViewLink = resp.webViewLink;
80
80
  $.export("$summary", `Successfully added a sharing permission to the file, "${resp.name}"`);
81
81
  return webViewLink;
@@ -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.10",
3
+ "version": "0.6.12",
4
4
  "description": "Pipedream Google_drive Components",
5
5
  "main": "google_drive.app.mjs",
6
6
  "keywords": [