@pipedream/google_drive 0.4.7 → 0.4.9
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,21 +1,14 @@
|
|
|
1
1
|
import googleDrive from "../../google_drive.app.mjs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import {
|
|
4
|
-
getFileStream,
|
|
5
|
-
streamToBuffer,
|
|
6
|
-
byteToMB,
|
|
7
|
-
} from "../../utils.mjs";
|
|
3
|
+
import { getFileStream } from "../../utils.mjs";
|
|
8
4
|
import { omitEmptyStringValues } from "../../utils.mjs";
|
|
9
|
-
import {
|
|
10
|
-
GOOGLE_DRIVE_UPLOAD_TYPE_MEDIA,
|
|
11
|
-
GOOGLE_DRIVE_UPLOAD_TYPE_RESUMABLE,
|
|
12
|
-
} from "../../constants.mjs";
|
|
5
|
+
import { GOOGLE_DRIVE_UPLOAD_TYPE_MULTIPART } from "../../constants.mjs";
|
|
13
6
|
|
|
14
7
|
export default {
|
|
15
8
|
key: "google_drive-upload-file",
|
|
16
9
|
name: "Upload File",
|
|
17
10
|
description: "Copy an existing file to Google Drive. [See the docs](https://developers.google.com/drive/api/v3/manage-uploads) for more information",
|
|
18
|
-
version: "0.0.
|
|
11
|
+
version: "0.0.7",
|
|
19
12
|
type: "action",
|
|
20
13
|
props: {
|
|
21
14
|
googleDrive,
|
|
@@ -71,6 +64,7 @@ export default {
|
|
|
71
64
|
googleDrive,
|
|
72
65
|
"uploadType",
|
|
73
66
|
],
|
|
67
|
+
default: GOOGLE_DRIVE_UPLOAD_TYPE_MULTIPART,
|
|
74
68
|
optional: true,
|
|
75
69
|
},
|
|
76
70
|
},
|
|
@@ -92,20 +86,7 @@ export default {
|
|
|
92
86
|
fileUrl,
|
|
93
87
|
filePath,
|
|
94
88
|
});
|
|
95
|
-
|
|
96
|
-
try {
|
|
97
|
-
const fileBuffer = await streamToBuffer(file);
|
|
98
|
-
const bufferSize = byteToMB(Buffer.byteLength(fileBuffer));
|
|
99
|
-
uploadType = bufferSize > 5
|
|
100
|
-
? GOOGLE_DRIVE_UPLOAD_TYPE_RESUMABLE
|
|
101
|
-
: GOOGLE_DRIVE_UPLOAD_TYPE_MEDIA;
|
|
102
|
-
console.log(`Upload type: ${uploadType}`);
|
|
103
|
-
} catch (err) {
|
|
104
|
-
console.log(err);
|
|
105
|
-
uploadType = "media";
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
console.log(`Upload type: ${uploadType}`);
|
|
89
|
+
console.log(`Upload type: ${uploadType}.`);
|
|
109
90
|
const resp = await this.googleDrive.createFile(omitEmptyStringValues({
|
|
110
91
|
file,
|
|
111
92
|
mimeType,
|
package/package.json
CHANGED
|
@@ -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
|
+
};
|