@guayaba/workflow-piece-google-drive 0.7.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.
- package/.babelrc +3 -0
- package/.eslintrc.json +18 -0
- package/README.md +5 -0
- package/assets/logo.png +0 -0
- package/package.json +28 -0
- package/src/i18n/ca.json +125 -0
- package/src/i18n/de.json +136 -0
- package/src/i18n/es.json +136 -0
- package/src/i18n/fr.json +136 -0
- package/src/i18n/hi.json +125 -0
- package/src/i18n/id.json +125 -0
- package/src/i18n/ja.json +136 -0
- package/src/i18n/nl.json +136 -0
- package/src/i18n/pt.json +136 -0
- package/src/i18n/ru.json +127 -0
- package/src/i18n/translation.json +137 -0
- package/src/i18n/vi.json +127 -0
- package/src/i18n/zh.json +136 -0
- package/src/index.ts +74 -0
- package/src/lib/action/add-permission.action.ts +78 -0
- package/src/lib/action/create-new-folder.ts +38 -0
- package/src/lib/action/create-new-text-file.ts +89 -0
- package/src/lib/action/delete-file.ts +31 -0
- package/src/lib/action/delete-permission.action.ts +80 -0
- package/src/lib/action/duplicate-file.action.ts +78 -0
- package/src/lib/action/get-file-by-id.ts +34 -0
- package/src/lib/action/list-files.action.ts +209 -0
- package/src/lib/action/move-file.ts +44 -0
- package/src/lib/action/read-file.ts +24 -0
- package/src/lib/action/save-file-as-pdf.action.ts +72 -0
- package/src/lib/action/search-folder-or-file.action.ts +108 -0
- package/src/lib/action/send-to-trash.ts +34 -0
- package/src/lib/action/set-public-access.ts +64 -0
- package/src/lib/action/upload-file.ts +72 -0
- package/src/lib/auth.ts +80 -0
- package/src/lib/common/get-file-content.ts +109 -0
- package/src/lib/common/index.ts +179 -0
- package/src/lib/triggers/new-file.ts +115 -0
- package/src/lib/triggers/new-folder.ts +74 -0
- package/tsconfig.json +16 -0
- package/tsconfig.lib.json +15 -0
package/src/i18n/zh.json
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Cloud storage and file backup": "Cloud storage and file backup",
|
|
3
|
+
"Create new folder": "Create new folder",
|
|
4
|
+
"Create new file": "Create new file",
|
|
5
|
+
"Upload file": "Upload file",
|
|
6
|
+
"Read File Content": "Read File Content",
|
|
7
|
+
"Get File Information": "Get File Information",
|
|
8
|
+
"List files": "List files",
|
|
9
|
+
"Search": "Search",
|
|
10
|
+
"Duplicate File": "Duplicate File",
|
|
11
|
+
"Save Document as PDF": "Save Document as PDF",
|
|
12
|
+
"Update permissions": "Update permissions",
|
|
13
|
+
"Delete permissions": "Delete permissions",
|
|
14
|
+
"Set public access": "Set public access",
|
|
15
|
+
"Move File": "Move File",
|
|
16
|
+
"Delete file": "Delete file",
|
|
17
|
+
"Trash file": "Trash file",
|
|
18
|
+
"Custom API Call": "自定义 API 呼叫",
|
|
19
|
+
"Create a new empty folder in your Google Drive": "Create a new empty folder in your Google Drive",
|
|
20
|
+
"Create a new text file in your Google Drive from text": "Create a new text file in your Google Drive from text",
|
|
21
|
+
"Upload a file in your Google Drive": "Upload a file in your Google Drive",
|
|
22
|
+
"Read a selected file from google drive file": "Read a selected file from google drive file",
|
|
23
|
+
"Get a file folder for files/sub-folders": "Get a file folder for files/sub-folders",
|
|
24
|
+
"List files from a Google Drive folder": "List files from a Google Drive folder",
|
|
25
|
+
"Search a Google Drive folder for files/sub-folders": "Search a Google Drive folder for files/sub-folders",
|
|
26
|
+
"Duplicate a file from Google Drive. Returns the new file ID.": "Duplicate a file from Google Drive. Returns the new file ID.",
|
|
27
|
+
"Save a document as PDF in a Google Drive folder": "Save a document as PDF in a Google Drive folder",
|
|
28
|
+
"Update permissions for a file or folder": "Update permissions for a file or folder",
|
|
29
|
+
"Removes a role from an user for a file or folder": "Removes a role from an user for a file or folder",
|
|
30
|
+
"Set public access for a file or folder": "Set public access for a file or folder",
|
|
31
|
+
"Moves a file from one folder to another.": "Moves a file from one folder to another.",
|
|
32
|
+
"Delete permanently a file from your Google Drive": "Delete permanently a file from your Google Drive",
|
|
33
|
+
"Move a file to the trash in your Google Drive": "Move a file to the trash in your Google Drive",
|
|
34
|
+
"Make a custom API call to a specific endpoint": "将一个自定义 API 调用到一个特定的终点",
|
|
35
|
+
"Folder name": "Folder name",
|
|
36
|
+
"Parent Folder": "父文件夹",
|
|
37
|
+
"Include Team Drives": "Include Team Drives",
|
|
38
|
+
"File name": "File name",
|
|
39
|
+
"Text": "文本",
|
|
40
|
+
"Content type": "Content type",
|
|
41
|
+
"File": "文件",
|
|
42
|
+
"File ID": "File ID",
|
|
43
|
+
"Destination File name": "Destination File name",
|
|
44
|
+
"File / Folder Id": "File / Folder Id",
|
|
45
|
+
"Folder ID": "Folder ID",
|
|
46
|
+
"Include Trashed": "Include Trashed",
|
|
47
|
+
"Depth Level": "Depth Level",
|
|
48
|
+
"Download Files": "Download Files",
|
|
49
|
+
"Query Term": "Query Term",
|
|
50
|
+
"Operator": "运算符",
|
|
51
|
+
"Value": "值",
|
|
52
|
+
"File Type": "File Type",
|
|
53
|
+
"Name": "名称",
|
|
54
|
+
"Duplicate as": "Duplicate as",
|
|
55
|
+
"Document ID": "Document ID",
|
|
56
|
+
"File or Folder ID": "File or Folder ID",
|
|
57
|
+
"User email": "User email",
|
|
58
|
+
"Role": "作用",
|
|
59
|
+
"Send invitation email": "Send invitation email",
|
|
60
|
+
"Method": "方法",
|
|
61
|
+
"Headers": "信头",
|
|
62
|
+
"Query Parameters": "查询参数",
|
|
63
|
+
"Body Type": "Body Type",
|
|
64
|
+
"Body": "正文内容",
|
|
65
|
+
"Response is Binary ?": "Response is Binary ?",
|
|
66
|
+
"No Error on Failure": "失败时没有错误",
|
|
67
|
+
"Timeout (in seconds)": "超时(秒)",
|
|
68
|
+
"Follow redirects": "Follow redirects",
|
|
69
|
+
"The name of the new folder": "The name of the new folder",
|
|
70
|
+
"Determines if folders from Team Drives should be included in the results.": "Determines if folders from Team Drives should be included in the results.",
|
|
71
|
+
"The name of the new text file": "The name of the new text file",
|
|
72
|
+
"The text content to add to file": "The text content to add to file",
|
|
73
|
+
"Select file type": "Select file type",
|
|
74
|
+
"The name of the file": "The name of the file",
|
|
75
|
+
"The file URL or base64 to upload": "The file URL or base64 to upload",
|
|
76
|
+
"File ID coming from | New File -> id |": "File ID coming from | New File -> id |",
|
|
77
|
+
"The Id of the file/folder to search for.": "The Id of the file/folder to search for.",
|
|
78
|
+
"Folder ID coming from | New Folder -> id | (or any other source)": "Folder ID coming from | New Folder -> id | (or any other source)",
|
|
79
|
+
"Include new files that have been trashed.": "Include new files that have been trashed.",
|
|
80
|
+
"How many levels deep to search for files. 1 = current folder only, 2 = current + next level, etc.": "How many levels deep to search for files. 1 = current folder only, 2 = current + next level, etc.",
|
|
81
|
+
"Download all file contents in a list": "Download all file contents in a list",
|
|
82
|
+
"The Query term or field of file/folder to search upon.": "The Query term or field of file/folder to search upon.",
|
|
83
|
+
"The operator to create criteria.": "The operator to create criteria.",
|
|
84
|
+
"Value of the field of file/folder to search for.": "Value of the field of file/folder to search for.",
|
|
85
|
+
"(Optional) Choose between files and folders.": "(Optional) Choose between files and folders.",
|
|
86
|
+
"The ID of the file to duplicate": "The ID of the file to duplicate",
|
|
87
|
+
"The name of the new file": "The name of the new file",
|
|
88
|
+
"The ID of the folder where the file will be duplicated": "The ID of the folder where the file will be duplicated",
|
|
89
|
+
"If left unselected the file will be duplicated as it is": "If left unselected the file will be duplicated as it is",
|
|
90
|
+
"The ID of the document to export": "The ID of the document to export",
|
|
91
|
+
"The ID of the folder where the file will be exported": "The ID of the folder where the file will be exported",
|
|
92
|
+
"The name of the new file (do not include the extension)": "The name of the new file (do not include the extension)",
|
|
93
|
+
"The ID of the file or folder to update permissions for": "The ID of the file or folder to update permissions for",
|
|
94
|
+
"The email address of the user to update permissions for": "The email address of the user to update permissions for",
|
|
95
|
+
"The role to grant to user. See more at: https://developers.google.com/drive/api/guides/ref-roles": "The role to grant to user. See more at: https://developers.google.com/drive/api/guides/ref-roles",
|
|
96
|
+
"Send an email to the user to notify them of the new permissions": "Send an email to the user to notify them of the new permissions",
|
|
97
|
+
"The role to remove from user.": "The role to remove from user.",
|
|
98
|
+
"The role to assign for public access": "The role to assign for public access",
|
|
99
|
+
"You can use **Search Folder/File** action to retrieve ID.": "You can use **Search Folder/File** action to retrieve ID.",
|
|
100
|
+
"The ID of the file to delete": "The ID of the file to delete",
|
|
101
|
+
"The ID of the file to trash": "The ID of the file to trash",
|
|
102
|
+
"Authorization headers are injected automatically from your connection.": "授权头自动从您的连接中注入。",
|
|
103
|
+
"Enable for files like PDFs, images, etc.": "Enable for files like PDFs, images, etc.",
|
|
104
|
+
"CSV": "CSV",
|
|
105
|
+
"XML": "XML",
|
|
106
|
+
"Full text search": "Full text search",
|
|
107
|
+
"Contains": "Contains",
|
|
108
|
+
"Equals": "Equals",
|
|
109
|
+
"All": "所有的",
|
|
110
|
+
"Files": "Files",
|
|
111
|
+
"Folders": "文件夹",
|
|
112
|
+
"Google Sheets": "谷歌工作表",
|
|
113
|
+
"Google Docs": "Google Docs",
|
|
114
|
+
"Organizer": "Organizer",
|
|
115
|
+
"File Organizer": "File Organizer",
|
|
116
|
+
"Writer": "Writer",
|
|
117
|
+
"Commenter": "Commenter",
|
|
118
|
+
"Reader": "Reader",
|
|
119
|
+
"Editor": "编辑器",
|
|
120
|
+
"GET": "获取",
|
|
121
|
+
"POST": "帖子",
|
|
122
|
+
"PATCH": "PATCH",
|
|
123
|
+
"PUT": "弹出",
|
|
124
|
+
"DELETE": "删除",
|
|
125
|
+
"HEAD": "黑色",
|
|
126
|
+
"None": "无",
|
|
127
|
+
"JSON": "JSON",
|
|
128
|
+
"Form Data": "表单数据",
|
|
129
|
+
"Raw": "原始文件",
|
|
130
|
+
"New File": "New File",
|
|
131
|
+
"New Folder": "新建文件夹",
|
|
132
|
+
"Trigger when a new file is uploaded.": "Trigger when a new file is uploaded.",
|
|
133
|
+
"Trigger when a new folder is created or uploaded.": "Trigger when a new folder is created or uploaded.",
|
|
134
|
+
"Include File Content": "Include File Content",
|
|
135
|
+
"Include the file content in the output. This will increase the time taken to fetch the files and might cause issues with large files.": "Include the file content in the output. This will increase the time taken to fetch the files and might cause issues with large files."
|
|
136
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createPiece,
|
|
3
|
+
} from '@guayaba/workflows-framework';
|
|
4
|
+
|
|
5
|
+
import { createCustomApiCallAction } from '@guayaba/workflows-common';
|
|
6
|
+
import { PieceCategory } from '@guayaba/workflows-shared';
|
|
7
|
+
import { addPermission } from './lib/action/add-permission.action';
|
|
8
|
+
import { googleDriveCreateNewFolder } from './lib/action/create-new-folder';
|
|
9
|
+
import { googleDriveCreateNewTextFile } from './lib/action/create-new-text-file';
|
|
10
|
+
import { deletePermission } from './lib/action/delete-permission.action';
|
|
11
|
+
import { duplicateFileAction } from './lib/action/duplicate-file.action';
|
|
12
|
+
import { googleDriveGetResourceById } from './lib/action/get-file-by-id';
|
|
13
|
+
import { googleDriveListFiles } from './lib/action/list-files.action';
|
|
14
|
+
import { readFile } from './lib/action/read-file';
|
|
15
|
+
import { saveFileAsPdf } from './lib/action/save-file-as-pdf.action';
|
|
16
|
+
import { googleDriveSearchFolder } from './lib/action/search-folder-or-file.action';
|
|
17
|
+
import { googleDriveUploadFile } from './lib/action/upload-file';
|
|
18
|
+
import { newFile } from './lib/triggers/new-file';
|
|
19
|
+
import { newFolder } from './lib/triggers/new-folder';
|
|
20
|
+
import { setPublicAccess } from './lib/action/set-public-access';
|
|
21
|
+
import { moveFileAction } from './lib/action/move-file';
|
|
22
|
+
import { googleDriveDeleteFile } from './lib/action/delete-file';
|
|
23
|
+
import { googleDriveTrashFile } from './lib/action/send-to-trash';
|
|
24
|
+
import { googleDriveAuth, getAccessToken, GoogleDriveAuthValue } from './lib/auth';
|
|
25
|
+
|
|
26
|
+
export { googleDriveAuth, getAccessToken, GoogleDriveAuthValue, createGoogleClient } from './lib/auth';
|
|
27
|
+
|
|
28
|
+
export const googleDrive = createPiece({
|
|
29
|
+
minimumSupportedRelease: '0.5.6',
|
|
30
|
+
logoUrl: 'https://cdn.activepieces.com/pieces/google-drive.png',
|
|
31
|
+
categories: [PieceCategory.CONTENT_AND_FILES],
|
|
32
|
+
displayName: 'Google Drive',
|
|
33
|
+
description: 'Cloud storage and file backup',
|
|
34
|
+
authors: [
|
|
35
|
+
'BastienMe',
|
|
36
|
+
'ArmanGiau3',
|
|
37
|
+
'Vitalini',
|
|
38
|
+
'pfernandez98',
|
|
39
|
+
'kanarelo',
|
|
40
|
+
'Salem-Alaa',
|
|
41
|
+
'kishanprmr',
|
|
42
|
+
'MoShizzle',
|
|
43
|
+
'AbdulTheActivePiecer',
|
|
44
|
+
'khaledmashaly',
|
|
45
|
+
'abuaboud',
|
|
46
|
+
'geekyme'
|
|
47
|
+
],
|
|
48
|
+
triggers: [newFile, newFolder],
|
|
49
|
+
actions: [
|
|
50
|
+
googleDriveCreateNewFolder,
|
|
51
|
+
googleDriveCreateNewTextFile,
|
|
52
|
+
googleDriveUploadFile,
|
|
53
|
+
readFile,
|
|
54
|
+
googleDriveGetResourceById,
|
|
55
|
+
googleDriveListFiles,
|
|
56
|
+
googleDriveSearchFolder,
|
|
57
|
+
duplicateFileAction,
|
|
58
|
+
saveFileAsPdf,
|
|
59
|
+
addPermission,
|
|
60
|
+
deletePermission,
|
|
61
|
+
setPublicAccess,
|
|
62
|
+
moveFileAction,
|
|
63
|
+
googleDriveDeleteFile,
|
|
64
|
+
googleDriveTrashFile,
|
|
65
|
+
createCustomApiCallAction({
|
|
66
|
+
baseUrl: () => 'https://www.googleapis.com/drive/v3',
|
|
67
|
+
auth: googleDriveAuth,
|
|
68
|
+
authMapping: async (auth) => ({
|
|
69
|
+
Authorization: `Bearer ${await getAccessToken(auth as GoogleDriveAuthValue)}`,
|
|
70
|
+
}),
|
|
71
|
+
}),
|
|
72
|
+
],
|
|
73
|
+
auth: googleDriveAuth,
|
|
74
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Property, createAction } from "@guayaba/workflows-framework";
|
|
2
|
+
import { googleDriveAuth, createGoogleClient } from '../auth';
|
|
3
|
+
import { google } from 'googleapis';
|
|
4
|
+
import { common } from "../common";
|
|
5
|
+
|
|
6
|
+
export const addPermission = createAction({
|
|
7
|
+
auth: googleDriveAuth,
|
|
8
|
+
name: 'update_permissions',
|
|
9
|
+
description: 'Update permissions for a file or folder',
|
|
10
|
+
displayName: 'Update permissions',
|
|
11
|
+
props: {
|
|
12
|
+
fileId: Property.ShortText({
|
|
13
|
+
displayName: 'File or Folder ID',
|
|
14
|
+
description: 'The ID of the file or folder to update permissions for',
|
|
15
|
+
required: true,
|
|
16
|
+
}),
|
|
17
|
+
user_email: Property.ShortText({
|
|
18
|
+
displayName: 'User email',
|
|
19
|
+
description: 'The email address of the user to update permissions for',
|
|
20
|
+
required: true,
|
|
21
|
+
}),
|
|
22
|
+
permission_name : Property.StaticDropdown({
|
|
23
|
+
displayName: 'Role',
|
|
24
|
+
description: 'The role to grant to user. See more at: https://developers.google.com/drive/api/guides/ref-roles',
|
|
25
|
+
required: true,
|
|
26
|
+
options: {
|
|
27
|
+
options: [
|
|
28
|
+
{
|
|
29
|
+
label: 'Organizer',
|
|
30
|
+
value: 'organizer',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
label: 'File Organizer',
|
|
34
|
+
value: 'fileOrganizer',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
label: 'Writer',
|
|
38
|
+
value: 'writer',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
label: 'Commenter',
|
|
42
|
+
value: 'commenter',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
label: 'Reader',
|
|
46
|
+
value: 'reader',
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
include_team_drives: common.properties.include_team_drives,
|
|
53
|
+
send_invitation_email: Property.Checkbox({
|
|
54
|
+
displayName: 'Send invitation email',
|
|
55
|
+
description: 'Send an email to the user to notify them of the new permissions',
|
|
56
|
+
required: true,
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
async run(context) {
|
|
61
|
+
const {fileId, user_email, permission_name, send_invitation_email,include_team_drives} = context.propsValue;
|
|
62
|
+
|
|
63
|
+
const authClient = await createGoogleClient(context.auth);
|
|
64
|
+
|
|
65
|
+
const drive = google.drive({ version: 'v3', auth: authClient });
|
|
66
|
+
|
|
67
|
+
const permission = { 'type': 'user', 'role': permission_name, 'emailAddress': user_email };
|
|
68
|
+
|
|
69
|
+
const result = await drive.permissions.create({
|
|
70
|
+
requestBody: permission,
|
|
71
|
+
fileId: fileId,
|
|
72
|
+
sendNotificationEmail: send_invitation_email,
|
|
73
|
+
supportsAllDrives: include_team_drives,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return result.data;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createAction, Property } from '@guayaba/workflows-framework';
|
|
2
|
+
import { googleDriveAuth, createGoogleClient } from '../auth';
|
|
3
|
+
import { common } from '../common';
|
|
4
|
+
import { google } from 'googleapis';
|
|
5
|
+
|
|
6
|
+
export const googleDriveCreateNewFolder = createAction({
|
|
7
|
+
auth: googleDriveAuth,
|
|
8
|
+
name: 'create_new_gdrive_folder',
|
|
9
|
+
description: 'Create a new empty folder in your Google Drive',
|
|
10
|
+
displayName: 'Create new folder',
|
|
11
|
+
props: {
|
|
12
|
+
folderName: Property.ShortText({
|
|
13
|
+
displayName: 'Folder name',
|
|
14
|
+
description: 'The name of the new folder',
|
|
15
|
+
required: true,
|
|
16
|
+
}),
|
|
17
|
+
parentFolder: common.properties.parentFolder,
|
|
18
|
+
include_team_drives: common.properties.include_team_drives,
|
|
19
|
+
},
|
|
20
|
+
async run(context) {
|
|
21
|
+
const authClient = await createGoogleClient(context.auth);
|
|
22
|
+
|
|
23
|
+
const drive = google.drive({ version: 'v3', auth: authClient });
|
|
24
|
+
|
|
25
|
+
const response = await drive.files.create({
|
|
26
|
+
requestBody: {
|
|
27
|
+
mimeType: 'application/vnd.google-apps.folder',
|
|
28
|
+
name: context.propsValue.folderName,
|
|
29
|
+
...(context.propsValue.parentFolder
|
|
30
|
+
? { parents: [context.propsValue.parentFolder] }
|
|
31
|
+
: {}),
|
|
32
|
+
},
|
|
33
|
+
supportsAllDrives: context.propsValue.include_team_drives,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return response.data;
|
|
37
|
+
},
|
|
38
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createAction, Property } from '@guayaba/workflows-framework';
|
|
2
|
+
import {
|
|
3
|
+
httpClient,
|
|
4
|
+
HttpMethod,
|
|
5
|
+
AuthenticationType,
|
|
6
|
+
} from '@guayaba/workflows-common';
|
|
7
|
+
import FormData from 'form-data';
|
|
8
|
+
import { googleDriveAuth, getAccessToken } from '../auth';
|
|
9
|
+
import { common } from '../common';
|
|
10
|
+
|
|
11
|
+
export const googleDriveCreateNewTextFile = createAction({
|
|
12
|
+
auth: googleDriveAuth,
|
|
13
|
+
name: 'create_new_gdrive_file',
|
|
14
|
+
description: 'Create a new text file in your Google Drive from text',
|
|
15
|
+
displayName: 'Create new file',
|
|
16
|
+
props: {
|
|
17
|
+
fileName: Property.ShortText({
|
|
18
|
+
displayName: 'File name',
|
|
19
|
+
description: 'The name of the new text file',
|
|
20
|
+
required: true,
|
|
21
|
+
}),
|
|
22
|
+
text: Property.LongText({
|
|
23
|
+
displayName: 'Text',
|
|
24
|
+
description: 'The text content to add to file',
|
|
25
|
+
required: true,
|
|
26
|
+
}),
|
|
27
|
+
fileType: Property.StaticDropdown({
|
|
28
|
+
displayName: 'Content type',
|
|
29
|
+
description: 'Select file type',
|
|
30
|
+
required: true,
|
|
31
|
+
defaultValue: 'plain/text',
|
|
32
|
+
options: {
|
|
33
|
+
options: [
|
|
34
|
+
{
|
|
35
|
+
label: 'Text',
|
|
36
|
+
value: 'plain/text',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
label: 'CSV',
|
|
40
|
+
value: 'text/csv',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
label: 'XML',
|
|
44
|
+
value: 'text/xml',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
parentFolder: common.properties.parentFolder,
|
|
50
|
+
include_team_drives: common.properties.include_team_drives,
|
|
51
|
+
},
|
|
52
|
+
async run(context) {
|
|
53
|
+
const meta = {
|
|
54
|
+
mimeType: context.propsValue.fileType,
|
|
55
|
+
name: context.propsValue.fileName,
|
|
56
|
+
...(context.propsValue.parentFolder
|
|
57
|
+
? { parents: [context.propsValue.parentFolder] }
|
|
58
|
+
: {}),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const metaBuffer = Buffer.from(JSON.stringify(meta), 'utf-8');
|
|
62
|
+
const textBuffer = Buffer.from(context.propsValue.text!, 'utf-8');
|
|
63
|
+
|
|
64
|
+
const form = new FormData();
|
|
65
|
+
form.append('Metadata', metaBuffer, { contentType: 'application/json' });
|
|
66
|
+
form.append('Media', textBuffer, {
|
|
67
|
+
contentType: context.propsValue.fileType,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const result = await httpClient.sendRequest({
|
|
71
|
+
method: HttpMethod.POST,
|
|
72
|
+
url: `https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart`,
|
|
73
|
+
body: form,
|
|
74
|
+
headers: {
|
|
75
|
+
...form.getHeaders(),
|
|
76
|
+
},
|
|
77
|
+
queryParams: {
|
|
78
|
+
supportsAllDrives: String(context.propsValue.include_team_drives || false),
|
|
79
|
+
},
|
|
80
|
+
authentication: {
|
|
81
|
+
type: AuthenticationType.BEARER_TOKEN,
|
|
82
|
+
token: await getAccessToken(context.auth),
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
console.debug('File creation response', result);
|
|
87
|
+
return result.body;
|
|
88
|
+
},
|
|
89
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createAction, Property } from '@guayaba/workflows-framework';
|
|
2
|
+
import { googleDriveAuth, createGoogleClient } from '../auth';
|
|
3
|
+
import { common } from '../common';
|
|
4
|
+
import { google } from 'googleapis';
|
|
5
|
+
|
|
6
|
+
export const googleDriveDeleteFile = createAction({
|
|
7
|
+
auth: googleDriveAuth,
|
|
8
|
+
name: 'delete_gdrive_file',
|
|
9
|
+
description: 'Delete permanently a file from your Google Drive',
|
|
10
|
+
displayName: 'Delete file',
|
|
11
|
+
props: {
|
|
12
|
+
fileId: Property.ShortText({
|
|
13
|
+
displayName: 'File ID',
|
|
14
|
+
description: 'The ID of the file to delete',
|
|
15
|
+
required: true,
|
|
16
|
+
}),
|
|
17
|
+
include_team_drives: common.properties.include_team_drives,
|
|
18
|
+
},
|
|
19
|
+
async run(context) {
|
|
20
|
+
const authClient = await createGoogleClient(context.auth);
|
|
21
|
+
|
|
22
|
+
const drive = google.drive({ version: 'v3', auth: authClient });
|
|
23
|
+
|
|
24
|
+
const response = await drive.files.delete({
|
|
25
|
+
fileId: context.propsValue.fileId,
|
|
26
|
+
supportsAllDrives: context.propsValue.include_team_drives,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return response.data;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Property, createAction } from "@guayaba/workflows-framework";
|
|
2
|
+
import { googleDriveAuth, createGoogleClient } from '../auth';
|
|
3
|
+
import { google } from 'googleapis';
|
|
4
|
+
|
|
5
|
+
export const deletePermission = createAction({
|
|
6
|
+
auth: googleDriveAuth,
|
|
7
|
+
name: 'delete_permissions',
|
|
8
|
+
description: 'Removes a role from an user for a file or folder',
|
|
9
|
+
displayName: 'Delete permissions',
|
|
10
|
+
props: {
|
|
11
|
+
fileId: Property.ShortText({
|
|
12
|
+
displayName: 'File or Folder ID',
|
|
13
|
+
description: 'The ID of the file or folder to update permissions for',
|
|
14
|
+
required: true,
|
|
15
|
+
}),
|
|
16
|
+
user_email: Property.ShortText({
|
|
17
|
+
displayName: 'User email',
|
|
18
|
+
description: 'The email address of the user to update permissions for',
|
|
19
|
+
required: true,
|
|
20
|
+
}),
|
|
21
|
+
permission_name : Property.StaticDropdown({
|
|
22
|
+
displayName: 'Role',
|
|
23
|
+
description: 'The role to remove from user.',
|
|
24
|
+
required: true,
|
|
25
|
+
options: {
|
|
26
|
+
options: [
|
|
27
|
+
{
|
|
28
|
+
label: 'Organizer',
|
|
29
|
+
value: 'organizer',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: 'File Organizer',
|
|
33
|
+
value: 'fileOrganizer',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
label: 'Writer',
|
|
37
|
+
value: 'writer',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: 'Commenter',
|
|
41
|
+
value: 'commenter',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
label: 'Reader',
|
|
45
|
+
value: 'reader',
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
},
|
|
52
|
+
async run (context) {
|
|
53
|
+
const [fileId, user_email] = [context.propsValue.fileId, context.propsValue.user_email];
|
|
54
|
+
const authClient = await createGoogleClient(context.auth);
|
|
55
|
+
|
|
56
|
+
const drive = google.drive({ version: 'v3', auth: authClient });
|
|
57
|
+
|
|
58
|
+
const response_permissions_list = await drive.permissions.list({
|
|
59
|
+
fileId: fileId,
|
|
60
|
+
fields: 'permissions(id, emailAddress, role)',
|
|
61
|
+
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (response_permissions_list.data.permissions) {
|
|
65
|
+
|
|
66
|
+
for (const permission of response_permissions_list.data.permissions) {
|
|
67
|
+
if (permission.emailAddress === user_email && permission.role === context.propsValue.permission_name) {
|
|
68
|
+
await drive.permissions.delete({
|
|
69
|
+
fileId: fileId,
|
|
70
|
+
permissionId: permission.id ? permission.id : '',
|
|
71
|
+
});
|
|
72
|
+
return {removed: true, message: 'Permission removed'};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {removed: false, message: 'Permission not found'};
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Property, createAction } from '@guayaba/workflows-framework';
|
|
2
|
+
import { google } from 'googleapis';
|
|
3
|
+
import { googleDriveAuth, createGoogleClient } from '../auth';
|
|
4
|
+
import { common } from '../common';
|
|
5
|
+
|
|
6
|
+
export const duplicateFileAction = createAction({
|
|
7
|
+
displayName: 'Duplicate File',
|
|
8
|
+
auth: googleDriveAuth,
|
|
9
|
+
name: 'duplicate_file',
|
|
10
|
+
description: 'Duplicate a file from Google Drive. Returns the new file ID.',
|
|
11
|
+
props: {
|
|
12
|
+
fileId: Property.ShortText({
|
|
13
|
+
displayName: 'File ID',
|
|
14
|
+
description: 'The ID of the file to duplicate',
|
|
15
|
+
required: true,
|
|
16
|
+
}),
|
|
17
|
+
name: Property.ShortText({
|
|
18
|
+
displayName: 'Name',
|
|
19
|
+
description: 'The name of the new file',
|
|
20
|
+
required: true,
|
|
21
|
+
}),
|
|
22
|
+
folderId: Property.ShortText({
|
|
23
|
+
displayName: 'Folder ID',
|
|
24
|
+
description: 'The ID of the folder where the file will be duplicated',
|
|
25
|
+
required: true,
|
|
26
|
+
}),
|
|
27
|
+
mimeType: Property.StaticDropdown({
|
|
28
|
+
displayName: 'Duplicate as',
|
|
29
|
+
description: 'If left unselected the file will be duplicated as it is',
|
|
30
|
+
required: false,
|
|
31
|
+
options: {
|
|
32
|
+
options: [
|
|
33
|
+
{
|
|
34
|
+
label: 'Google Sheets',
|
|
35
|
+
value: 'application/vnd.google-apps.spreadsheet',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: 'Google Docs',
|
|
39
|
+
value: 'application/vnd.google-apps.document',
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
include_team_drives: common.properties.include_team_drives,
|
|
45
|
+
},
|
|
46
|
+
async run(context) {
|
|
47
|
+
const authClient = await createGoogleClient(context.auth);
|
|
48
|
+
|
|
49
|
+
const fileId = context.propsValue.fileId;
|
|
50
|
+
const nameForNewFile = context.propsValue.name;
|
|
51
|
+
const parentFolderId = context.propsValue.folderId;
|
|
52
|
+
const mimeType = context.propsValue.mimeType;
|
|
53
|
+
|
|
54
|
+
const drive = google.drive({ version: 'v3', auth: authClient });
|
|
55
|
+
|
|
56
|
+
const requestBody: any = {
|
|
57
|
+
name: nameForNewFile,
|
|
58
|
+
parents: [parentFolderId],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
if (mimeType) {
|
|
62
|
+
requestBody.mimeType = mimeType;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const response = await drive.files.copy({
|
|
66
|
+
fileId,
|
|
67
|
+
auth: authClient,
|
|
68
|
+
requestBody,
|
|
69
|
+
supportsAllDrives: context.propsValue.include_team_drives,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (response.status !== 200) {
|
|
73
|
+
throw new Error('Error duplicating file');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return response.data;
|
|
77
|
+
},
|
|
78
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { googleDriveAuth, createGoogleClient } from '../auth';
|
|
2
|
+
import { Property, createAction } from '@guayaba/workflows-framework';
|
|
3
|
+
import { google } from 'googleapis';
|
|
4
|
+
import { common } from '../common';
|
|
5
|
+
|
|
6
|
+
export const googleDriveGetResourceById = createAction({
|
|
7
|
+
auth: googleDriveAuth,
|
|
8
|
+
name: 'get-file-or-folder-by-id',
|
|
9
|
+
displayName: 'Get File Information',
|
|
10
|
+
description: 'Get a file folder for files/sub-folders',
|
|
11
|
+
props: {
|
|
12
|
+
id: Property.ShortText({
|
|
13
|
+
displayName: 'File / Folder Id',
|
|
14
|
+
description: 'The Id of the file/folder to search for.',
|
|
15
|
+
required: true,
|
|
16
|
+
}),
|
|
17
|
+
include_team_drives: common.properties.include_team_drives,
|
|
18
|
+
},
|
|
19
|
+
async run(context) {
|
|
20
|
+
const authClient = await createGoogleClient(context.auth);
|
|
21
|
+
const drive = google.drive({ version: 'v3', auth: authClient });
|
|
22
|
+
const response = await drive.files.get({
|
|
23
|
+
fileId: context.propsValue.id,
|
|
24
|
+
supportsAllDrives: context.propsValue.include_team_drives,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (response.data) {
|
|
28
|
+
return response.data;
|
|
29
|
+
} else {
|
|
30
|
+
console.log('The specified ID corresponds to a folder. Returning null.');
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
});
|