@pipedream/google_drive 0.6.14 → 0.6.16

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.
@@ -10,7 +10,7 @@ export default {
10
10
  key: "google_drive-upload-file",
11
11
  name: "Upload File",
12
12
  description: "Copy an existing file to Google Drive. [See the docs](https://developers.google.com/drive/api/v3/manage-uploads) for more information",
13
- version: "0.1.2",
13
+ version: "0.1.3",
14
14
  type: "action",
15
15
  props: {
16
16
  googleDrive,
@@ -69,26 +69,14 @@ export default {
69
69
  default: GOOGLE_DRIVE_UPLOAD_TYPE_MULTIPART,
70
70
  optional: true,
71
71
  },
72
- replaceFile: {
73
- type: "boolean",
74
- label: "Replace File",
75
- description: "Whether should replace file case it exists, default: `false`",
72
+ fileId: {
73
+ propDefinition: [
74
+ googleDrive,
75
+ "fileId",
76
+ ],
77
+ label: "File to replace",
78
+ description: "Id of the file to replace. Leave it empty to upload a new file.",
76
79
  optional: true,
77
- default: false,
78
- },
79
- },
80
- methods: {
81
- async getFileIdForReplace(filename, parentId) {
82
- if (this.replaceFile) {
83
- const { files } = await this.googleDrive.listFilesInPage(null, {
84
- q: `name = '${filename}' and '${parentId || "root"}' in parents and trashed = false`,
85
- fields: "files/id,files/name,files/parents",
86
- });
87
- if (files.length) {
88
- return files[0].id;
89
- }
90
- }
91
- return null;
92
80
  },
93
81
  },
94
82
  async run({ $ }) {
@@ -106,7 +94,6 @@ export default {
106
94
  const driveId = this.googleDrive.getDriveId(this.drive);
107
95
 
108
96
  const filename = name || path.basename(fileUrl || filePath);
109
- const fileId = await this.getFileIdForReplace(filename, parentId);
110
97
 
111
98
  const file = await getFileStream({
112
99
  $,
@@ -116,12 +103,12 @@ export default {
116
103
  console.log(`Upload type: ${uploadType}.`);
117
104
 
118
105
  let result = null;
119
- if (fileId) {
120
- await this.googleDrive.updateFileMedia(fileId, file, omitEmptyStringValues({
106
+ if (this.fileId) {
107
+ await this.googleDrive.updateFileMedia(this.fileId, file, omitEmptyStringValues({
121
108
  mimeType,
122
109
  uploadType,
123
110
  }));
124
- result = await this.googleDrive.updateFile(fileId, omitEmptyStringValues({
111
+ result = await this.googleDrive.updateFile(this.fileId, omitEmptyStringValues({
125
112
  name: filename,
126
113
  mimeType,
127
114
  uploadType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/google_drive",
3
- "version": "0.6.14",
3
+ "version": "0.6.16",
4
4
  "description": "Pipedream Google_drive Components",
5
5
  "main": "google_drive.app.mjs",
6
6
  "keywords": [
@@ -21,11 +21,38 @@ export default {
21
21
  key: "google_drive-new-or-modified-files",
22
22
  name: "New or Modified Files",
23
23
  description: "Emit new event any time any file in your linked Google Drive is added, modified, or deleted",
24
- version: "0.1.3",
24
+ version: "0.2.0",
25
25
  type: "source",
26
26
  // Dedupe events based on the "x-goog-message-number" header for the target channel:
27
27
  // https://developers.google.com/drive/api/v3/push#making-watch-requests
28
28
  dedupe: "unique",
29
+ props: {
30
+ ...common.props,
31
+ folders: {
32
+ type: "string[]",
33
+ label: "Folders",
34
+ description:
35
+ "(Optional) The folders you want to watch for changes. Leave blank to watch for any new file in the Drive.",
36
+ optional: true,
37
+ default: [],
38
+ options({ prevContext }) {
39
+ const { nextPageToken } = prevContext;
40
+ const baseOpts = {
41
+ q: "mimeType = 'application/vnd.google-apps.folder' and trashed = false",
42
+ };
43
+ const opts = this.isMyDrive()
44
+ ? baseOpts
45
+ : {
46
+ ...baseOpts,
47
+ corpora: "drive",
48
+ driveId: this.getDriveId(),
49
+ includeItemsFromAllDrives: true,
50
+ supportsAllDrives: true,
51
+ };
52
+ return this.googleDrive.listFilesOptions(nextPageToken, opts);
53
+ },
54
+ },
55
+ },
29
56
  hooks: {
30
57
  async deploy() {
31
58
  const daysAgo = new Date();
@@ -45,6 +72,15 @@ export default {
45
72
  },
46
73
  methods: {
47
74
  ...common.methods,
75
+ shouldProcess(file) {
76
+ if (file.mimeType !== "application/vnd.google-apps.folder") {
77
+ const watchedFolders = new Set(this.folders);
78
+ return (
79
+ watchedFolders.size == 0 ||
80
+ (file.parents && file.parents.some((p) => watchedFolders.has(p)))
81
+ );
82
+ }
83
+ },
48
84
  getUpdateTypes() {
49
85
  return [
50
86
  GOOGLE_DRIVE_NOTIFICATION_ADD,
@@ -86,6 +122,17 @@ export default {
86
122
  const changes = await this.getChanges(headers);
87
123
 
88
124
  for (const file of changedFiles) {
125
+ file.parents = (await this.googleDrive.getFile(file.id, {
126
+ fields: "parents",
127
+ })).parents;
128
+
129
+ console.log(file); // see what file was processed
130
+
131
+ if (!this.shouldProcess(file)) {
132
+ console.log(`Skipping file ${file.name}`);
133
+ continue;
134
+ }
135
+
89
136
  const eventToEmit = {
90
137
  file,
91
138
  ...changes,