Skip to content

Commit af81188

Browse files
authored
Merge branch 'master' into issue-18428
2 parents 91366d2 + 6545da9 commit af81188

File tree

12 files changed

+182
-16
lines changed

12 files changed

+182
-16
lines changed

components/google_drive/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/google_drive",
3-
"version": "1.0.7",
3+
"version": "1.1.0",
44
"description": "Pipedream Google_drive Components",
55
"main": "google_drive.app.mjs",
66
"keywords": [
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import common from "../common-webhook.mjs";
2+
import {
3+
MY_DRIVE_VALUE,
4+
GOOGLE_DRIVE_NOTIFICATION_ADD,
5+
GOOGLE_DRIVE_NOTIFICATION_CHANGE,
6+
GOOGLE_DRIVE_NOTIFICATION_UPDATE,
7+
} from "../../common/constants.mjs";
8+
import commonDedupeChanges from "../common-dedupe-changes.mjs";
9+
import { stashFile } from "../../common/utils.mjs";
10+
11+
export default {
12+
...common,
13+
key: "google_drive-changes-to-files-in-drive",
14+
name: "Changes to Files in Drive",
15+
description: "Emit new event when a change is made to one of the specified files. [See the documentation](https://developers.google.com/drive/api/v3/reference/changes/watch)",
16+
version: "0.0.1",
17+
type: "source",
18+
dedupe: "unique",
19+
props: {
20+
infoAlert: {
21+
type: "alert",
22+
alertType: "info",
23+
content: "This source uses `changes.watch` and supports watching 10+ files. To watch for changes to fewer than 10 files, you may want to use the **Changes to Specific Files** source instead (uses `files.watch`).",
24+
},
25+
...common.props,
26+
drive: {
27+
type: "string",
28+
label: "Drive",
29+
description: "Defaults to `My Drive`. To use a [Shared Drive](https://support.google.com/a/users/answer/9310351), use the **Changes to Specific Files (Shared Drive)** source instead.",
30+
optional: true,
31+
default: MY_DRIVE_VALUE,
32+
},
33+
files: {
34+
type: "string[]",
35+
label: "Files",
36+
description: "The files you want to watch for changes.",
37+
options({ prevContext }) {
38+
const { nextPageToken } = prevContext;
39+
return this.googleDrive.listFilesOptions(nextPageToken, this.getListFilesOpts());
40+
},
41+
},
42+
includeLink: {
43+
label: "Include Link",
44+
type: "boolean",
45+
description: "Upload file to your File Stash and emit temporary download link to the file. Google Workspace documents will be converted to PDF. See [the docs](https://pipedream.com/docs/connect/components/files) to learn more about working with files in Pipedream.",
46+
default: false,
47+
optional: true,
48+
},
49+
dir: {
50+
type: "dir",
51+
accessMode: "write",
52+
optional: true,
53+
},
54+
...commonDedupeChanges.props,
55+
},
56+
hooks: {
57+
async deploy() {
58+
const daysAgo = new Date();
59+
daysAgo.setDate(daysAgo.getDate() - 30);
60+
const timeString = daysAgo.toISOString();
61+
62+
const args = this.getListFilesOpts({
63+
q: `mimeType != "application/vnd.google-apps.folder" and modifiedTime > "${timeString}" and trashed = false`,
64+
fields: "files",
65+
pageSize: 5,
66+
});
67+
68+
const { files } = await this.googleDrive.listFilesInPage(null, args);
69+
70+
await this.processChanges(files);
71+
},
72+
...common.hooks,
73+
},
74+
methods: {
75+
...common.methods,
76+
getUpdateTypes() {
77+
return [
78+
GOOGLE_DRIVE_NOTIFICATION_ADD,
79+
GOOGLE_DRIVE_NOTIFICATION_CHANGE,
80+
GOOGLE_DRIVE_NOTIFICATION_UPDATE,
81+
];
82+
},
83+
generateMeta(data, headers) {
84+
const {
85+
id: fileId,
86+
name: fileName,
87+
modifiedTime: tsString,
88+
} = data;
89+
const ts = Date.parse(tsString);
90+
const resourceState = headers && headers["x-goog-resource-state"];
91+
92+
const summary = resourceState
93+
? `${resourceState.toUpperCase()} - ${fileName || "Untitled"}`
94+
: fileName || "Untitled";
95+
96+
return {
97+
id: `${fileId}-${ts}`,
98+
summary,
99+
ts,
100+
};
101+
},
102+
isFileRelevant(file) {
103+
return this.files.includes(file.id);
104+
},
105+
getChanges(headers) {
106+
if (!headers) {
107+
return {
108+
change: { },
109+
};
110+
}
111+
return {
112+
change: {
113+
state: headers["x-goog-resource-state"],
114+
resourceURI: headers["x-goog-resource-uri"],
115+
changed: headers["x-goog-changed"], // "Additional details about the changes. Possible values: content, parents, children, permissions"
116+
},
117+
};
118+
},
119+
async processChange(file, headers) {
120+
const changes = this.getChanges(headers);
121+
const fileInfo = await this.googleDrive.getFile(file.id);
122+
if (this.includeLink) {
123+
fileInfo.file = await stashFile(file, this.googleDrive, this.dir);
124+
}
125+
const eventToEmit = {
126+
file: fileInfo,
127+
...changes,
128+
};
129+
const meta = this.generateMeta(fileInfo, headers);
130+
this.$emit(eventToEmit, meta);
131+
},
132+
async processChanges(changedFiles, headers) {
133+
console.log(`Processing ${changedFiles.length} changed files`);
134+
console.log(`Changed files: ${JSON.stringify(changedFiles, null, 2)}!!!`);
135+
console.log(`Files: ${this.files}!!!`);
136+
137+
const filteredFiles = this.checkMinimumInterval(changedFiles);
138+
for (const file of filteredFiles) {
139+
if (!this.isFileRelevant(file)) {
140+
console.log(`Skipping event for irrelevant file ${file.id}`);
141+
continue;
142+
}
143+
await this.processChange(file, headers);
144+
}
145+
},
146+
},
147+
};

components/google_drive/sources/changes-to-specific-files-shared-drive/changes-to-specific-files-shared-drive.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default {
2828
key: "google_drive-changes-to-specific-files-shared-drive",
2929
name: "Changes to Specific Files (Shared Drive)",
3030
description: "Watches for changes to specific files in a shared drive, emitting an event when a change is made to one of those files",
31-
version: "0.3.0",
31+
version: "0.3.1",
3232
type: "source",
3333
// Dedupe events based on the "x-goog-message-number" header for the target channel:
3434
// https://developers.google.com/drive/api/v3/push#making-watch-requests
@@ -92,15 +92,14 @@ export default {
9292
modifiedTime: tsString,
9393
} = data;
9494
const ts = Date.parse(tsString);
95-
const eventId = headers && headers["x-goog-message-number"];
9695
const resourceState = headers && headers["x-goog-resource-state"];
9796

9897
const summary = resourceState
9998
? `${resourceState.toUpperCase()} - ${fileName || "Untitled"}`
10099
: fileName || "Untitled";
101100

102101
return {
103-
id: `${fileId}-${eventId || ts}`,
102+
id: `${fileId}-${ts}`,
104103
summary,
105104
ts,
106105
};
@@ -124,14 +123,15 @@ export default {
124123
},
125124
async processChange(file, headers) {
126125
const changes = this.getChanges(headers);
126+
const fileInfo = await this.googleDrive.getFile(file.id);
127127
if (this.includeLink) {
128-
file.file = await stashFile(file, this.googleDrive, this.dir);
128+
fileInfo.file = await stashFile(file, this.googleDrive, this.dir);
129129
}
130130
const eventToEmit = {
131-
file,
131+
file: fileInfo,
132132
...changes,
133133
};
134-
const meta = this.generateMeta(file, headers);
134+
const meta = this.generateMeta(fileInfo, headers);
135135
this.$emit(eventToEmit, meta);
136136
},
137137
async processChanges(changedFiles, headers) {

components/google_drive/sources/changes-to-specific-files/changes-to-specific-files.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import includes from "lodash/includes.js";
33
import { v4 as uuid } from "uuid";
44
import { MY_DRIVE_VALUE } from "../../common/constants.mjs";
55
import changesToSpecificFiles from "../changes-to-specific-files-shared-drive/changes-to-specific-files-shared-drive.mjs";
6+
import { ConfigurationError } from "@pipedream/platform";
67
import sampleEmit from "./test-event.mjs";
78

89
/**
@@ -15,12 +16,17 @@ export default {
1516
key: "google_drive-changes-to-specific-files",
1617
name: "Changes to Specific Files",
1718
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.",
18-
version: "0.3.0",
19+
version: "0.3.1",
1920
type: "source",
2021
// Dedupe events based on the "x-goog-message-number" header for the target channel:
2122
// https://developers.google.com/drive/api/v3/push#making-watch-requests
2223
dedupe: "unique",
2324
props: {
25+
infoAlert: {
26+
type: "alert",
27+
alertType: "info",
28+
content: "This source uses `files.watch` and supports up to 10 file subscriptions. To watch for changes to more than 10 files, use the **Changes to Files in Drive** source instead (uses `changes.watch`).",
29+
},
2430
...changesToSpecificFiles.props,
2531
drive: {
2632
type: "string",
@@ -50,6 +56,12 @@ export default {
5056
},
5157
hooks: {
5258
...changesToSpecificFiles.hooks,
59+
async deploy() {
60+
if (this.files.length > 10) {
61+
throw new ConfigurationError("This source only supports up to 10 files");
62+
}
63+
await changesToSpecificFiles.hooks.deploy.bind(this)();
64+
},
5365
async activate() {
5466
// Called when a component is created or updated. Handles all the logic
5567
// for starting and stopping watch notifications tied to the desired

components/google_drive/sources/common-dedupe-changes.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ You can change or disable this minimum interval using the prop \`Minimum Interva
1313
description: "How many minutes to wait until the same file can emit another event.\n\nIf set to `0`, this interval is disabled and all events will be emitted.",
1414
min: 0,
1515
max: 60,
16-
default: 1,
16+
default: 3,
1717
optional: true,
1818
},
1919
},

components/google_drive/sources/common-webhook.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ export default {
1010
props: {
1111
googleDrive,
1212
db: "$.service.db",
13-
http: "$.interface.http",
13+
http: {
14+
type: "$.interface.http",
15+
customResponse: true,
16+
},
1417
drive: {
1518
propDefinition: [
1619
googleDrive,
@@ -157,6 +160,10 @@ export default {
157160
this._setChannelID(newChannelID);
158161
this._setPageToken(newPageToken);
159162
return;
163+
} else {
164+
this.http.respond({
165+
status: 200,
166+
});
160167
}
161168

162169
const { headers } = event;

components/google_drive/sources/new-files-instant/new-files-instant.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111
key: "google_drive-new-files-instant",
1212
name: "New Files (Instant)",
1313
description: "Emit new event when a new file is added in your linked Google Drive",
14-
version: "0.2.0",
14+
version: "0.2.1",
1515
type: "source",
1616
dedupe: "unique",
1717
props: {

components/google_drive/sources/new-files-shared-drive/new-files-shared-drive.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
key: "google_drive-new-files-shared-drive",
88
name: "New Files (Shared Drive)",
99
description: "Emit new event when a new file is added in your shared Google Drive",
10-
version: "0.1.0",
10+
version: "0.1.1",
1111
type: "source",
1212
dedupe: "unique",
1313
props: {

components/google_drive/sources/new-or-modified-comments/new-or-modified-comments.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default {
1717
name: "New or Modified Comments (Instant)",
1818
description:
1919
"Emit new event when a comment is created or modified in the selected file",
20-
version: "1.0.9",
20+
version: "1.0.10",
2121
type: "source",
2222
// Dedupe events based on the "x-goog-message-number" header for the target channel:
2323
// https://developers.google.com/drive/api/v3/push#making-watch-requests

components/google_drive/sources/new-or-modified-files/new-or-modified-files.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default {
2525
key: "google_drive-new-or-modified-files",
2626
name: "New or Modified Files (Instant)",
2727
description: "Emit new event when a file in the selected Drive is created, modified or trashed.",
28-
version: "0.4.0",
28+
version: "0.4.1",
2929
type: "source",
3030
// Dedupe events based on the "x-goog-message-number" header for the target channel:
3131
// https://developers.google.com/drive/api/v3/push#making-watch-requests

0 commit comments

Comments
 (0)