Skip to content

Commit 6b29c93

Browse files
Google Drive - new files shared drive polling trigger (#15997)
* add polling source for shared drives * add alert to new files instant trigger * bump package.json
1 parent cdd0ddb commit 6b29c93

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
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": "0.8.10",
3+
"version": "0.8.11",
44
"description": "Pipedream Google_drive Components",
55
"main": "google_drive.app.mjs",
66
"keywords": [

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ export default {
1010
key: "google_drive-new-files-instant",
1111
name: "New Files (Instant)",
1212
description: "Emit new event when a new file is added in your linked Google Drive",
13-
version: "0.1.11",
13+
version: "0.1.12",
1414
type: "source",
1515
dedupe: "unique",
1616
props: {
1717
...common.props,
18+
alert: {
19+
type: "alert",
20+
content: "For shared drives, prefer to use [New Files (Shared Drive)](https://pipedream.com/apps/google-drive/triggers/new-files-shared-drive) instead. \
21+
It provides a more reliable way to track changes using polling. \
22+
Shared drive notifications may be delayed or incomplete, as they don't immediately reflect all changes made by other users. \
23+
For more details, see [Google's documentation](https://developers.google.com/drive/api/guides/about-changes#track_shared_drives).",
24+
},
1825
folders: {
1926
type: "string[]",
2027
label: "Folders",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import googleDrive from "../../google_drive.app.mjs";
2+
import sourceComponent from "../new-files-instant/new-files-instant.mjs";
3+
import sampleEmit from "../new-files-instant/test-event.mjs";
4+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
5+
6+
export default {
7+
key: "google_drive-new-files-shared-drive",
8+
name: "New Files (Shared Drive)",
9+
description: "Emit new event when a new file is added in your shared Google Drive",
10+
version: "0.0.1",
11+
type: "source",
12+
dedupe: "unique",
13+
props: {
14+
googleDrive,
15+
db: "$.service.db",
16+
timer: {
17+
label: "Polling interval",
18+
description: "Interval to poll the Google Drive API for new files",
19+
type: "$.interface.timer",
20+
default: {
21+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
22+
},
23+
},
24+
drive: {
25+
propDefinition: [
26+
googleDrive,
27+
"sharedDrive",
28+
],
29+
description: "Select a [Shared Drive](https://support.google.com/a/users/answer/9310351) from this list",
30+
optional: false,
31+
},
32+
folders: sourceComponent.props.folders,
33+
},
34+
hooks: {
35+
async deploy() {
36+
// Get initial page token for change tracking
37+
const startPageToken = await this.googleDrive.getPageToken(this.getDriveId());
38+
this._setPageToken(startPageToken);
39+
this._setLastFileCreatedTime(Date.now());
40+
41+
// Emit the most recent files
42+
await sourceComponent.hooks.deploy.bind(this)();
43+
},
44+
},
45+
methods: sourceComponent.methods,
46+
async run() {
47+
const pageToken = this._getPageToken();
48+
49+
const driveId = this.getDriveId();
50+
const changedFilesStream = this.googleDrive.listChanges(pageToken, driveId);
51+
for await (const changedFilesPage of changedFilesStream) {
52+
const { nextPageToken } = changedFilesPage;
53+
54+
// Process all the changed files retrieved from the current page
55+
await this.processChanges();
56+
57+
// After successfully processing the changed files, we store the page
58+
// token of the next page
59+
this._setPageToken(nextPageToken);
60+
}
61+
},
62+
sampleEmit,
63+
};

0 commit comments

Comments
 (0)