@activepieces/piece-google-drive 0.5.0 → 0.5.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@activepieces/piece-google-drive",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@sinclair/typebox": "^0.26.3",
|
|
6
6
|
"axios": "1.4.0",
|
|
@@ -9,11 +9,10 @@
|
|
|
9
9
|
"is-base64": "^1.1.0",
|
|
10
10
|
"mime-types": "^2.1.35",
|
|
11
11
|
"nanoid": "^3.3.4",
|
|
12
|
-
"object-sizeof": "^2.6.3",
|
|
13
12
|
"semver": "7.5.4",
|
|
14
13
|
"@activepieces/pieces-common": "0.2.2",
|
|
15
|
-
"@activepieces/pieces-framework": "0.6.
|
|
16
|
-
"@activepieces/shared": "0.
|
|
14
|
+
"@activepieces/pieces-framework": "0.6.15",
|
|
15
|
+
"@activepieces/shared": "0.8.0",
|
|
17
16
|
"tslib": "2.6.1"
|
|
18
17
|
},
|
|
19
18
|
"main": "./src/index.js",
|
package/src/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const create_new_text_file_1 = require("./lib/action/create-new-text-file");
|
|
|
7
7
|
const upload_file_1 = require("./lib/action/upload-file");
|
|
8
8
|
const new_file_1 = require("./lib/triggers/new-file");
|
|
9
9
|
const new_folder_1 = require("./lib/triggers/new-folder");
|
|
10
|
+
const read_file_1 = require("./lib/action/read-file");
|
|
10
11
|
exports.googleDriveAuth = pieces_framework_1.PieceAuth.OAuth2({
|
|
11
12
|
description: "",
|
|
12
13
|
authUrl: "https://accounts.google.com/o/oauth2/auth",
|
|
@@ -17,9 +18,9 @@ exports.googleDriveAuth = pieces_framework_1.PieceAuth.OAuth2({
|
|
|
17
18
|
exports.googleDrive = (0, pieces_framework_1.createPiece)({
|
|
18
19
|
minimumSupportedRelease: '0.5.0',
|
|
19
20
|
logoUrl: 'https://cdn.activepieces.com/pieces/google-drive.png',
|
|
20
|
-
actions: [create_new_folder_1.googleDriveCreateNewFolder, create_new_text_file_1.googleDriveCreateNewTextFile, upload_file_1.googleDriveUploadFile],
|
|
21
|
+
actions: [create_new_folder_1.googleDriveCreateNewFolder, create_new_text_file_1.googleDriveCreateNewTextFile, upload_file_1.googleDriveUploadFile, read_file_1.readFile],
|
|
21
22
|
displayName: "Google Drive",
|
|
22
|
-
authors: ['kanarelo', 'BastienMe', 'MoShizzle'],
|
|
23
|
+
authors: ['kanarelo', 'BastienMe', 'MoShizzle', 'Armangiau'],
|
|
23
24
|
triggers: [new_file_1.newFile, new_folder_1.newFolder],
|
|
24
25
|
auth: exports.googleDriveAuth,
|
|
25
26
|
});
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/pieces/google-drive/src/index.ts"],"names":[],"mappings":";;;AAAA,qEAAwE;AAExE,sEAA4E;AAC5E,4EAAiF;AACjF,0DAAiE;AACjE,sDAAkD;AAClD,0DAAsD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/pieces/google-drive/src/index.ts"],"names":[],"mappings":";;;AAAA,qEAAwE;AAExE,sEAA4E;AAC5E,4EAAiF;AACjF,0DAAiE;AACjE,sDAAkD;AAClD,0DAAsD;AACtD,sDAAkD;AAErC,QAAA,eAAe,GAAG,4BAAS,CAAC,MAAM,CAAC;IAC5C,WAAW,EAAE,EAAE;IACf,OAAO,EAAE,2CAA2C;IACpD,QAAQ,EAAE,qCAAqC;IAC/C,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,CAAC,uCAAuC,CAAC;CACnD,CAAC,CAAA;AAEW,QAAA,WAAW,GAAG,IAAA,8BAAW,EAAC;IACtC,uBAAuB,EAAE,OAAO;IAC7B,OAAO,EAAE,sDAAsD;IAClE,OAAO,EAAE,CAAC,8CAA0B,EAAE,mDAA4B,EAAE,mCAAqB,EAAE,oBAAQ,CAAC;IACpG,WAAW,EAAE,cAAc;IAC3B,OAAO,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,CAAC;IAC5D,QAAQ,EAAE,CAAC,kBAAO,EAAE,sBAAS,CAAC;IAC3B,IAAI,EAAE,uBAAe;CACxB,CAAC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const readFile: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").OAuth2Property<true, import("@activepieces/pieces-framework").OAuth2Props>, {
|
|
2
|
+
fileId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
+
fileName: import("@activepieces/pieces-framework").ShortTextProperty<false>;
|
|
4
|
+
}>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readFile = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const __1 = require("../..");
|
|
6
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
7
|
+
const mime_types_1 = require("mime-types");
|
|
8
|
+
exports.readFile = (0, pieces_framework_1.createAction)({
|
|
9
|
+
auth: __1.googleDriveAuth,
|
|
10
|
+
name: 'read-file',
|
|
11
|
+
displayName: 'Read file',
|
|
12
|
+
description: 'Read a selected file from google drive file',
|
|
13
|
+
props: {
|
|
14
|
+
fileId: pieces_framework_1.Property.ShortText({
|
|
15
|
+
displayName: 'File ID',
|
|
16
|
+
description: 'File ID comming from | New File -> id |',
|
|
17
|
+
required: true,
|
|
18
|
+
}),
|
|
19
|
+
fileName: pieces_framework_1.Property.ShortText({
|
|
20
|
+
displayName: 'Destination File name',
|
|
21
|
+
required: false,
|
|
22
|
+
}),
|
|
23
|
+
},
|
|
24
|
+
run: ({ auth, propsValue, files }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
let mimeType = (yield fetch(`https://www.googleapis.com/drive/v3/files/${propsValue.fileId}?fields=mimeType`, {
|
|
26
|
+
headers: {
|
|
27
|
+
Authorization: `Bearer ${auth.access_token}`,
|
|
28
|
+
},
|
|
29
|
+
}).then((res) => res.json()))['mimeType'];
|
|
30
|
+
const googledlCall = (url) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
const download = yield fetch(url, {
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: `Bearer ${auth.access_token}`,
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
.then((response) => response.ok ? response.blob() : Promise.reject(response))
|
|
37
|
+
.catch((error) => {
|
|
38
|
+
var _a;
|
|
39
|
+
return Promise.reject(new Error(`Error when download file:\n\tDownload file response: ${(_a = error.message) !== null && _a !== void 0 ? _a : error}`));
|
|
40
|
+
});
|
|
41
|
+
const extention = '.' + (0, mime_types_1.extension)(mimeType);
|
|
42
|
+
const srcFileName = propsValue.fileName;
|
|
43
|
+
const fileName = (srcFileName
|
|
44
|
+
? srcFileName.replace(new RegExp(extention + '$'), '')
|
|
45
|
+
: propsValue.fileId) + extention;
|
|
46
|
+
return files.write({
|
|
47
|
+
fileName,
|
|
48
|
+
data: Buffer.from(yield download.arrayBuffer()),
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
// the google drive API doesn't allowed downloading google documents but we can export them to office formats
|
|
52
|
+
if ([
|
|
53
|
+
'application/vnd.google-apps.document',
|
|
54
|
+
'application/vnd.google-apps.spreadsheet',
|
|
55
|
+
'application/vnd.google-apps.presentation',
|
|
56
|
+
].includes(mimeType)) {
|
|
57
|
+
switch (mimeType) {
|
|
58
|
+
case 'application/vnd.google-apps.document':
|
|
59
|
+
mimeType =
|
|
60
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
|
61
|
+
break;
|
|
62
|
+
case 'application/vnd.google-apps.spreadsheet':
|
|
63
|
+
mimeType =
|
|
64
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
65
|
+
break;
|
|
66
|
+
case 'application/vnd.google-apps.presentation':
|
|
67
|
+
mimeType =
|
|
68
|
+
'application/vnd.openxmlformats-officedocument.presentationml.presentation';
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
return yield googledlCall(`https://www.googleapis.com/drive/v3/files/${propsValue.fileId}/export?mimeType=${mimeType}`);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return yield googledlCall(`https://www.googleapis.com/drive/v3/files/${propsValue.fileId}?alt=media`);
|
|
75
|
+
}
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=read-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-file.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/google-drive/src/lib/action/read-file.ts"],"names":[],"mappings":";;;;AAAA,6BAAwC;AACxC,qEAAwE;AACxE,2CAAuC;AAE1B,QAAA,QAAQ,GAAG,IAAA,+BAAY,EAAC;IACnC,IAAI,EAAE,mBAAe;IACrB,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,6CAA6C;IAC1D,KAAK,EAAE;QACL,MAAM,EAAE,2BAAQ,CAAC,SAAS,CAAC;YACzB,WAAW,EAAE,SAAS;YACtB,WAAW,EAAE,yCAAyC;YACtD,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,QAAQ,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC3B,WAAW,EAAE,uBAAuB;YACpC,QAAQ,EAAE,KAAK;SAChB,CAAC;KACH;IACD,GAAG,EAAE,CAAO,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,EAAE;QAEzC,IAAI,QAAQ,GAAG,CACb,MAAM,KAAK,CACT,6CAA6C,UAAU,CAAC,MAAM,kBAAkB,EAChF;YACE,OAAO,EAAE;gBACP,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