@pipedream/google_drive 0.6.0 → 0.6.2
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/actions/add-file-sharing-preference/add-file-sharing-preference.mjs +1 -1
- package/actions/copy-file/copy-file.mjs +1 -1
- package/actions/create-file/create-file.mjs +2 -2
- package/actions/create-file-from-template/create-file-from-template.mjs +1 -1
- package/actions/create-file-from-text/create-file-from-text.mjs +1 -1
- package/actions/create-folder/create-folder.mjs +1 -1
- package/actions/create-shared-drive/create-shared-drive.mjs +1 -1
- package/actions/delete-file/delete-file.mjs +1 -1
- package/actions/delete-shared-drive/delete-shared-drive.mjs +1 -1
- package/actions/download-file/download-file.mjs +1 -1
- package/actions/find-file/find-file.mjs +1 -1
- package/actions/find-folder/find-folder.mjs +1 -1
- package/actions/find-forms/find-forms.mjs +1 -1
- package/actions/find-spreadsheets/find-spreadsheets.mjs +1 -1
- package/actions/get-folder-id-for-path/get-folder-id-for-path.mjs +1 -1
- package/actions/get-shared-drive/get-shared-drive.mjs +1 -1
- package/actions/list-files/list-files.mjs +1 -1
- package/actions/move-file/move-file.mjs +1 -1
- package/actions/move-file-to-trash/move-file-to-trash.mjs +1 -1
- package/actions/replace-file/replace-file.mjs +1 -1
- package/actions/search-shared-drives/search-shared-drives.mjs +1 -1
- package/actions/update-file/update-file.mjs +1 -1
- package/actions/update-shared-drive/update-shared-drive.mjs +1 -1
- package/actions/upload-file/upload-file.mjs +1 -1
- package/google_drive.app.mjs +9 -3
- package/package.json +1 -1
- package/sources/changes-to-specific-files/changes-to-specific-files.mjs +1 -1
- package/sources/changes-to-specific-files-shared-drive/changes-to-specific-files-shared-drive.mjs +45 -25
- package/sources/common-webhook.mjs +15 -0
- package/sources/new-files-instant/new-files-instant.mjs +14 -2
- package/sources/new-or-modified-comments/new-or-modified-comments.mjs +38 -13
- package/sources/new-or-modified-files/new-or-modified-files.mjs +39 -12
- package/sources/new-or-modified-folders/new-or-modified-folders.mjs +36 -10
- package/sources/new-shared-drive/new-shared-drive.mjs +1 -1
- package/sources/new-spreadsheet/new-spreadsheet.mjs +22 -11
|
@@ -11,7 +11,7 @@ export default {
|
|
|
11
11
|
name: "Add File Sharing Preference",
|
|
12
12
|
description:
|
|
13
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.
|
|
14
|
+
version: "0.1.1",
|
|
15
15
|
type: "action",
|
|
16
16
|
props: {
|
|
17
17
|
googleDrive,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_drive-copy-file",
|
|
5
5
|
name: "Copy File",
|
|
6
6
|
description: "Create a copy of the specified file. [See the docs](https://developers.google.com/drive/api/v3/reference/files/copy) for more information",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.1",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleDrive,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import googleDrive from "../../google_drive.app.mjs";
|
|
2
2
|
import fs from "fs";
|
|
3
|
-
import got from "got";
|
|
3
|
+
import got from "got@12.4.1";
|
|
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.
|
|
10
|
+
version: "0.1.2",
|
|
11
11
|
type: "action",
|
|
12
12
|
props: {
|
|
13
13
|
googleDrive,
|
|
@@ -8,7 +8,7 @@ export default {
|
|
|
8
8
|
key: "google_drive-create-file-from-template",
|
|
9
9
|
name: "Create New File From Template",
|
|
10
10
|
description: "Create a new Google Docs file from a template. Optionally include placeholders in the template document that will get replaced from this action. [See documentation](https://www.npmjs.com/package/google-docs-mustaches)",
|
|
11
|
-
version: "0.1.
|
|
11
|
+
version: "0.1.1",
|
|
12
12
|
type: "action",
|
|
13
13
|
props: {
|
|
14
14
|
googleDrive,
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
key: "google_drive-create-file-from-text",
|
|
6
6
|
name: "Create New File From Text",
|
|
7
7
|
description: "Create a new file from plain text. [See the docs](https://developers.google.com/drive/api/v3/reference/files/create) for more information",
|
|
8
|
-
version: "0.1.
|
|
8
|
+
version: "0.1.1",
|
|
9
9
|
type: "action",
|
|
10
10
|
props: {
|
|
11
11
|
googleDrive,
|
|
@@ -13,7 +13,7 @@ export default {
|
|
|
13
13
|
key: "google_drive-create-folder",
|
|
14
14
|
name: "Create Folder",
|
|
15
15
|
description: "Create a new empty folder. [See the docs](https://developers.google.com/drive/api/v3/reference/files/create) for more information",
|
|
16
|
-
version: "0.1.
|
|
16
|
+
version: "0.1.1",
|
|
17
17
|
type: "action",
|
|
18
18
|
props: {
|
|
19
19
|
googleDrive,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_drive-create-shared-drive",
|
|
5
5
|
name: "Create Shared Drive",
|
|
6
6
|
description: "Create a new shared drive. [See the docs](https://developers.google.com/drive/api/v3/reference/drives/create) for more information",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.1",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleDrive,
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
name: "Delete File",
|
|
6
6
|
description:
|
|
7
7
|
"Permanently delete a file or folder without moving it to the trash. [See the docs](https://developers.google.com/drive/api/v3/reference/files/delete) for more information",
|
|
8
|
-
version: "0.1.
|
|
8
|
+
version: "0.1.1",
|
|
9
9
|
type: "action",
|
|
10
10
|
props: {
|
|
11
11
|
googleDrive,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_drive-delete-shared-drive",
|
|
5
5
|
name: "Delete Shared Drive",
|
|
6
6
|
description: "Delete a shared drive without any content. [See the docs](https://developers.google.com/drive/api/v3/reference/drives/delete) for more information",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.1",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleDrive,
|
|
@@ -18,7 +18,7 @@ export default {
|
|
|
18
18
|
key: "google_drive-download-file",
|
|
19
19
|
name: "Download File",
|
|
20
20
|
description: "Download a file. [See the docs](https://developers.google.com/drive/api/v3/manage-downloads) for more information",
|
|
21
|
-
version: "0.1.
|
|
21
|
+
version: "0.1.1",
|
|
22
22
|
type: "action",
|
|
23
23
|
props: {
|
|
24
24
|
googleDrive,
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
key: "google_drive-find-file",
|
|
6
6
|
name: "Find File",
|
|
7
7
|
description: "Search for a specific file by name. [See the docs](https://developers.google.com/drive/api/v3/search-files) for more information",
|
|
8
|
-
version: "0.1.
|
|
8
|
+
version: "0.1.1",
|
|
9
9
|
type: "action",
|
|
10
10
|
props: {
|
|
11
11
|
googleDrive,
|
|
@@ -7,7 +7,7 @@ export default {
|
|
|
7
7
|
key: "google_drive-find-folder",
|
|
8
8
|
name: "Find Folder",
|
|
9
9
|
description: "Search for a specific folder by name. [See the docs](https://developers.google.com/drive/api/v3/search-files) for more information",
|
|
10
|
-
version: "0.1.
|
|
10
|
+
version: "0.1.1",
|
|
11
11
|
type: "action",
|
|
12
12
|
props: {
|
|
13
13
|
googleDrive,
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
key: "google_drive-find-forms",
|
|
6
6
|
name: "Find Forms",
|
|
7
7
|
description: "List Google Form documents or search for a Form by name. [See the docs](https://developers.google.com/drive/api/v3/search-files) for more information",
|
|
8
|
-
version: "0.0.
|
|
8
|
+
version: "0.0.2",
|
|
9
9
|
type: "action",
|
|
10
10
|
props: {
|
|
11
11
|
googleDrive,
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
key: "google_drive-find-spreadsheets",
|
|
6
6
|
name: "Find Spreadsheets",
|
|
7
7
|
description: "Search for a specific spreadsheet by name. [See the docs](https://developers.google.com/drive/api/v3/search-files) for more information",
|
|
8
|
-
version: "0.1.
|
|
8
|
+
version: "0.1.1",
|
|
9
9
|
type: "action",
|
|
10
10
|
props: {
|
|
11
11
|
googleDrive,
|
|
@@ -12,7 +12,7 @@ export default {
|
|
|
12
12
|
key: "google_drive-get-folder-id-for-path",
|
|
13
13
|
name: "Get Folder ID for a Path",
|
|
14
14
|
description: "Retrieve a folderId for a path. [See the docs](https://developers.google.com/drive/api/v3/search-files) for more information",
|
|
15
|
-
version: "0.1.
|
|
15
|
+
version: "0.1.1",
|
|
16
16
|
type: "action",
|
|
17
17
|
props: {
|
|
18
18
|
googleDrive,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_drive-get-shared-drive",
|
|
5
5
|
name: "Get Shared Drive",
|
|
6
6
|
description: "Get a shared drive's metadata by ID. [See the docs](https://developers.google.com/drive/api/v3/reference/drives/get) for more information",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.1",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleDrive,
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
key: "google_drive-list-files",
|
|
6
6
|
name: "List Files",
|
|
7
7
|
description: "List files from a specific folder. [See the docs](https://developers.google.com/drive/api/v3/reference/files/list) for more information",
|
|
8
|
-
version: "0.1.
|
|
8
|
+
version: "0.1.1",
|
|
9
9
|
type: "action",
|
|
10
10
|
props: {
|
|
11
11
|
googleDrive,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_drive-move-file",
|
|
5
5
|
name: "Move File",
|
|
6
6
|
description: "Move a file from one folder to another. [See the docs](https://developers.google.com/drive/api/v3/reference/files/update) for more information",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.1",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleDrive,
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
key: "google_drive-move-file-to-trash",
|
|
6
6
|
name: "Move File to Trash",
|
|
7
7
|
description: "Move a file or folder to trash. [See the docs](https://developers.google.com/drive/api/v3/reference/files/update) for more information",
|
|
8
|
-
version: "0.1.
|
|
8
|
+
version: "0.1.1",
|
|
9
9
|
type: "action",
|
|
10
10
|
props: {
|
|
11
11
|
googleDrive,
|
|
@@ -15,7 +15,7 @@ export default {
|
|
|
15
15
|
key: "google_drive-replace-file",
|
|
16
16
|
name: "Replace File",
|
|
17
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.
|
|
18
|
+
version: "0.1.1",
|
|
19
19
|
type: "action",
|
|
20
20
|
props: {
|
|
21
21
|
googleDrive,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_drive-search-shared-drives",
|
|
5
5
|
name: "Search for Shared Drives",
|
|
6
6
|
description: "Search for shared drives with query options. [See the docs](https://developers.google.com/drive/api/v3/search-shareddrives) for more information",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.1",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleDrive,
|
|
@@ -8,7 +8,7 @@ export default {
|
|
|
8
8
|
key: "google_drive-update-file",
|
|
9
9
|
name: "Update File",
|
|
10
10
|
description: "Update a file's metadata and/or content. [See the docs](https://developers.google.com/drive/api/v3/reference/files/update) for more information",
|
|
11
|
-
version: "0.1.
|
|
11
|
+
version: "0.1.1",
|
|
12
12
|
type: "action",
|
|
13
13
|
props: {
|
|
14
14
|
googleDrive,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_drive-update-shared-drive",
|
|
5
5
|
name: "Update Shared Drive",
|
|
6
6
|
description: "Update an existing shared drive. [See the docs](https://developers.google.com/drive/api/v3/reference/drives/update) for more information",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.1",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
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.
|
|
13
|
+
version: "0.1.1",
|
|
14
14
|
type: "action",
|
|
15
15
|
props: {
|
|
16
16
|
googleDrive,
|
package/google_drive.app.mjs
CHANGED
|
@@ -442,7 +442,7 @@ export default {
|
|
|
442
442
|
pageToken,
|
|
443
443
|
);
|
|
444
444
|
|
|
445
|
-
for (const drive
|
|
445
|
+
for (const drive of drives) {
|
|
446
446
|
yield drive;
|
|
447
447
|
}
|
|
448
448
|
|
|
@@ -626,6 +626,7 @@ export default {
|
|
|
626
626
|
* @type {Comment}
|
|
627
627
|
*/
|
|
628
628
|
async *listComments(fileId, startModifiedTime = null) {
|
|
629
|
+
let data;
|
|
629
630
|
const drive = this.drive();
|
|
630
631
|
const opts = {
|
|
631
632
|
fileId,
|
|
@@ -633,12 +634,17 @@ export default {
|
|
|
633
634
|
pageSize: 100,
|
|
634
635
|
};
|
|
635
636
|
|
|
636
|
-
if (startModifiedTime !== null) {
|
|
637
|
+
if (startModifiedTime !== null && startModifiedTime !== undefined) {
|
|
637
638
|
opts.startModifiedTime = new Date(startModifiedTime).toISOString();
|
|
638
639
|
}
|
|
639
640
|
|
|
640
641
|
while (true) {
|
|
641
|
-
|
|
642
|
+
try {
|
|
643
|
+
({ data } = await drive.comments.list(opts));
|
|
644
|
+
} catch (error) {
|
|
645
|
+
console.log("listComments error!!", error);
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
642
648
|
const {
|
|
643
649
|
comments = [],
|
|
644
650
|
nextPageToken,
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@ export default {
|
|
|
16
16
|
key: "google_drive-changes-to-specific-files",
|
|
17
17
|
name: "Changes to Specific Files",
|
|
18
18
|
description: "Watches for changes to specific files, emitting an event any time 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.1.
|
|
19
|
+
version: "0.1.1",
|
|
20
20
|
type: "source",
|
|
21
21
|
// Dedupe events based on the "x-goog-message-number" header for the target channel:
|
|
22
22
|
// https://developers.google.com/drive/api/v3/push#making-watch-requests
|
package/sources/changes-to-specific-files-shared-drive/changes-to-specific-files-shared-drive.mjs
CHANGED
|
@@ -25,7 +25,7 @@ export default {
|
|
|
25
25
|
key: "google_drive-changes-to-specific-files-shared-drive",
|
|
26
26
|
name: "Changes to Specific Files (Shared Drive)",
|
|
27
27
|
description: "Watches for changes to specific files in a shared drive, emitting an event any time a change is made to one of those files",
|
|
28
|
-
version: "0.1.
|
|
28
|
+
version: "0.1.1",
|
|
29
29
|
type: "source",
|
|
30
30
|
// Dedupe events based on the "x-goog-message-number" header for the target channel:
|
|
31
31
|
// https://developers.google.com/drive/api/v3/push#making-watch-requests
|
|
@@ -40,20 +40,27 @@ export default {
|
|
|
40
40
|
default: [],
|
|
41
41
|
options({ prevContext }) {
|
|
42
42
|
const { nextPageToken } = prevContext;
|
|
43
|
-
|
|
44
|
-
const opts = this.isMyDrive()
|
|
45
|
-
? baseOpts
|
|
46
|
-
: {
|
|
47
|
-
...baseOpts,
|
|
48
|
-
corpora: "drive",
|
|
49
|
-
driveId: this.getDriveId(),
|
|
50
|
-
includeItemsFromAllDrives: true,
|
|
51
|
-
supportsAllDrives: true,
|
|
52
|
-
};
|
|
53
|
-
return this.googleDrive.listFilesOptions(nextPageToken, opts);
|
|
43
|
+
return this.googleDrive.listFilesOptions(nextPageToken, this.getFilesOpts());
|
|
54
44
|
},
|
|
55
45
|
},
|
|
56
46
|
},
|
|
47
|
+
hooks: {
|
|
48
|
+
async deploy() {
|
|
49
|
+
const daysAgo = new Date();
|
|
50
|
+
daysAgo.setDate(daysAgo.getDate() - 30);
|
|
51
|
+
const timeString = daysAgo.toISOString();
|
|
52
|
+
|
|
53
|
+
const args = this.getFilesOpts({
|
|
54
|
+
q: `mimeType != "application/vnd.google-apps.folder" and modifiedTime > "${timeString}" and trashed = false`,
|
|
55
|
+
fields: "files",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const { data } = await this.googleDrive.drive().files.list(args);
|
|
59
|
+
|
|
60
|
+
this.processChanges(data.files);
|
|
61
|
+
},
|
|
62
|
+
...common.hooks,
|
|
63
|
+
},
|
|
57
64
|
methods: {
|
|
58
65
|
...common.methods,
|
|
59
66
|
getUpdateTypes() {
|
|
@@ -69,35 +76,48 @@ export default {
|
|
|
69
76
|
name: fileName,
|
|
70
77
|
modifiedTime: tsString,
|
|
71
78
|
} = data;
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
const ts = Date.parse(tsString);
|
|
80
|
+
const eventId = headers && headers["x-goog-message-number"];
|
|
81
|
+
const resourceState = headers && headers["x-goog-resource-state"];
|
|
82
|
+
|
|
83
|
+
const summary = resourceState
|
|
84
|
+
? `${resourceState.toUpperCase()} - ${fileName || "Untitled"}`
|
|
85
|
+
: fileName || "Untitled";
|
|
76
86
|
|
|
77
87
|
return {
|
|
78
|
-
id: `${fileId}-${eventId}`,
|
|
79
|
-
summary
|
|
80
|
-
|
|
81
|
-
}`,
|
|
82
|
-
ts: Date.parse(tsString),
|
|
88
|
+
id: `${fileId}-${eventId || ts}`,
|
|
89
|
+
summary,
|
|
90
|
+
ts,
|
|
83
91
|
};
|
|
84
92
|
},
|
|
85
93
|
isFileRelevant(file) {
|
|
86
94
|
return this.files.includes(file.id);
|
|
87
95
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
getChanges(headers) {
|
|
97
|
+
if (!headers) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
91
101
|
change: {
|
|
92
102
|
state: headers["x-goog-resource-state"],
|
|
93
103
|
resourceURI: headers["x-goog-resource-uri"],
|
|
94
104
|
changed: headers["x-goog-changed"], // "Additional details about the changes. Possible values: content, parents, children, permissions"
|
|
95
105
|
},
|
|
96
106
|
};
|
|
107
|
+
},
|
|
108
|
+
processChange(file, headers) {
|
|
109
|
+
const changes = this.getChanges(headers);
|
|
110
|
+
const eventToEmit = {
|
|
111
|
+
file,
|
|
112
|
+
...changes,
|
|
113
|
+
};
|
|
97
114
|
const meta = this.generateMeta(file, headers);
|
|
98
115
|
this.$emit(eventToEmit, meta);
|
|
99
116
|
},
|
|
100
|
-
|
|
117
|
+
processChanges(changedFiles, headers) {
|
|
118
|
+
console.log(`Processing ${changedFiles.length} changed files`);
|
|
119
|
+
console.log(`Changed files: ${JSON.stringify(changedFiles, null, 2)}!!!`);
|
|
120
|
+
console.log(`Files: ${this.files}!!!`);
|
|
101
121
|
for (const file of changedFiles) {
|
|
102
122
|
if (!this.isFileRelevant(file)) {
|
|
103
123
|
console.log(`Skipping event for irrelevant file ${file.id}`);
|
|
@@ -96,6 +96,21 @@ export default {
|
|
|
96
96
|
getDriveId(drive = this.drive) {
|
|
97
97
|
return googleDrive.methods.getDriveId(drive);
|
|
98
98
|
},
|
|
99
|
+
getFilesOpts(args = {}) {
|
|
100
|
+
const opts = {
|
|
101
|
+
q: "mimeType != 'application/vnd.google-apps.folder' and trashed = false",
|
|
102
|
+
...args,
|
|
103
|
+
};
|
|
104
|
+
return this.isMyDrive()
|
|
105
|
+
? opts
|
|
106
|
+
: {
|
|
107
|
+
...opts,
|
|
108
|
+
corpora: "drive",
|
|
109
|
+
driveId: this.getDriveId(),
|
|
110
|
+
includeItemsFromAllDrives: true,
|
|
111
|
+
supportsAllDrives: true,
|
|
112
|
+
};
|
|
113
|
+
},
|
|
99
114
|
/**
|
|
100
115
|
* This method returns the types of updates/events from Google Drive that
|
|
101
116
|
* the event source should listen to. This base implementation returns an
|
|
@@ -9,7 +9,7 @@ export default {
|
|
|
9
9
|
key: "google_drive-new-files-instant",
|
|
10
10
|
name: "New Files (Instant)",
|
|
11
11
|
description: "Emit new event any time a new file is added in your linked Google Drive",
|
|
12
|
-
version: "0.1.
|
|
12
|
+
version: "0.1.1",
|
|
13
13
|
type: "source",
|
|
14
14
|
dedupe: "unique",
|
|
15
15
|
props: {
|
|
@@ -24,7 +24,7 @@ export default {
|
|
|
24
24
|
options({ prevContext }) {
|
|
25
25
|
const { nextPageToken } = prevContext;
|
|
26
26
|
const baseOpts = {
|
|
27
|
-
q: "mimeType = 'application/vnd.google-apps.folder'",
|
|
27
|
+
q: "mimeType = 'application/vnd.google-apps.folder' and trashed = false",
|
|
28
28
|
};
|
|
29
29
|
const opts = this.isMyDrive()
|
|
30
30
|
? baseOpts
|
|
@@ -40,6 +40,18 @@ export default {
|
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
42
|
hooks: {
|
|
43
|
+
async deploy() {
|
|
44
|
+
const daysAgo = new Date();
|
|
45
|
+
daysAgo.setDate(daysAgo.getDate() - 30);
|
|
46
|
+
const timeString = daysAgo.toISOString();
|
|
47
|
+
|
|
48
|
+
const { data } = await this.googleDrive.drive().files.list({
|
|
49
|
+
q: `mimeType != "application/vnd.google-apps.folder" and modifiedTime > "${timeString}" and trashed = false`,
|
|
50
|
+
fields: "files(id)",
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
await this.processChanges(data.files);
|
|
54
|
+
},
|
|
43
55
|
...common.hooks,
|
|
44
56
|
async activate() {
|
|
45
57
|
await common.hooks.activate.bind(this)();
|
|
@@ -17,13 +17,27 @@ export default {
|
|
|
17
17
|
name: "New or Modified Comments",
|
|
18
18
|
description:
|
|
19
19
|
"Emits a new event any time a file comment is added, modified, or deleted in your linked Google Drive",
|
|
20
|
-
version: "0.1.
|
|
20
|
+
// version: "0.1.1",
|
|
21
|
+
version: "0.1.3",
|
|
21
22
|
type: "source",
|
|
22
23
|
// Dedupe events based on the "x-goog-message-number" header for the target channel:
|
|
23
24
|
// https://developers.google.com/drive/api/v3/push#making-watch-requests
|
|
24
25
|
dedupe: "unique",
|
|
25
26
|
hooks: {
|
|
26
|
-
|
|
27
|
+
async deploy() {
|
|
28
|
+
const daysAgo = new Date();
|
|
29
|
+
daysAgo.setDate(daysAgo.getDate() - 30);
|
|
30
|
+
const timeString = daysAgo.toISOString();
|
|
31
|
+
|
|
32
|
+
const args = this.getFilesOpts({
|
|
33
|
+
q: `mimeType != "application/vnd.google-apps.folder" and modifiedTime > "${timeString}" and trashed = false`,
|
|
34
|
+
fields: "files",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const { data } = await this.googleDrive.drive().files.list(args);
|
|
38
|
+
|
|
39
|
+
await this.processChanges(data.files);
|
|
40
|
+
},
|
|
27
41
|
async activate() {
|
|
28
42
|
await common.hooks.activate.bind(this)();
|
|
29
43
|
this._setInitTime(Date.now());
|
|
@@ -58,14 +72,32 @@ export default {
|
|
|
58
72
|
content: summary,
|
|
59
73
|
modifiedTime: tsString,
|
|
60
74
|
} = data;
|
|
61
|
-
const
|
|
75
|
+
const ts = Date.parse(tsString);
|
|
76
|
+
const eventId = headers && headers["x-goog-message-number"];
|
|
77
|
+
|
|
62
78
|
return {
|
|
63
|
-
id: `${commentId}-${eventId}`,
|
|
79
|
+
id: `${commentId}-${eventId || ts}`,
|
|
64
80
|
summary,
|
|
65
|
-
ts
|
|
81
|
+
ts,
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
getChanges(headers) {
|
|
85
|
+
if (!headers) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
change: {
|
|
90
|
+
state: headers["x-goog-resource-state"],
|
|
91
|
+
resourceURI: headers["x-goog-resource-uri"],
|
|
92
|
+
// Additional details about the changes. Possible values: content,
|
|
93
|
+
// parents, children, permissions.
|
|
94
|
+
changed: headers["x-goog-changed"],
|
|
95
|
+
},
|
|
66
96
|
};
|
|
67
97
|
},
|
|
68
98
|
async processChanges(changedFiles, headers) {
|
|
99
|
+
const changes = this.getChanges(headers);
|
|
100
|
+
|
|
69
101
|
for (const file of changedFiles) {
|
|
70
102
|
const lastCommentTimeForFile = this._getLastCommentTimeForFile(file.id);
|
|
71
103
|
let maxModifiedTime = lastCommentTimeForFile;
|
|
@@ -83,14 +115,7 @@ export default {
|
|
|
83
115
|
const eventToEmit = {
|
|
84
116
|
comment,
|
|
85
117
|
file,
|
|
86
|
-
|
|
87
|
-
state: headers["x-goog-resource-state"],
|
|
88
|
-
resourceURI: headers["x-goog-resource-uri"],
|
|
89
|
-
|
|
90
|
-
// Additional details about the changes. Possible values: content,
|
|
91
|
-
// parents, children, permissions.
|
|
92
|
-
changed: headers["x-goog-changed"],
|
|
93
|
-
},
|
|
118
|
+
...changes,
|
|
94
119
|
};
|
|
95
120
|
const meta = this.generateMeta(comment, headers);
|
|
96
121
|
this.$emit(eventToEmit, meta);
|
|
@@ -20,11 +20,26 @@ export default {
|
|
|
20
20
|
key: "google_drive-new-or-modified-files",
|
|
21
21
|
name: "New or Modified Files",
|
|
22
22
|
description: "Emit new event any time any file in your linked Google Drive is added, modified, or deleted",
|
|
23
|
-
version: "0.1.
|
|
23
|
+
version: "0.1.1",
|
|
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
|
|
27
27
|
dedupe: "unique",
|
|
28
|
+
hooks: {
|
|
29
|
+
async deploy() {
|
|
30
|
+
const daysAgo = new Date();
|
|
31
|
+
daysAgo.setDate(daysAgo.getDate() - 30);
|
|
32
|
+
const timeString = daysAgo.toISOString();
|
|
33
|
+
|
|
34
|
+
const { data } = await this.googleDrive.drive().files.list({
|
|
35
|
+
q: `mimeType != "application/vnd.google-apps.folder" and modifiedTime > "${timeString}" and trashed = false`,
|
|
36
|
+
fields: "files",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await this.processChanges(data.files);
|
|
40
|
+
},
|
|
41
|
+
...common.hooks,
|
|
42
|
+
},
|
|
28
43
|
methods: {
|
|
29
44
|
...common.methods,
|
|
30
45
|
getUpdateTypes() {
|
|
@@ -40,25 +55,37 @@ export default {
|
|
|
40
55
|
name: summary,
|
|
41
56
|
modifiedTime: tsString,
|
|
42
57
|
} = data;
|
|
43
|
-
const
|
|
58
|
+
const ts = Date.parse(tsString);
|
|
59
|
+
const eventId = headers && headers["x-goog-message-number"];
|
|
60
|
+
|
|
44
61
|
return {
|
|
45
|
-
id: `${fileId}-${eventId}`,
|
|
62
|
+
id: `${fileId}-${eventId || ts}`,
|
|
46
63
|
summary,
|
|
47
|
-
ts
|
|
64
|
+
ts,
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
async getChanges(headers) {
|
|
68
|
+
if (!headers) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const resourceUri = headers["x-goog-resource-uri"];
|
|
72
|
+
const metadata = await this.googleDrive.getFileMetadata(`${resourceUri}&fields=*`);
|
|
73
|
+
return {
|
|
74
|
+
...metadata,
|
|
75
|
+
change: {
|
|
76
|
+
state: headers["x-goog-resource-state"],
|
|
77
|
+
resourceURI: headers["x-goog-resource-uri"],
|
|
78
|
+
changed: headers["x-goog-changed"], // "Additional details about the changes. Possible values: content, parents, children, permissions"
|
|
79
|
+
},
|
|
48
80
|
};
|
|
49
81
|
},
|
|
50
82
|
async processChanges(changedFiles, headers) {
|
|
51
|
-
|
|
52
|
-
const metadata = await this.googleDrive.getFileMetadata(`${headers["x-goog-resource-uri"]}&fields=*`);
|
|
83
|
+
const changes = await this.getChanges(headers);
|
|
53
84
|
|
|
85
|
+
for (const file of changedFiles) {
|
|
54
86
|
const eventToEmit = {
|
|
55
87
|
file,
|
|
56
|
-
...
|
|
57
|
-
change: {
|
|
58
|
-
state: headers["x-goog-resource-state"],
|
|
59
|
-
resourceURI: headers["x-goog-resource-uri"],
|
|
60
|
-
changed: headers["x-goog-changed"], // "Additional details about the changes. Possible values: content, parents, children, permissions"
|
|
61
|
-
},
|
|
88
|
+
...changes,
|
|
62
89
|
};
|
|
63
90
|
const meta = this.generateMeta(file, headers);
|
|
64
91
|
this.$emit(eventToEmit, meta);
|
|
@@ -20,11 +20,26 @@ export default {
|
|
|
20
20
|
key: "google_drive-new-or-modified-folders",
|
|
21
21
|
name: "New or Modified Folders",
|
|
22
22
|
description: "Emit new event any time any folder in your linked Google Drive is added, modified, or deleted",
|
|
23
|
-
version: "0.1.
|
|
23
|
+
version: "0.1.1",
|
|
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
|
|
27
27
|
dedupe: "unique",
|
|
28
|
+
hooks: {
|
|
29
|
+
async deploy() {
|
|
30
|
+
const daysAgo = new Date();
|
|
31
|
+
daysAgo.setDate(daysAgo.getDate() - 30);
|
|
32
|
+
const timeString = daysAgo.toISOString();
|
|
33
|
+
|
|
34
|
+
const { data } = await this.googleDrive.drive().files.list({
|
|
35
|
+
q: `mimeType = "application/vnd.google-apps.folder" and modifiedTime > "${timeString}" and trashed = false`,
|
|
36
|
+
fields: "files(id, mimeType)",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await this.processChanges(data.files);
|
|
40
|
+
},
|
|
41
|
+
...common.hooks,
|
|
42
|
+
},
|
|
28
43
|
methods: {
|
|
29
44
|
...common.methods,
|
|
30
45
|
_getLastModifiedTimeForFile(fileId) {
|
|
@@ -51,6 +66,21 @@ export default {
|
|
|
51
66
|
ts,
|
|
52
67
|
};
|
|
53
68
|
},
|
|
69
|
+
async getChanges(headers) {
|
|
70
|
+
if (!headers) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const resourceUri = headers["x-goog-resource-uri"];
|
|
74
|
+
const metadata = await this.googleDrive.getFileMetadata(`${resourceUri}&fields=*`);
|
|
75
|
+
return {
|
|
76
|
+
...metadata,
|
|
77
|
+
change: {
|
|
78
|
+
state: headers["x-goog-resource-state"],
|
|
79
|
+
resourceURI: headers["x-goog-resource-uri"],
|
|
80
|
+
changed: headers["x-goog-changed"], // "Additional details about the changes. Possible values: content, parents, children, permissions"
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
},
|
|
54
84
|
async processChanges(changedFiles, headers) {
|
|
55
85
|
const files = changedFiles.filter(
|
|
56
86
|
// API docs that define Google Drive folders:
|
|
@@ -67,18 +97,14 @@ export default {
|
|
|
67
97
|
const modifiedTime = Date.parse(fileInfo.modifiedTime);
|
|
68
98
|
if (lastModifiedTimeForFile == modifiedTime) continue;
|
|
69
99
|
|
|
70
|
-
const
|
|
100
|
+
const changes = await this.getChanges(headers);
|
|
71
101
|
|
|
72
102
|
const eventToEmit = {
|
|
73
|
-
file,
|
|
74
|
-
...
|
|
75
|
-
change: {
|
|
76
|
-
state: headers["x-goog-resource-state"],
|
|
77
|
-
resourceURI: headers["x-goog-resource-uri"],
|
|
78
|
-
changed: headers["x-goog-changed"], // "Additional details about the changes. Possible values: content, parents, children, permissions"
|
|
79
|
-
},
|
|
103
|
+
file: fileInfo,
|
|
104
|
+
...changes,
|
|
80
105
|
};
|
|
81
|
-
const meta = this.generateMeta(
|
|
106
|
+
const meta = this.generateMeta(fileInfo, modifiedTime);
|
|
107
|
+
|
|
82
108
|
this.$emit(eventToEmit, meta);
|
|
83
109
|
|
|
84
110
|
this._setModifiedTimeForFile(file.id, modifiedTime);
|
|
@@ -6,7 +6,7 @@ export default {
|
|
|
6
6
|
type: "source",
|
|
7
7
|
name: "New Spreadsheet (Instant)",
|
|
8
8
|
description: "Emit new event each time a new spreadsheet is created in a drive.",
|
|
9
|
-
version: "0.1.
|
|
9
|
+
version: "0.1.1",
|
|
10
10
|
props: {
|
|
11
11
|
googleDrive: newFilesInstant.props.googleDrive,
|
|
12
12
|
db: newFilesInstant.props.db,
|
|
@@ -54,19 +54,30 @@ export default {
|
|
|
54
54
|
}
|
|
55
55
|
return opts;
|
|
56
56
|
},
|
|
57
|
+
getSpreadsheetsFromFiles(files, limit) {
|
|
58
|
+
return files.reduce(async (acc, file) => {
|
|
59
|
+
const spreadsheets = await acc;
|
|
60
|
+
const fileInfo = await this.googleDrive.getFile(file.id);
|
|
61
|
+
return spreadsheets.length >= limit
|
|
62
|
+
? spreadsheets
|
|
63
|
+
: spreadsheets.concat(fileInfo);
|
|
64
|
+
}, []);
|
|
65
|
+
},
|
|
57
66
|
async getSpreadsheets(limit) {
|
|
58
|
-
const spreadsheets = [];
|
|
59
67
|
const foldersIds = this.folders;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
spreadsheets.push(fileInfo);
|
|
66
|
-
if (spreadsheets.length >= limit) { return spreadsheets; }
|
|
67
|
-
}
|
|
68
|
+
|
|
69
|
+
if (!foldersIds.length) {
|
|
70
|
+
const opts = this.getSpreadsheetsFromFolderOpts("root");
|
|
71
|
+
const { files } = await this.googleDrive.listFilesInPage(null, opts);
|
|
72
|
+
return this.getSpreadsheetsFromFiles(files, limit);
|
|
68
73
|
}
|
|
69
|
-
|
|
74
|
+
|
|
75
|
+
return foldersIds.reduce(async (spreadsheets, folderId) => {
|
|
76
|
+
const opts = this.getSpreadsheetsFromFolderOpts(folderId);
|
|
77
|
+
const { files } = await this.googleDrive.listFilesInPage(null, opts);
|
|
78
|
+
const nextSpreadsheets = await this.getSpreadsheetsFromFiles(files, limit);
|
|
79
|
+
return (await spreadsheets).concat(nextSpreadsheets);
|
|
80
|
+
}, []);
|
|
70
81
|
},
|
|
71
82
|
},
|
|
72
83
|
};
|