@pipedream/google_drive 0.4.3 → 0.4.5

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.
@@ -4,13 +4,16 @@ import {
4
4
  toSingleLineString,
5
5
  } from "../../utils.mjs";
6
6
 
7
- import { GOOGLE_DRIVE_FOLDER_MIME_TYPE } from "../../constants.mjs";
7
+ import {
8
+ MY_DRIVE_VALUE,
9
+ GOOGLE_DRIVE_FOLDER_MIME_TYPE,
10
+ } from "../../constants.mjs";
8
11
 
9
12
  export default {
10
13
  key: "google_drive-create-folder",
11
14
  name: "Create Folder",
12
15
  description: "Create a new empty folder. [See the docs](https://developers.google.com/drive/api/v3/reference/files/create) for more information",
13
- version: "0.0.6",
16
+ version: "0.0.7",
14
17
  type: "action",
15
18
  props: {
16
19
  googleDrive,
@@ -29,8 +32,10 @@ export default {
29
32
  drive: c.drive,
30
33
  }),
31
34
  ],
32
- description:
33
- "Select a folder in which to place the new folder. If not specified, the folder will be placed directly in the drive's top-level folder.",
35
+ description: toSingleLineString(`
36
+ Select a folder in which to place the new folder.
37
+ If not specified, the folder will be placed directly in the drive's top-level folder.
38
+ `),
34
39
  optional: true,
35
40
  },
36
41
  name: {
@@ -42,42 +47,46 @@ export default {
42
47
  description: "The name of the new folder",
43
48
  optional: true,
44
49
  },
45
- createIfExists: {
50
+ createIfUnique: {
46
51
  type: "boolean",
47
- label: "Create If Exists?",
52
+ label: "Create Only If Filename Is Unique?",
48
53
  description: toSingleLineString(`
49
- If the folder already exists and is not in the trash, should we create it? This option defaults to 'true' for
50
- backwards compatibility and to be consistent with default Google Drive behavior.
54
+ If the folder already exists, **do not** create. This option defaults to \`false\` for
55
+ backwards compatibility and to be consistent with default Google Drive behavior.
51
56
  `),
52
57
  optional: true,
53
- default: true,
58
+ default: false,
54
59
  },
55
60
  },
56
61
  async run({ $ }) {
57
62
  const {
63
+ drive,
58
64
  parentId,
59
65
  name,
60
- createIfExists,
66
+ createIfUnique,
61
67
  } = this;
62
- let folder;
63
- if (createIfExists == false) {//checking "false" because if this optional prop may not be given
64
- const folders = (await this.googleDrive.listFilesInPage(null, getListFilesOpts(this.drive, {
65
- q: `mimeType = '${GOOGLE_DRIVE_FOLDER_MIME_TYPE}' and name contains '${name}' and trashed=false`.trim(),
66
- }))).files;
67
- for (let f of folders) {
68
- if (f.name == name) {
69
- folder = f;
70
- break;
71
- }
68
+
69
+ const driveId = await this.googleDrive.getDriveId(drive);
70
+
71
+ if (createIfUnique) {
72
+ let q = `mimeType = '${GOOGLE_DRIVE_FOLDER_MIME_TYPE}' and name = '${name}' and trashed = false`;
73
+ if (parentId) {
74
+ q += ` and '${parentId}' in parents`;
75
+ } else if (drive === MY_DRIVE_VALUE) {
76
+ q += " and 'root' in parents";
77
+ } else {
78
+ q += ` and '${driveId}' in parents`;
72
79
  }
73
- if (folder) {
74
- $.export("$summary", "Found existing folder, therefore not creating folder. Returning found folder.");
75
- const folderDetails = await this.googleDrive.getFile(folder.id);
80
+ const folders = (await this.googleDrive.listFilesInPage(null, getListFilesOpts(drive, {
81
+ q,
82
+ }))).files;
76
83
 
77
- return folderDetails;
84
+ if (folders.length) {
85
+ $.export("$summary", "Found existing folder, therefore not creating folder. Returning found folder.");
86
+ return this.googleDrive.getFile(folders[0].id);
78
87
  }
79
88
  }
80
- const driveId = this.googleDrive.getDriveId(this.drive);
89
+
81
90
  const resp = await this.googleDrive.createFolder({
82
91
  name,
83
92
  parentId,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_drive-list-files",
6
6
  name: "List Files",
7
7
  description: "List files from a specific folder. [See the docs](https://developers.google.com/drive/api/v3/reference/files/list) for more information",
8
- version: "0.0.1",
8
+ version: "0.0.2",
9
9
  type: "action",
10
10
  props: {
11
11
  googleDrive,
@@ -34,12 +34,25 @@ export default {
34
34
  description: "The paths of the fields you want included in the response. If not specified, the response includes a default set of fields specific to this method. For development you can use the special value `*` to return all fields, but you'll achieve greater performance by only selecting the fields you need.\n\n**eg:** `files(id,mimeType,name,webContentLink,webViewLink)`",
35
35
  optional: true,
36
36
  },
37
+ filterText: {
38
+ label: "Filter Text",
39
+ description: "Filter by file name that contains a specific text",
40
+ type: "string",
41
+ optional: true,
42
+ },
37
43
  },
38
44
  async run({ $ }) {
39
- const opts = getListFilesOpts(this.drive);
45
+ const opts = getListFilesOpts(this.drive, {
46
+ q: "",
47
+ });
40
48
  if (this.folderId) {
41
49
  opts.q = `"${this.folderId}" in parents`;
42
50
  }
51
+ if (this.filterText) {
52
+ opts.q += `${opts.q
53
+ ? " AND "
54
+ : ""}name contains '${this.filterText}'`;
55
+ }
43
56
  if (this.fields) {
44
57
  opts.fields = this.fields;
45
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/google_drive",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "description": "Pipedream Google_drive Components",
5
5
  "main": "google_drive.app.mjs",
6
6
  "keywords": [