@pipedream/google_drive 0.6.10 → 0.6.11

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.1",
13
+ version: "0.1.2",
14
14
  type: "action",
15
15
  props: {
16
16
  googleDrive,
@@ -69,6 +69,27 @@ 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`",
76
+ 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
+ },
72
93
  },
73
94
  async run({ $ }) {
74
95
  const {
@@ -83,21 +104,40 @@ export default {
83
104
  throw new Error("One of File URL and File Path is required.");
84
105
  }
85
106
  const driveId = this.googleDrive.getDriveId(this.drive);
107
+
108
+ const filename = name || path.basename(fileUrl || filePath);
109
+ const fileId = await this.getFileIdForReplace(filename, parentId);
110
+
86
111
  const file = await getFileStream({
87
112
  $,
88
113
  fileUrl,
89
114
  filePath,
90
115
  });
91
116
  console.log(`Upload type: ${uploadType}.`);
92
- const resp = await this.googleDrive.createFile(omitEmptyStringValues({
93
- file,
94
- mimeType,
95
- name: name || path.basename(fileUrl || filePath),
96
- parentId,
97
- driveId,
98
- uploadType,
99
- }));
100
- $.export("$summary", `Successfully uploaded a new file, "${resp.name}"`);
101
- return resp;
117
+
118
+ let result = null;
119
+ if (fileId) {
120
+ await this.googleDrive.updateFileMedia(fileId, file, omitEmptyStringValues({
121
+ mimeType,
122
+ uploadType,
123
+ }));
124
+ result = await this.googleDrive.updateFile(fileId, omitEmptyStringValues({
125
+ name: filename,
126
+ mimeType,
127
+ uploadType,
128
+ }));
129
+ $.export("$summary", `Successfully updated file, "${result.name}"`);
130
+ } else {
131
+ result = await this.googleDrive.createFile(omitEmptyStringValues({
132
+ file,
133
+ mimeType,
134
+ name: filename,
135
+ parentId,
136
+ driveId,
137
+ uploadType,
138
+ }));
139
+ $.export("$summary", `Successfully uploaded a new file, "${result.name}"`);
140
+ }
141
+ return result;
102
142
  },
103
143
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/google_drive",
3
- "version": "0.6.10",
3
+ "version": "0.6.11",
4
4
  "description": "Pipedream Google_drive Components",
5
5
  "main": "google_drive.app.mjs",
6
6
  "keywords": [