@pipedream/google_drive 0.7.2 → 0.8.0

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.
Files changed (38) hide show
  1. package/actions/add-file-sharing-preference/add-file-sharing-preference.mjs +30 -8
  2. package/actions/copy-file/copy-file.mjs +2 -2
  3. package/actions/create-file-from-template/create-file-from-template.mjs +3 -3
  4. package/actions/create-file-from-text/create-file-from-text.mjs +3 -2
  5. package/actions/create-folder/create-folder.mjs +3 -2
  6. package/actions/create-shared-drive/create-shared-drive.mjs +1 -2
  7. package/actions/delete-file/delete-file.mjs +10 -3
  8. package/actions/delete-shared-drive/delete-shared-drive.mjs +7 -5
  9. package/actions/download-file/download-file.mjs +11 -6
  10. package/actions/find-file/find-file.mjs +8 -10
  11. package/actions/find-folder/find-folder.mjs +2 -2
  12. package/actions/find-forms/find-forms.mjs +22 -18
  13. package/actions/find-spreadsheets/find-spreadsheets.mjs +21 -18
  14. package/actions/get-file-by-id/common-file-fields.mjs +293 -0
  15. package/actions/get-file-by-id/get-file-by-id.mjs +56 -0
  16. package/actions/get-folder-id-for-path/get-folder-id-for-path.mjs +1 -1
  17. package/actions/get-shared-drive/get-shared-drive.mjs +8 -8
  18. package/actions/list-files/list-files.mjs +3 -3
  19. package/actions/move-file/move-file.mjs +2 -2
  20. package/actions/move-file-to-trash/move-file-to-trash.mjs +7 -2
  21. package/actions/search-shared-drives/search-shared-drives.mjs +1 -1
  22. package/actions/update-file/update-file.mjs +9 -7
  23. package/actions/update-shared-drive/update-shared-drive.mjs +11 -11
  24. package/actions/upload-file/upload-file.mjs +12 -4
  25. package/common/commonSearchQuery.mjs +48 -0
  26. package/common/constants.mjs +27 -22
  27. package/google_drive.app.mjs +41 -16
  28. package/package.json +1 -1
  29. package/sources/changes-to-specific-files/changes-to-specific-files.mjs +2 -3
  30. package/sources/changes-to-specific-files-shared-drive/changes-to-specific-files-shared-drive.mjs +1 -1
  31. package/sources/new-files-instant/new-files-instant.mjs +1 -1
  32. package/sources/new-or-modified-comments/new-or-modified-comments.mjs +1 -1
  33. package/sources/new-or-modified-files/new-or-modified-files.mjs +1 -1
  34. package/sources/new-or-modified-folders/new-or-modified-folders.mjs +1 -1
  35. package/sources/new-shared-drive/new-shared-drive.mjs +1 -1
  36. package/sources/new-spreadsheet/new-spreadsheet.mjs +1 -1
  37. package/actions/create-file/create-file.mjs +0 -242
  38. package/actions/replace-file/replace-file.mjs +0 -134
@@ -163,14 +163,6 @@ const GOOGLE_DRIVE_ROLE_READER = "reader";
163
163
  * All of the available Google Drive roles granted by a permission as defined by the [Google
164
164
  * Drive API docs](https://developers.google.com/drive/api/v3/reference/permissions)
165
165
  */
166
- const GOOGLE_DRIVE_ROLES = [
167
- GOOGLE_DRIVE_ROLE_OWNER,
168
- GOOGLE_DRIVE_ROLE_ORGANIZER,
169
- GOOGLE_DRIVE_ROLE_FILEORGANIZER,
170
- GOOGLE_DRIVE_ROLE_WRITER,
171
- GOOGLE_DRIVE_ROLE_COMMENTER,
172
- GOOGLE_DRIVE_ROLE_READER,
173
- ];
174
166
 
175
167
  const GOOGLE_DRIVE_ROLE_OPTIONS = [
176
168
  {
@@ -182,23 +174,20 @@ const GOOGLE_DRIVE_ROLE_OPTIONS = [
182
174
  value: GOOGLE_DRIVE_ROLE_COMMENTER,
183
175
  },
184
176
  {
185
- label: "Reader - Can access, but can't change or share the file with others.",
177
+ label: "Viewer - Can access, but can't change or share the file with others.",
186
178
  value: GOOGLE_DRIVE_ROLE_READER,
187
179
  },
188
- {
189
- label: "(Advanced) File Owner - this will transfer ownership of the file.",
190
- value: GOOGLE_DRIVE_ROLE_OWNER,
191
- },
192
- {
193
- label: "(Advanced) File Organizar",
194
- value: GOOGLE_DRIVE_ROLE_FILEORGANIZER,
195
- },
196
- {
197
- label: "(Advanced) Organizar",
198
- value: GOOGLE_DRIVE_ROLE_ORGANIZER,
199
- },
200
180
  ];
201
181
 
182
+ const GOOGLE_DRIVE_ROLE_OPTION_FILEORGANIZER = {
183
+ label: "(Advanced) Content Manager - add, edit, move, delete and share content",
184
+ value: GOOGLE_DRIVE_ROLE_FILEORGANIZER,
185
+ };
186
+ const GOOGLE_DRIVE_ROLE_OPTION_OWNER = {
187
+ label: "(Advanced) File Owner - this will transfer ownership of the file.",
188
+ value: GOOGLE_DRIVE_ROLE_OWNER,
189
+ };
190
+
202
191
  const GOOGLE_DRIVE_GRANTEE_USER = "user";
203
192
  const GOOGLE_DRIVE_GRANTEE_GROUP = "group";
204
193
  const GOOGLE_DRIVE_GRANTEE_DOMAIN = "domain";
@@ -222,6 +211,20 @@ const GOOGLE_DRIVE_UPLOAD_TYPES = [
222
211
  GOOGLE_DRIVE_UPLOAD_TYPE_RESUMABLE,
223
212
  GOOGLE_DRIVE_UPLOAD_TYPE_MULTIPART,
224
213
  ];
214
+ const GOOGLE_DRIVE_UPLOAD_TYPE_OPTIONS = [
215
+ {
216
+ label: "Simple upload. Upload the media only, without any metadata.",
217
+ value: GOOGLE_DRIVE_UPLOAD_TYPE_MEDIA,
218
+ },
219
+ {
220
+ label: "Resumable upload. Upload the file in a resumable fashion, using a series of at least two requests where the first request includes the metadata.",
221
+ value: GOOGLE_DRIVE_UPLOAD_TYPE_RESUMABLE,
222
+ },
223
+ {
224
+ label: "Multipart upload. Upload both the media and its metadata, in a single request.",
225
+ value: GOOGLE_DRIVE_UPLOAD_TYPE_MULTIPART,
226
+ },
227
+ ];
225
228
 
226
229
  export {
227
230
  GOOGLE_DRIVE_NOTIFICATION_SYNC,
@@ -241,6 +244,7 @@ export {
241
244
  GOOGLE_DRIVE_MIME_TYPE_PREFIX,
242
245
  GOOGLE_DRIVE_FOLDER_MIME_TYPE,
243
246
  GOOGLE_DRIVE_UPLOAD_TYPES,
247
+ GOOGLE_DRIVE_UPLOAD_TYPE_OPTIONS,
244
248
  // Google Drive Roles
245
249
  GOOGLE_DRIVE_ROLE_OWNER,
246
250
  GOOGLE_DRIVE_ROLE_ORGANIZER,
@@ -248,8 +252,9 @@ export {
248
252
  GOOGLE_DRIVE_ROLE_WRITER,
249
253
  GOOGLE_DRIVE_ROLE_COMMENTER,
250
254
  GOOGLE_DRIVE_ROLE_READER,
251
- GOOGLE_DRIVE_ROLES,
252
255
  GOOGLE_DRIVE_ROLE_OPTIONS,
256
+ GOOGLE_DRIVE_ROLE_OPTION_FILEORGANIZER,
257
+ GOOGLE_DRIVE_ROLE_OPTION_OWNER,
253
258
  // Google Drive Grantee Types
254
259
  GOOGLE_DRIVE_GRANTEE_USER,
255
260
  GOOGLE_DRIVE_GRANTEE_GROUP,
@@ -11,7 +11,7 @@ import {
11
11
  WEBHOOK_SUBSCRIPTION_EXPIRATION_TIME_MILLISECONDS,
12
12
  GOOGLE_DRIVE_FOLDER_MIME_TYPE,
13
13
  GOOGLE_DRIVE_GRANTEE_TYPES,
14
- GOOGLE_DRIVE_UPLOAD_TYPES,
14
+ GOOGLE_DRIVE_UPLOAD_TYPE_OPTIONS,
15
15
  GOOGLE_DRIVE_UPDATE_TYPE_OPTIONS,
16
16
  } from "./common/constants.mjs";
17
17
  import googleMimeTypes from "./actions/google-mime-types.mjs";
@@ -40,6 +40,31 @@ export default {
40
40
  return this._listDriveOptions(nextPageToken);
41
41
  },
42
42
  },
43
+ sharedDrive: {
44
+ type: "string",
45
+ label: "Shared Drive",
46
+ description: "Select a [Shared Drive](https://support.google.com/a/users/answer/9310351) or leave blank to retrieve all available shared drives.",
47
+ optional: true,
48
+ async options({ prevContext }) {
49
+ const { nextPageToken } = prevContext;
50
+ return this._listDriveOptions(nextPageToken, false);
51
+ },
52
+ },
53
+ themeId: {
54
+ type: "string",
55
+ label: "Theme ID",
56
+ description: "The theme from which the background image and color will be set. Cannot be set if `Color` or `Background Image Link` are used.",
57
+ optional: true,
58
+ async options() {
59
+ const { driveThemes } = await this.getAbout("driveThemes");
60
+ return driveThemes?.map(({
61
+ id, colorRgb,
62
+ }) => ({
63
+ label: `${id} (${colorRgb})`,
64
+ value: id,
65
+ }));
66
+ },
67
+ },
43
68
  folderId: {
44
69
  type: "string",
45
70
  label: "Folder",
@@ -155,7 +180,13 @@ export default {
155
180
  fileNameSearchTerm: {
156
181
  type: "string",
157
182
  label: "Search Name",
158
- description: "Enter the name of a file to search for.",
183
+ description: "Search for a file by name (equivalent to the query `name contains [value]`).",
184
+ optional: true,
185
+ },
186
+ searchQuery: {
187
+ type: "string",
188
+ label: "Search Query",
189
+ description: "Search for a file with a query. [See the documentation](https://developers.google.com/drive/api/guides/ref-search-terms) for more information. If specified, `Search Name` will be ignored.",
159
190
  optional: true,
160
191
  },
161
192
  mimeType: {
@@ -179,14 +210,8 @@ export default {
179
210
  uploadType: {
180
211
  type: "string",
181
212
  label: "Upload Type",
182
- description: `The type of upload request to the /upload URI. If you are uploading data
183
- (using an /upload URI), this field is required. If you are creating a metadata-only file,
184
- this field is not required.
185
- media - Simple upload. Upload the media only, without any metadata.
186
- multipart - Multipart upload. Upload both the media and its metadata, in a single request.
187
- resumable - Resumable upload. Upload the file in a resumable fashion, using a series of
188
- at least two requests where the first request includes the metadata.`,
189
- options: GOOGLE_DRIVE_UPLOAD_TYPES,
213
+ description: "The type of upload request to the /upload URI. Required if you are uploading data, but not if are creating a metadata-only file. [See the documentation](https://developers.google.com/drive/api/reference/rest/v2/files/update#path-parameters) for more information.",
214
+ options: GOOGLE_DRIVE_UPLOAD_TYPE_OPTIONS,
190
215
  },
191
216
  useDomainAdminAccess: {
192
217
  type: "boolean",
@@ -429,7 +454,7 @@ export default {
429
454
  pageToken = nextPageToken;
430
455
  }
431
456
  },
432
- async _listDriveOptions(pageToken) {
457
+ async _listDriveOptions(pageToken, myDrive = true) {
433
458
  const {
434
459
  drives,
435
460
  nextPageToken,
@@ -440,14 +465,14 @@ export default {
440
465
  // only do this during the first page of options (i.e. when `pageToken` is
441
466
  // undefined).
442
467
  const options =
443
- pageToken !== undefined
444
- ? []
445
- : [
468
+ myDrive && pageToken === undefined
469
+ ? [
446
470
  {
447
471
  label: "My Drive",
448
472
  value: MY_DRIVE_VALUE,
449
473
  },
450
- ];
474
+ ]
475
+ : [];
451
476
  for (const d of drives) {
452
477
  options.push({
453
478
  label: d.name,
@@ -1239,7 +1264,7 @@ export default {
1239
1264
  */
1240
1265
  async createPermission(fileId, opts = {}) {
1241
1266
  const {
1242
- role = "reader",
1267
+ role,
1243
1268
  type,
1244
1269
  domain,
1245
1270
  emailAddress,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/google_drive",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "Pipedream Google_drive Components",
5
5
  "main": "google_drive.app.mjs",
6
6
  "keywords": [
@@ -2,9 +2,8 @@ import cronParser from "cron-parser";
2
2
  import sampleEmit from "./test-event.mjs";
3
3
  import includes from "lodash/includes.js";
4
4
  import { v4 as uuid } from "uuid";
5
-
6
- import changesToSpecificFiles from "../changes-to-specific-files-shared-drive/changes-to-specific-files-shared-drive.mjs";
7
5
  import { MY_DRIVE_VALUE } from "../../common/constants.mjs";
6
+ import changesToSpecificFiles from "../changes-to-specific-files-shared-drive/changes-to-specific-files-shared-drive.mjs";
8
7
 
9
8
  /**
10
9
  * This source uses the Google Drive API's
@@ -16,7 +15,7 @@ export default {
16
15
  key: "google_drive-changes-to-specific-files",
17
16
  name: "Changes to Specific Files",
18
17
  description: "Watches for changes to specific files, emitting an event when a change is made to one of those files. To watch for changes to [shared drive](https://support.google.com/a/users/answer/9310351) files, use the **Changes to Specific Files (Shared Drive)** source instead.",
19
- version: "0.2.0",
18
+ version: "0.2.1",
20
19
  type: "source",
21
20
  // Dedupe events based on the "x-goog-message-number" header for the target channel:
22
21
  // https://developers.google.com/drive/api/v3/push#making-watch-requests
@@ -27,7 +27,7 @@ export default {
27
27
  key: "google_drive-changes-to-specific-files-shared-drive",
28
28
  name: "Changes to Specific Files (Shared Drive)",
29
29
  description: "Watches for changes to specific files in a shared drive, emitting an event when a change is made to one of those files",
30
- version: "0.2.0",
30
+ version: "0.2.1",
31
31
  type: "source",
32
32
  // Dedupe events based on the "x-goog-message-number" header for the target channel:
33
33
  // https://developers.google.com/drive/api/v3/push#making-watch-requests
@@ -10,7 +10,7 @@ export default {
10
10
  key: "google_drive-new-files-instant",
11
11
  name: "New Files (Instant)",
12
12
  description: "Emit new event when a new file is added in your linked Google Drive",
13
- version: "0.1.7",
13
+ version: "0.1.8",
14
14
  type: "source",
15
15
  dedupe: "unique",
16
16
  props: {
@@ -17,7 +17,7 @@ export default {
17
17
  name: "New or Modified Comments (Instant)",
18
18
  description:
19
19
  "Emit new event when a file comment is created or modified in the selected Drive",
20
- version: "0.1.7",
20
+ version: "0.1.8",
21
21
  type: "source",
22
22
  // Dedupe events based on the "x-goog-message-number" header for the target channel:
23
23
  // https://developers.google.com/drive/api/v3/push#making-watch-requests
@@ -24,7 +24,7 @@ export default {
24
24
  key: "google_drive-new-or-modified-files",
25
25
  name: "New or Modified Files (Instant)",
26
26
  description: "Emit new event when a file in the selected Drive is created, modified or trashed.",
27
- version: "0.3.0",
27
+ version: "0.3.1",
28
28
  type: "source",
29
29
  // Dedupe events based on the "x-goog-message-number" header for the target channel:
30
30
  // https://developers.google.com/drive/api/v3/push#making-watch-requests
@@ -20,7 +20,7 @@ export default {
20
20
  key: "google_drive-new-or-modified-folders",
21
21
  name: "New or Modified Folders (Instant)",
22
22
  description: "Emit new event when a folder is created or modified in the selected Drive",
23
- version: "0.1.5",
23
+ version: "0.1.6",
24
24
  type: "source",
25
25
  // Dedupe events based on the "x-goog-message-number" header for the target channel:
26
26
  // https://developers.google.com/drive/api/v3/push#making-watch-requests
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_drive-new-shared-drive",
6
6
  name: "New Shared Drive",
7
7
  description: "Emits a new event any time a shared drive is created.",
8
- version: "0.1.4",
8
+ version: "0.1.5",
9
9
  type: "source",
10
10
  dedupe: "unique",
11
11
  props: {
@@ -6,7 +6,7 @@ export default {
6
6
  type: "source",
7
7
  name: "New Spreadsheet (Instant)",
8
8
  description: "Emit new event when a new spreadsheet is created in a drive.",
9
- version: "0.1.5",
9
+ version: "0.1.6",
10
10
  props: {
11
11
  googleDrive: newFilesInstant.props.googleDrive,
12
12
  db: newFilesInstant.props.db,
@@ -1,242 +0,0 @@
1
- import googleDrive from "../../google_drive.app.mjs";
2
- import fs from "fs";
3
- import got from "got@13.0.0";
4
- import { toSingleLineString } from "../../common/utils.mjs";
5
-
6
- export default {
7
- key: "google_drive-create-file",
8
- name: "Create a New File",
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.6",
11
- type: "action",
12
- props: {
13
- googleDrive,
14
- drive: {
15
- propDefinition: [
16
- googleDrive,
17
- "watchedDrive",
18
- ],
19
- },
20
- parent: {
21
- propDefinition: [
22
- googleDrive,
23
- "folderId",
24
- (c) => ({
25
- drive: c.drive,
26
- }),
27
- ],
28
- label: "Parent Folder",
29
- description: toSingleLineString(`
30
- The ID of the parent folder which contains the file. If not specified, the file will be
31
- placed directly in the drive's top-level folder.
32
- `),
33
- optional: true,
34
- },
35
- uploadType: {
36
- propDefinition: [
37
- googleDrive,
38
- "uploadType",
39
- ],
40
- },
41
- fileUrl: {
42
- propDefinition: [
43
- googleDrive,
44
- "fileUrl",
45
- ],
46
- },
47
- filePath: {
48
- propDefinition: [
49
- googleDrive,
50
- "filePath",
51
- ],
52
- },
53
- ignoreDefaultVisibility: {
54
- type: "boolean",
55
- label: "Ignore Default Visibility",
56
- description: toSingleLineString(`
57
- Whether to ignore the domain's default visibility settings for the created
58
- file. Domain administrators can choose to make all uploaded files visible to the domain
59
- by default; this parameter bypasses that behavior for the request. Permissions are still
60
- inherited from parent folders.
61
- `),
62
- default: false,
63
- },
64
- includePermissionsForView: {
65
- type: "string",
66
- label: "Include Permissions For View",
67
- description: toSingleLineString(`
68
- Specifies which additional view's permissions to include in the response. Only
69
- 'published' is supported.
70
- `),
71
- optional: true,
72
- options: [
73
- "published",
74
- ],
75
- },
76
- keepRevisionForever: {
77
- propDefinition: [
78
- googleDrive,
79
- "keepRevisionForever",
80
- ],
81
- default: false,
82
- },
83
- ocrLanguage: {
84
- propDefinition: [
85
- googleDrive,
86
- "ocrLanguage",
87
- ],
88
- },
89
- useContentAsIndexableText: {
90
- propDefinition: [
91
- googleDrive,
92
- "useContentAsIndexableText",
93
- ],
94
- default: false,
95
- },
96
- supportsAllDrives: {
97
- type: "boolean",
98
- label: "Supports All Drives",
99
- description: toSingleLineString(`
100
- Whether to include shared drives. Set to 'true' if saving to a shared drive.
101
- Defaults to 'false' if left blank.
102
- `),
103
- optional: true,
104
- },
105
- contentHintsIndexableText: {
106
- type: "string",
107
- label: "Content Hints Indexable Text",
108
- description: toSingleLineString(`
109
- Text to be indexed for the file to improve fullText queries. This is limited to 128KB in
110
- length and may contain HTML elements.
111
- `),
112
- optional: true,
113
- },
114
- contentRestrictionsReadOnly: {
115
- type: "boolean",
116
- label: "Content Restrictions Read Only",
117
- description: toSingleLineString(`
118
- Whether the content of the file is read-only. If a file is read-only, a new revision of
119
- the file may not be added, comments may not be added or modified, and the title of the file
120
- may not be modified.
121
- `),
122
- optional: true,
123
- },
124
- contentRestrictionsReason: {
125
- type: "string",
126
- label: "Content Restrictions Reason",
127
- description: toSingleLineString(`
128
- Reason for why the content of the file is restricted. This is only mutable on requests
129
- that also set readOnly=true.
130
- `),
131
- optional: true,
132
- },
133
- copyRequiresWriterPermission: {
134
- type: "boolean",
135
- label: "Copy Requires Writer Permission",
136
- description: toSingleLineString(`
137
- Whether the options to copy, print, or download this file, should be disabled for
138
- readers and commentators
139
- `),
140
- optional: true,
141
- },
142
- description: {
143
- type: "string",
144
- label: "Description",
145
- description: "A short description of the file",
146
- optional: true,
147
- },
148
- folderColorRgb: {
149
- type: "string",
150
- label: "Folder Color RGB",
151
- description: toSingleLineString(`
152
- The color for a folder as an RGB hex string. If an unsupported color is specified,
153
- the closest color in the palette will be used instead.
154
- `),
155
- optional: true,
156
- },
157
- mimeType: {
158
- propDefinition: [
159
- googleDrive,
160
- "mimeType",
161
- ],
162
- },
163
- name: {
164
- propDefinition: [
165
- googleDrive,
166
- "fileName",
167
- ],
168
- description: "Name of the file",
169
- },
170
- originalFilename: {
171
- type: "string",
172
- label: "Original Filename",
173
- description:
174
- "The original filename of the uploaded content if available, or else the original value of the name field. This is only available for files with binary content in Google Drive.",
175
- optional: true,
176
- },
177
- shortcutDetailsTargetId: {
178
- type: "string",
179
- label: "Shortcut Details Target ID",
180
- description: "The ID of the file that this shortcut points to",
181
- optional: true,
182
- },
183
- starred: {
184
- type: "boolean",
185
- label: "Starred",
186
- description: "Whether the user has starred the file",
187
- optional: true,
188
- },
189
- writersCanShare: {
190
- type: "boolean",
191
- label: "Writers Can Share",
192
- description:
193
- "Whether users with only writer permission can modify the file's permissions. Not populated for items in shared drives.",
194
- optional: true,
195
- },
196
- },
197
- async run({ $ }) {
198
- const body = this.fileUrl
199
- ? await got.stream(this.fileUrl)
200
- : fs.createReadStream(this.filePath);
201
- const driveId = this.googleDrive.getDriveId(this.drive);
202
- const resp = await this.googleDrive.createFile({
203
- ignoreDefaultVisibility: this.ignoreDefaultVisibility,
204
- includePermissionsForView: this.includePermissionsForView,
205
- keepRevisionForever: this.keepRevisionForever,
206
- ocrLanguage: this.ocrLanguage,
207
- useContentAsIndexableText: this.useContentAsIndexableText,
208
- supportsAllDrives: this.supportsAllDrives,
209
- resource: {
210
- name: this.name,
211
- originalFilename: this.originalFilename,
212
- parents: [
213
- this.parent ?? driveId,
214
- ],
215
- mimeType: this.mimeType,
216
- description: this.description,
217
- folderColorRgb: this.folderColorRgb,
218
- shortcutDetails: {
219
- targetId: this.shortcutDetailsTargetId,
220
- },
221
- starred: this.starred,
222
- writersCanShare: this.writersCanShare,
223
- contentHints: {
224
- indexableText: this.contentHintsIndexableText,
225
- },
226
- contentRestrictions: {
227
- readOnly: this.contentRestrictionsReadOnly,
228
- reason: this.contentRestrictionsReason,
229
- },
230
- copyRequiresWriterPermission: this.copyRequiresWriterPermission,
231
- },
232
- media: {
233
- mimeType: this.mimeType,
234
- uploadType: this.uploadType,
235
- body,
236
- },
237
- fields: "*",
238
- });
239
- $.export("$summary", `Successfully created a new file, "${resp.name}"`);
240
- return resp;
241
- },
242
- };
@@ -1,134 +0,0 @@
1
- import path from "path";
2
- import googleDrive from "../../google_drive.app.mjs";
3
- import {
4
- omitEmptyStringValues,
5
- getFileStream,
6
- streamToBuffer,
7
- byteToMB,
8
- } from "../../common/utils.mjs";
9
- import {
10
- GOOGLE_DRIVE_UPLOAD_TYPE_MEDIA,
11
- GOOGLE_DRIVE_UPLOAD_TYPE_RESUMABLE,
12
- } from "../../common/constants.mjs";
13
-
14
- export default {
15
- key: "google_drive-replace-file",
16
- name: "Replace File",
17
- description: "Upload a file that replaces an existing file. [See the docs](https://developers.google.com/drive/api/v3/reference/files/update) for more information",
18
- version: "0.1.4",
19
- type: "action",
20
- props: {
21
- googleDrive,
22
- drive: {
23
- propDefinition: [
24
- googleDrive,
25
- "watchedDrive",
26
- ],
27
- optional: true,
28
- },
29
- fileId: {
30
- propDefinition: [
31
- googleDrive,
32
- "fileId",
33
- (c) => ({
34
- drive: c.drive,
35
- }),
36
- ],
37
- optional: false,
38
- description: "The file to update",
39
- },
40
- fileUrl: {
41
- propDefinition: [
42
- googleDrive,
43
- "fileUrl",
44
- ],
45
- },
46
- filePath: {
47
- propDefinition: [
48
- googleDrive,
49
- "filePath",
50
- ],
51
- },
52
- name: {
53
- propDefinition: [
54
- googleDrive,
55
- "fileName",
56
- ],
57
- label: "Name",
58
- description: "The name of the new file (e.g., `myFile.csv`)",
59
- },
60
- mimeType: {
61
- propDefinition: [
62
- googleDrive,
63
- "mimeType",
64
- ],
65
- description: "The MIME type of the new file (e.g., `image/jpeg`)",
66
- },
67
- uploadType: {
68
- propDefinition: [
69
- googleDrive,
70
- "uploadType",
71
- ],
72
- optional: true,
73
- },
74
- },
75
- async run({ $ }) {
76
- const {
77
- fileId,
78
- fileUrl,
79
- filePath,
80
- name,
81
- mimeType,
82
- } = this;
83
- let { uploadType } = this;
84
- if (!fileUrl && !filePath) {
85
- throw new Error("One of File URL and File Path is required.");
86
- }
87
- const fileStream = await getFileStream({
88
- $,
89
- fileUrl,
90
- filePath,
91
- });
92
-
93
- if (!uploadType || uploadType === "") {
94
- try {
95
- // Its necessary to get the file stream again, after user streamToBuffer function and pass
96
- // the same object to updateFileMedia function, the function will throw an error about
97
- // circular json structure.
98
- // Deep clone is very slow in this case, so its better get the stream again
99
- const fileBuffer = await streamToBuffer(await getFileStream({
100
- $,
101
- fileUrl,
102
- filePath,
103
- }));
104
- const bufferSize = byteToMB(Buffer.byteLength(fileBuffer));
105
- uploadType = bufferSize > 5
106
- ? GOOGLE_DRIVE_UPLOAD_TYPE_RESUMABLE
107
- : undefined;
108
- } catch (err) {
109
- console.log(err);
110
- uploadType = undefined;
111
- }
112
- }
113
-
114
- if (uploadType === GOOGLE_DRIVE_UPLOAD_TYPE_MEDIA) {
115
- uploadType = undefined;
116
- }
117
- console.log(`Upload type: ${uploadType}`);
118
- // Update file media separately from metadata to prevent multipart upload,
119
- // which `google-apis-nodejs-client` doesn't seem to support for
120
- // [files.update](https://bit.ly/3lP5sWn)
121
- await this.googleDrive.updateFileMedia(fileId, fileStream, omitEmptyStringValues({
122
- mimeType,
123
- uploadType,
124
- }));
125
-
126
- const resp = await this.googleDrive.updateFile(fileId, omitEmptyStringValues({
127
- name: name || path.basename(fileUrl || filePath),
128
- mimeType,
129
- uploadType,
130
- }));
131
- $.export("$summary", "Successfully replaced the file");
132
- return resp;
133
- },
134
- };