@pipedream/google_drive 0.10.1 → 1.0.1

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.
@@ -1,39 +1,15 @@
1
1
  import googleDrive from "../../google_drive.app.mjs";
2
- import {
3
- toSingleLineString,
4
- getFileStream,
5
- } from "../../common/utils.mjs";
6
- import { additionalProps } from "../../common/filePathOrUrl.mjs";
2
+ import { toSingleLineString } from "../../common/utils.mjs";
3
+ import { getFileStream } from "@pipedream/platform";
7
4
 
8
5
  export default {
9
6
  key: "google_drive-update-file",
10
7
  name: "Update File",
11
8
  description: "Update a file's metadata and/or content. [See the documentation](https://developers.google.com/drive/api/v3/reference/files/update) for more information",
12
- version: "1.0.2",
9
+ version: "2.0.0",
13
10
  type: "action",
14
- additionalProps,
15
11
  props: {
16
12
  googleDrive,
17
- updateType: {
18
- type: "string",
19
- label: "Update Type",
20
- description: "Whether to update content or metadata only",
21
- options: [
22
- {
23
- label: "Upload content from File URL",
24
- value: "File URL",
25
- },
26
- {
27
- label: "Upload content from File Path",
28
- value: "File Path",
29
- },
30
- {
31
- label: "Update file metadata only",
32
- value: "File Metadata",
33
- },
34
- ],
35
- reloadProps: true,
36
- },
37
13
  drive: {
38
14
  propDefinition: [
39
15
  googleDrive,
@@ -51,27 +27,12 @@ export default {
51
27
  ],
52
28
  description: "The file to update",
53
29
  },
54
- fileUrl: {
55
- propDefinition: [
56
- googleDrive,
57
- "fileUrl",
58
- ],
59
- description: "The URL of the file to use to update content",
60
- optional: false,
61
- hidden: true,
62
- },
63
30
  filePath: {
64
31
  propDefinition: [
65
32
  googleDrive,
66
33
  "filePath",
67
34
  ],
68
- description: toSingleLineString(`
69
- The path to the file saved to the [\`/tmp\`
70
- directory](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory)
71
- (e.g., \`/tmp/myFile.csv\`) with which to update content
72
- `),
73
- optional: false,
74
- hidden: true,
35
+ optional: true,
75
36
  },
76
37
  name: {
77
38
  propDefinition: [
@@ -139,7 +100,6 @@ export default {
139
100
  async run({ $ }) {
140
101
  const {
141
102
  fileId,
142
- fileUrl,
143
103
  filePath,
144
104
  name,
145
105
  mimeType,
@@ -149,26 +109,13 @@ export default {
149
109
  ocrLanguage,
150
110
  useContentAsIndexableText,
151
111
  advanced,
152
- updateType,
153
112
  } = this;
154
113
 
155
- let fileStream;
156
- if (updateType === "File URL") {
157
- fileStream = await getFileStream({
158
- $,
159
- fileUrl,
160
- });
161
- } else if (updateType === "File Path") {
162
- fileStream = await getFileStream({
163
- $,
164
- filePath,
165
- });
166
- }
167
-
168
114
  // Update file content, if set, separately from metadata to prevent
169
115
  // multipart upload, which `google-apis-nodejs-client` doesn't seem to
170
116
  // support for [files.update](https://bit.ly/3lP5sWn)
171
- if (fileStream) {
117
+ if (filePath) {
118
+ const fileStream = await getFileStream(filePath);
172
119
  await this.googleDrive.updateFileMedia(fileId, fileStream, {
173
120
  mimeType,
174
121
  });
@@ -1,19 +1,18 @@
1
1
  import googleDrive from "../../google_drive.app.mjs";
2
- import path from "path";
3
2
  import {
4
3
  omitEmptyStringValues,
5
4
  parseObjectEntries,
6
5
  } from "../../common/utils.mjs";
7
6
  import { GOOGLE_DRIVE_UPLOAD_TYPE_MULTIPART } from "../../common/constants.mjs";
8
7
  import {
9
- getFileStream, ConfigurationError,
8
+ getFileStreamAndMetadata, ConfigurationError,
10
9
  } from "@pipedream/platform";
11
10
 
12
11
  export default {
13
12
  key: "google_drive-upload-file",
14
13
  name: "Upload File",
15
14
  description: "Upload a file to Google Drive. [See the documentation](https://developers.google.com/drive/api/v3/manage-uploads) for more information",
16
- version: "1.1.0",
15
+ version: "2.0.1",
17
16
  type: "action",
18
17
  props: {
19
18
  googleDrive,
@@ -36,10 +35,10 @@ export default {
36
35
  "The folder you want to upload the file to. If not specified, the file will be placed directly in the drive's top-level folder.",
37
36
  optional: true,
38
37
  },
39
- file: {
38
+ filePath: {
40
39
  type: "string",
41
- label: "File",
42
- description: "Provide either a file URL or a path to a file in the /tmp directory (for example, /tmp/myFlie.pdf).",
40
+ label: "File Path or URL",
41
+ description: "Provide either a file URL or a path to a file in the /tmp directory (for example, /tmp/myFile.pdf).",
43
42
  },
44
43
  name: {
45
44
  propDefinition: [
@@ -84,16 +83,18 @@ export default {
84
83
  async run({ $ }) {
85
84
  const {
86
85
  parentId,
86
+ filePath,
87
87
  name,
88
88
  mimeType,
89
89
  } = this;
90
90
  let { uploadType } = this;
91
91
  const driveId = this.googleDrive.getDriveId(this.drive);
92
92
 
93
- const filename = name || path.basename(this.file);
93
+ const {
94
+ stream: file, metadata: fileMetadata,
95
+ } = await getFileStreamAndMetadata(filePath);
94
96
 
95
- const file = await getFileStream(this.file);
96
- console.log(`Upload type: ${uploadType}.`);
97
+ const filename = name || fileMetadata.name;
97
98
 
98
99
  const metadata = this.metadata
99
100
  ? parseObjectEntries(this.metadata)
package/common/utils.mjs CHANGED
@@ -1,7 +1,4 @@
1
- import fs from "fs";
2
- import {
3
- axios, ConfigurationError,
4
- } from "@pipedream/platform";
1
+ import { ConfigurationError } from "@pipedream/platform";
5
2
  import {
6
3
  MY_DRIVE_VALUE,
7
4
  LEGACY_MY_DRIVE_VALUE,
@@ -60,34 +57,6 @@ function getListFilesOpts(drive, baseOpts = {}) {
60
57
  return opts;
61
58
  }
62
59
 
63
- /**
64
- * Returns a file stream from a file URL or file path to be used in Google Drive
65
- * API calls
66
- *
67
- * @param {Object} opts - an object containing options for getting a file stream
68
- * @param {String} opts.fileUrl - the url of a file to download to a Readable
69
- * stream
70
- * @param {String} opts.filePath - the path to a file from which to create a
71
- * Readable stream
72
- * @returns {stream.Readable} a Readable stream from the file URL or file path
73
- */
74
- async function getFileStream({
75
- fileUrl, filePath,
76
- }) {
77
- if (fileUrl) {
78
- try {
79
- return await axios(this, {
80
- url: fileUrl,
81
- method: "GET",
82
- responseType: "stream",
83
- });
84
- } catch (e) {
85
- throw new Error(`Status ${e.response.status} ${e.response.statusText}. ${e.message}`);
86
- }
87
- }
88
- return fs.createReadStream(filePath);
89
- }
90
-
91
60
  function streamToBuffer(stream) {
92
61
  return new Promise((resolve, reject) => {
93
62
  const chunks = [];
@@ -294,7 +263,6 @@ export {
294
263
  isMyDrive,
295
264
  getDriveId,
296
265
  getListFilesOpts,
297
- getFileStream,
298
266
  omitEmptyStringValues,
299
267
  toSingleLineString,
300
268
  buildFilePaths,
@@ -155,24 +155,10 @@ export default {
155
155
  optional: true,
156
156
  default: false,
157
157
  },
158
- fileUrl: {
159
- type: "string",
160
- label: "File URL",
161
- description: toSingleLineString(`
162
- The URL of the file you want to upload to Google Drive. Must specify either **File URL**
163
- or **File Path**.
164
- `),
165
- optional: true,
166
- },
167
158
  filePath: {
168
159
  type: "string",
169
- label: "File Path",
170
- description: toSingleLineString(`
171
- The path to the file saved to the [\`/tmp\`
172
- directory](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory)
173
- (e.g. \`/tmp/myFile.csv\`). Must specify either **File URL** or **File Path**.
174
- `),
175
- optional: true,
160
+ label: "File Path or URL",
161
+ description: "The file content to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
176
162
  },
177
163
  fileName: {
178
164
  type: "string",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/google_drive",
3
- "version": "0.10.1",
3
+ "version": "1.0.1",
4
4
  "description": "Pipedream Google_drive Components",
5
5
  "main": "google_drive.app.mjs",
6
6
  "keywords": [
@@ -1,27 +0,0 @@
1
- export const updateType = {
2
- type: "string",
3
- label: "Use File URL or File Path",
4
- description: "Whether to upload a file from a URL or from the `/tmp` folder",
5
- options: [
6
- "File URL",
7
- "File Path",
8
- ],
9
- reloadProps: true,
10
- };
11
-
12
- export async function additionalProps(previousProps) {
13
- const { updateType } = this;
14
-
15
- if (updateType === "File URL") {
16
- previousProps.fileUrl.hidden = false;
17
- previousProps.filePath.hidden = true;
18
- } else if (updateType === "File Path") {
19
- previousProps.fileUrl.hidden = true;
20
- previousProps.filePath.hidden = false;
21
- } else {
22
- previousProps.fileUrl.hidden = true;
23
- previousProps.filePath.hidden = true;
24
- }
25
-
26
- return {};
27
- }