@pipedream/google_drive 0.6.5 → 0.6.7
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/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import cronParser from "cron-parser";
|
|
2
|
+
import sampleEmit from "./test-event.mjs";
|
|
2
3
|
import includes from "lodash/includes.js";
|
|
3
4
|
import { v4 as uuid } from "uuid";
|
|
4
5
|
|
|
@@ -16,7 +17,7 @@ export default {
|
|
|
16
17
|
key: "google_drive-changes-to-specific-files",
|
|
17
18
|
name: "Changes to Specific Files",
|
|
18
19
|
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.
|
|
20
|
+
version: "0.1.2",
|
|
20
21
|
type: "source",
|
|
21
22
|
// Dedupe events based on the "x-goog-message-number" header for the target channel:
|
|
22
23
|
// https://developers.google.com/drive/api/v3/push#making-watch-requests
|
|
@@ -223,4 +224,5 @@ export default {
|
|
|
223
224
|
|
|
224
225
|
this.processChange(file, headers);
|
|
225
226
|
},
|
|
227
|
+
sampleEmit,
|
|
226
228
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default JSON.parse("{\n \"file\": {\n \"kind\": \"drive#file\",\n \"id\": \"1LmXTIQ0wqKP7T3-l9r127MaTXn3pVbTmw4Pt\",\n \"name\": \"Pipedream 2213\",\n \"mimeType\": \"application/vnd.google-apps.spreadsheet\"\n },\n \"change\": {\n \"state\": \"update\",\n \"resourceURI\": \"https://www.googleapis.com/drive/v3/files/1LmXTIQ0wqKP7T3-l9r127MaTXn3pVbTmw4P?alt=json&supportsAllDrives=true\",\n \"changed\": \"properties\"\n }\n}")
|
|
@@ -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 any time a new file is added in your linked Google Drive",
|
|
13
|
-
version: "0.1.
|
|
13
|
+
version: "0.1.3",
|
|
14
14
|
type: "source",
|
|
15
15
|
dedupe: "unique",
|
|
16
16
|
props: {
|
|
@@ -47,11 +47,13 @@ export default {
|
|
|
47
47
|
const timeString = daysAgo.toISOString();
|
|
48
48
|
|
|
49
49
|
const { data } = await this.googleDrive.drive().files.list({
|
|
50
|
-
q: `mimeType != "application/vnd.google-apps.folder" and
|
|
51
|
-
|
|
50
|
+
q: `mimeType != "application/vnd.google-apps.folder" and createdTime > "${timeString}" and trashed = false`,
|
|
51
|
+
orderBy: "createdTime desc",
|
|
52
|
+
fields: "*",
|
|
53
|
+
pageSize: 25,
|
|
52
54
|
});
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
this.emitFiles(data.files);
|
|
55
57
|
},
|
|
56
58
|
...common.hooks,
|
|
57
59
|
async activate() {
|
|
@@ -80,29 +82,35 @@ export default {
|
|
|
80
82
|
GOOGLE_DRIVE_NOTIFICATION_CHANGE,
|
|
81
83
|
];
|
|
82
84
|
},
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
for (const file of changedFiles) {
|
|
88
|
-
const fileInfo = await this.googleDrive.getFile(file.id);
|
|
89
|
-
const createdTime = Date.parse(fileInfo.createdTime);
|
|
90
|
-
if (
|
|
91
|
-
!this.shouldProcess(fileInfo) ||
|
|
92
|
-
createdTime < lastFileCreatedTime
|
|
93
|
-
) {
|
|
85
|
+
emitFiles(files) {
|
|
86
|
+
for (const file of files) {
|
|
87
|
+
if (!this.shouldProcess(file)) {
|
|
94
88
|
continue;
|
|
95
89
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
summary: `New File: ${fileInfo.name}`,
|
|
90
|
+
this.$emit(file, {
|
|
91
|
+
summary: `New File: ${file.name}`,
|
|
99
92
|
id: file.id,
|
|
100
|
-
ts: createdTime,
|
|
93
|
+
ts: Date.parse(file.createdTime),
|
|
101
94
|
});
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
async processChanges() {
|
|
98
|
+
const lastFileCreatedTime = this._getLastFileCreatedTime();
|
|
99
|
+
const timeString = new Date(lastFileCreatedTime).toISOString();
|
|
102
100
|
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
const { data } = await this.googleDrive.drive().files.list({
|
|
102
|
+
q: `mimeType != "application/vnd.google-apps.folder" and createdTime > "${timeString}" and trashed = false`,
|
|
103
|
+
orderBy: "createdTime desc",
|
|
104
|
+
fields: "*",
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
if (!data.files?.length) {
|
|
108
|
+
return;
|
|
105
109
|
}
|
|
110
|
+
|
|
111
|
+
this.emitFiles(data.files);
|
|
112
|
+
|
|
113
|
+
this._setLastFileCreatedTime(Date.parse(data.files[0].createdTime));
|
|
106
114
|
},
|
|
107
115
|
},
|
|
108
116
|
sampleEmit,
|