@pipedream/google_drive 0.6.6 → 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/google_drive",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "Pipedream Google_drive Components",
5
5
  "main": "google_drive.app.mjs",
6
6
  "keywords": [
@@ -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.2",
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 modifiedTime > "${timeString}" and trashed = false`,
51
- fields: "files(id)",
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
- await this.processChanges(data.files);
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
- async processChanges(changedFiles) {
84
- const lastFileCreatedTime = this._getLastFileCreatedTime();
85
- let maxCreatedTime = lastFileCreatedTime;
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
- this.$emit(fileInfo, {
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
- maxCreatedTime = Math.max(createdTime, maxCreatedTime);
104
- this._setLastFileCreatedTime(maxCreatedTime);
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,