@pipedream/google_drive 0.4.7 → 0.4.8

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.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "Pipedream Google_drive Components",
5
5
  "main": "google_drive.app.mjs",
6
6
  "keywords": [
@@ -0,0 +1,72 @@
1
+ import newFilesInstant from "../new-files-instant/new-files-instant.mjs";
2
+
3
+ export default {
4
+ ...newFilesInstant,
5
+ key: "google_drive-new-spreadsheet",
6
+ type: "source",
7
+ name: "New Spreadsheet (Instant)",
8
+ description: "Emit new event each time a new spreadsheet is created in a drive.",
9
+ version: "0.0.1",
10
+ props: {
11
+ googleDrive: newFilesInstant.props.googleDrive,
12
+ db: newFilesInstant.props.db,
13
+ http: newFilesInstant.props.http,
14
+ drive: newFilesInstant.props.drive,
15
+ timer: newFilesInstant.props.timer,
16
+ folders: newFilesInstant.props.folders,
17
+ },
18
+ hooks: {
19
+ ...newFilesInstant.hooks,
20
+ async deploy() {
21
+ // Emit sample records on the first run
22
+ const spreadsheets = await this.getSpreadsheets(10);
23
+ for (const fileInfo of spreadsheets) {
24
+ const createdTime = Date.parse(fileInfo.createdTime);
25
+ this.$emit(fileInfo, {
26
+ summary: `New File: ${fileInfo.name}`,
27
+ id: fileInfo.id,
28
+ ts: createdTime,
29
+ });
30
+ }
31
+ },
32
+ },
33
+ methods: {
34
+ ...newFilesInstant.methods,
35
+ shouldProcess(file) {
36
+ return (
37
+ file.mimeType.includes("spreadsheet") &&
38
+ newFilesInstant.methods.shouldProcess.bind(this)(file)
39
+ );
40
+ },
41
+ getSpreadsheetsFromFolderOpts(folderId) {
42
+ const mimeQuery = "mimeType = 'application/vnd.google-apps.spreadsheet'";
43
+ let opts = {
44
+ q: `${mimeQuery} and parents in '${folderId}' and trashed = false`,
45
+ };
46
+ if (!this.isMyDrive()) {
47
+ opts = {
48
+ corpora: "drive",
49
+ driveId: this.getDriveId(),
50
+ includeItemsFromAllDrives: true,
51
+ supportsAllDrives: true,
52
+ ...opts,
53
+ };
54
+ }
55
+ return opts;
56
+ },
57
+ async getSpreadsheets(limit) {
58
+ const spreadsheets = [];
59
+ const foldersIds = this.folders;
60
+ for (const folderId of foldersIds) {
61
+ const opts = this.getSpreadsheetsFromFolderOpts(folderId);
62
+ const filesWrapper = await this.googleDrive.listFilesInPage(null, opts);
63
+ for (const file of filesWrapper.files) {
64
+ const fileInfo = await this.googleDrive.getFile(file.id);
65
+ spreadsheets.push(fileInfo);
66
+ if (spreadsheets.length >= limit) { return spreadsheets; }
67
+ }
68
+ }
69
+ return spreadsheets;
70
+ },
71
+ },
72
+ };