Skip to content

Commit 34812fa

Browse files
authored
Created new actions and sources for ONLYOFFICE DocSpace (#12991)
1 parent 605441f commit 34812fa

File tree

12 files changed

+553
-8
lines changed

12 files changed

+553
-8
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import app from "../../onlyoffice_docspace.app.mjs";
2+
3+
export default {
4+
key: "onlyoffice_docspace-create-room",
5+
name: "Create Room",
6+
description: "Creates a new room. [See the documentation](https://api.onlyoffice.com/docspace/method/files/post/api/2.0/files/rooms)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
title: {
12+
type: "string",
13+
label: "Title",
14+
description: "The name of the room to be created.",
15+
},
16+
roomType: {
17+
type: "integer",
18+
label: "Room Type",
19+
description: "The type of the room.",
20+
options: [
21+
{
22+
label: "Editing Room",
23+
value: 2,
24+
},
25+
{
26+
label: "Custom Room",
27+
value: 5,
28+
},
29+
{
30+
label: "Public Room",
31+
value: 6,
32+
},
33+
],
34+
},
35+
notify: {
36+
type: "boolean",
37+
label: "Notify",
38+
description: "Whether to notify the user about the room creation.",
39+
optional: true,
40+
},
41+
sharingMessage: {
42+
type: "string",
43+
label: "Sharing Message",
44+
description: "Message to send when notifying about the shared room",
45+
optional: true,
46+
},
47+
},
48+
methods: {
49+
createRoom(args = {}) {
50+
return this.app.post({
51+
path: "/files/rooms",
52+
...args,
53+
});
54+
},
55+
},
56+
async run({ $ }) {
57+
const {
58+
createRoom,
59+
title,
60+
roomType,
61+
notify,
62+
sharingMessage,
63+
} = this;
64+
65+
const response = await createRoom({
66+
$,
67+
data: {
68+
Title: title,
69+
RoomType: roomType,
70+
Notify: notify,
71+
SharingMessage: sharingMessage,
72+
},
73+
});
74+
$.export("$summary", `Successfully created room with ID \`${response.response.id}\`.`);
75+
return response;
76+
},
77+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import app from "../../onlyoffice_docspace.app.mjs";
2+
3+
export default {
4+
key: "onlyoffice_docspace-invite-user",
5+
name: "Invite User",
6+
description: "Invites a new user to the portal. [See the documentation](https://api.onlyoffice.com/docspace/method/people/post/api/2.0/people/invite)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
email: {
12+
type: "string",
13+
label: "User Email",
14+
description: "The email of the user to invite.",
15+
},
16+
},
17+
methods: {
18+
inviteUser(args = {}) {
19+
return this.app.post({
20+
path: "/people/invite",
21+
...args,
22+
});
23+
},
24+
},
25+
async run({ $ }) {
26+
const {
27+
inviteUser,
28+
email,
29+
} = this;
30+
31+
const response = await inviteUser({
32+
$,
33+
data: {
34+
Invitations: [
35+
{
36+
email,
37+
},
38+
],
39+
},
40+
});
41+
42+
$.export("$summary", `Successfully invited user with email \`${email}\``);
43+
return response;
44+
},
45+
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import app from "../../onlyoffice_docspace.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "onlyoffice_docspace-upload-file",
6+
name: "Upload File",
7+
description: "Uploads a file to the specified room. [See the documentation](https://api.onlyoffice.com/docspace/method/files/post/api/2.0/files/%7bfolderid%7d/upload)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
folderId: {
13+
label: "Folder ID",
14+
description: "The ID of the folder where you want the file to be uploaded.",
15+
propDefinition: [
16+
app,
17+
"file",
18+
],
19+
},
20+
file: {
21+
type: "string",
22+
label: "File",
23+
description: "File path of a file previously downloaded in Pipedream E.g. (`/tmp/my-file.txt`). [Download a file to the `/tmp` directory](https://pipedream.com/docs/code/nodejs/http-requests/#download-a-file-to-the-tmp-directory)",
24+
},
25+
},
26+
methods: {
27+
uploadFile({
28+
folderId, ...args
29+
} = {}) {
30+
return this.app.post({
31+
path: `/files/${folderId}/upload`,
32+
...args,
33+
});
34+
},
35+
},
36+
async run({ $ }) {
37+
const {
38+
uploadFile,
39+
folderId,
40+
file,
41+
} = this;
42+
43+
const response = await uploadFile({
44+
$,
45+
folderId,
46+
headers: constants.MULTIPART_FORM_DATA_HEADERS,
47+
data: {
48+
File: file,
49+
},
50+
});
51+
52+
$.export("$summary", `Successfully uploaded file with ID \`${response.response.id}\`.`);
53+
return response;
54+
},
55+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const SUBDOMAIN_PLACEHOLDER = "{subdomain}";
2+
const VERSION_PATH = "/api/2.0";
3+
const BASE_URL = `https://${SUBDOMAIN_PLACEHOLDER}.onlyoffice.com${VERSION_PATH}`;
4+
5+
const FILE_PROP_NAMES = [
6+
"File",
7+
];
8+
9+
const CONTENT_TYPE_KEY_HEADER = "Content-Type";
10+
const MULTIPART_FORM_DATA_VALUE_HEADER = "multipart/form-data";
11+
const MULTIPART_FORM_DATA_HEADERS = {
12+
[CONTENT_TYPE_KEY_HEADER]: MULTIPART_FORM_DATA_VALUE_HEADER,
13+
};
14+
15+
const RESOURCE_NAME = {
16+
FILES: "files",
17+
FOLDERS: "folders",
18+
};
19+
20+
const FILTER_TYPE = {
21+
NONE: "None",
22+
FILES_ONLY: "FilesOnly",
23+
FOLDERS_ONLY: "FoldersOnly",
24+
DOCUMENTS_ONLY: "DocumentsOnly",
25+
PRESENTATIONS_ONLY: "PresentationsOnly",
26+
SPREADSHEETS_ONLY: "SpreadsheetsOnly",
27+
IMAGES_ONLY: "ImagesOnly",
28+
BY_USER: "ByUser",
29+
BY_DEPARTMENT: "ByDepartment",
30+
ARCHIVE_ONLY: "ArchiveOnly",
31+
BY_EXTENSION: "ByExtension",
32+
MEDIA_ONLY: "MediaOnly",
33+
EDITING_ROOMS: "EditingRooms",
34+
CUSTOM_ROOMS: "CustomRooms",
35+
OFORM_TEMPLATE_ONLY: "OFormTemplateOnly",
36+
OFORM_ONLY: "OFormOnly",
37+
};
38+
39+
export default {
40+
SUBDOMAIN_PLACEHOLDER,
41+
BASE_URL,
42+
VERSION_PATH,
43+
RESOURCE_NAME,
44+
FILTER_TYPE,
45+
FILE_PROP_NAMES,
46+
MULTIPART_FORM_DATA_VALUE_HEADER,
47+
MULTIPART_FORM_DATA_HEADERS,
48+
CONTENT_TYPE_KEY_HEADER,
49+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { createReadStream } from "fs";
2+
import FormData from "form-data";
3+
import constants from "./constants.mjs";
4+
5+
function buildFormData(formData, data, parentKey) {
6+
if (data && typeof(data) === "object") {
7+
Object.keys(data)
8+
.forEach((key) => {
9+
buildFormData(formData, data[key], parentKey && `${parentKey}[${key}]` || key);
10+
});
11+
12+
} else if (data && constants.FILE_PROP_NAMES.some((prop) => parentKey.includes(prop))) {
13+
formData.append(parentKey, createReadStream(data));
14+
15+
} else if (data) {
16+
formData.append(parentKey, (data).toString());
17+
}
18+
}
19+
20+
function getFormData(data) {
21+
try {
22+
const formData = new FormData();
23+
buildFormData(formData, data);
24+
return formData;
25+
} catch (error) {
26+
console.log("FormData Error", error);
27+
throw error;
28+
}
29+
}
30+
31+
function hasMultipartHeader(headers) {
32+
return headers
33+
&& headers[constants.CONTENT_TYPE_KEY_HEADER]?.
34+
includes(constants.MULTIPART_FORM_DATA_VALUE_HEADER);
35+
}
36+
37+
export default {
38+
getFormData,
39+
hasMultipartHeader,
40+
};
Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,97 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
import utils from "./common/utils.mjs";
4+
15
export default {
26
type: "app",
37
app: "onlyoffice_docspace",
4-
propDefinitions: {},
8+
propDefinitions: {
9+
file: {
10+
type: "string",
11+
label: "File",
12+
description: "The file or folder ID.",
13+
async options({
14+
resourcesName = constants.RESOURCE_NAME.FOLDERS,
15+
mapper = ({
16+
id,
17+
title: label,
18+
}) => ({
19+
value: String(id),
20+
label,
21+
}),
22+
params = {
23+
filterType: constants.FILTER_TYPE.FOLDERS_ONLY,
24+
withsubfolders: true,
25+
},
26+
}) {
27+
const { response: { [resourcesName]: resources } } =
28+
await this.listMyFilesAndFolders({
29+
params,
30+
});
31+
return resources.map(mapper);
32+
},
33+
},
34+
},
535
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
36+
getUrl(path) {
37+
const baseUrl = constants.BASE_URL
38+
.replace(constants.SUBDOMAIN_PLACEHOLDER, this.$auth.subdomain);
39+
return `${baseUrl}${path}`;
40+
},
41+
getHeaders(headers) {
42+
return {
43+
"Content-Type": "application/json",
44+
"Accept": "application/json",
45+
"Authorization": this.$auth.oauth_access_token,
46+
...headers,
47+
};
48+
},
49+
getConfig({
50+
headers, data: preData, ...args
51+
} = {}) {
52+
const contentType = constants.CONTENT_TYPE_KEY_HEADER;
53+
const hasMultipartHeader = utils.hasMultipartHeader(headers);
54+
const data = hasMultipartHeader && utils.getFormData(preData) || preData;
55+
const currentHeaders = this.getHeaders(headers);
56+
57+
return {
58+
headers: hasMultipartHeader
59+
? {
60+
...currentHeaders,
61+
[contentType]: data.getHeaders()[contentType.toLowerCase()],
62+
}
63+
: currentHeaders,
64+
data,
65+
...args,
66+
};
67+
},
68+
_makeRequest({
69+
$ = this, path, headers, ...args
70+
} = {}) {
71+
const config = this.getConfig({
72+
url: this.getUrl(path),
73+
headers: this.getHeaders(headers),
74+
...args,
75+
});
76+
return axios($, config);
77+
},
78+
post(args = {}) {
79+
return this._makeRequest({
80+
method: "POST",
81+
...args,
82+
});
83+
},
84+
listMyFilesAndFolders(args = {}) {
85+
return this._makeRequest({
86+
path: "/files/@my",
87+
...args,
88+
});
89+
},
90+
searchUsersByExtendedFilter(args = {}) {
91+
return this._makeRequest({
92+
path: "/people/simple/filter",
93+
...args,
94+
});
995
},
1096
},
11-
};
97+
};

components/onlyoffice_docspace/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/onlyoffice_docspace",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream ONLYOFFICE DocSpace Components",
55
"main": "onlyoffice_docspace.app.mjs",
66
"keywords": [
@@ -11,5 +11,9 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.0",
17+
"form-data": "^4.0.0"
1418
}
15-
}
19+
}

0 commit comments

Comments
 (0)