-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[Components] onlyoffice_docspace: Created new actions and sources for ONLYOFFICE DocSpace #12991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jcortes
merged 1 commit into
PipedreamHQ:master
from
jcortes:onlyoffice-docspace-new-sources-actions
Jul 26, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
components/onlyoffice_docspace/actions/create-room/create-room.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import app from "../../onlyoffice_docspace.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "onlyoffice_docspace-create-room", | ||
| name: "Create Room", | ||
| description: "Creates a new room. [See the documentation](https://api.onlyoffice.com/docspace/method/files/post/api/2.0/files/rooms)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| title: { | ||
| type: "string", | ||
| label: "Title", | ||
| description: "The name of the room to be created.", | ||
| }, | ||
| roomType: { | ||
| type: "integer", | ||
| label: "Room Type", | ||
| description: "The type of the room.", | ||
| options: [ | ||
| { | ||
| label: "Editing Room", | ||
| value: 2, | ||
| }, | ||
| { | ||
| label: "Custom Room", | ||
| value: 5, | ||
| }, | ||
| { | ||
| label: "Public Room", | ||
| value: 6, | ||
| }, | ||
| ], | ||
| }, | ||
| notify: { | ||
| type: "boolean", | ||
| label: "Notify", | ||
| description: "Whether to notify the user about the room creation.", | ||
| optional: true, | ||
| }, | ||
| sharingMessage: { | ||
| type: "string", | ||
| label: "Sharing Message", | ||
| description: "Message to send when notifying about the shared room", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| createRoom(args = {}) { | ||
| return this.app.post({ | ||
| path: "/files/rooms", | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| createRoom, | ||
| title, | ||
| roomType, | ||
| notify, | ||
| sharingMessage, | ||
| } = this; | ||
|
|
||
| const response = await createRoom({ | ||
| $, | ||
| data: { | ||
| Title: title, | ||
| RoomType: roomType, | ||
| Notify: notify, | ||
| SharingMessage: sharingMessage, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully created room with ID \`${response.response.id}\`.`); | ||
| return response; | ||
| }, | ||
| }; |
45 changes: 45 additions & 0 deletions
45
components/onlyoffice_docspace/actions/invite-user/invite-user.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import app from "../../onlyoffice_docspace.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "onlyoffice_docspace-invite-user", | ||
| name: "Invite User", | ||
| description: "Invites a new user to the portal. [See the documentation](https://api.onlyoffice.com/docspace/method/people/post/api/2.0/people/invite)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| email: { | ||
| type: "string", | ||
| label: "User Email", | ||
| description: "The email of the user to invite.", | ||
| }, | ||
| }, | ||
| methods: { | ||
| inviteUser(args = {}) { | ||
| return this.app.post({ | ||
| path: "/people/invite", | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| inviteUser, | ||
| email, | ||
| } = this; | ||
|
|
||
| const response = await inviteUser({ | ||
| $, | ||
| data: { | ||
| Invitations: [ | ||
| { | ||
| email, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully invited user with email \`${email}\``); | ||
| return response; | ||
| }, | ||
| }; |
55 changes: 55 additions & 0 deletions
55
components/onlyoffice_docspace/actions/upload-file/upload-file.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import app from "../../onlyoffice_docspace.app.mjs"; | ||
| import constants from "../../common/constants.mjs"; | ||
|
|
||
| export default { | ||
| key: "onlyoffice_docspace-upload-file", | ||
| name: "Upload File", | ||
| 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)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| folderId: { | ||
| label: "Folder ID", | ||
| description: "The ID of the folder where you want the file to be uploaded.", | ||
| propDefinition: [ | ||
| app, | ||
| "file", | ||
| ], | ||
| }, | ||
| file: { | ||
| type: "string", | ||
| label: "File", | ||
| 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)", | ||
| }, | ||
| }, | ||
| methods: { | ||
| uploadFile({ | ||
| folderId, ...args | ||
| } = {}) { | ||
| return this.app.post({ | ||
| path: `/files/${folderId}/upload`, | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| uploadFile, | ||
| folderId, | ||
| file, | ||
| } = this; | ||
|
|
||
| const response = await uploadFile({ | ||
| $, | ||
| folderId, | ||
| headers: constants.MULTIPART_FORM_DATA_HEADERS, | ||
| data: { | ||
| File: file, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully uploaded file with ID \`${response.response.id}\`.`); | ||
| return response; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| const SUBDOMAIN_PLACEHOLDER = "{subdomain}"; | ||
| const VERSION_PATH = "/api/2.0"; | ||
| const BASE_URL = `https://${SUBDOMAIN_PLACEHOLDER}.onlyoffice.com${VERSION_PATH}`; | ||
|
|
||
| const FILE_PROP_NAMES = [ | ||
| "File", | ||
| ]; | ||
|
|
||
| const CONTENT_TYPE_KEY_HEADER = "Content-Type"; | ||
| const MULTIPART_FORM_DATA_VALUE_HEADER = "multipart/form-data"; | ||
| const MULTIPART_FORM_DATA_HEADERS = { | ||
| [CONTENT_TYPE_KEY_HEADER]: MULTIPART_FORM_DATA_VALUE_HEADER, | ||
| }; | ||
|
|
||
| const RESOURCE_NAME = { | ||
| FILES: "files", | ||
| FOLDERS: "folders", | ||
| }; | ||
|
|
||
| const FILTER_TYPE = { | ||
| NONE: "None", | ||
| FILES_ONLY: "FilesOnly", | ||
| FOLDERS_ONLY: "FoldersOnly", | ||
| DOCUMENTS_ONLY: "DocumentsOnly", | ||
| PRESENTATIONS_ONLY: "PresentationsOnly", | ||
| SPREADSHEETS_ONLY: "SpreadsheetsOnly", | ||
| IMAGES_ONLY: "ImagesOnly", | ||
| BY_USER: "ByUser", | ||
| BY_DEPARTMENT: "ByDepartment", | ||
| ARCHIVE_ONLY: "ArchiveOnly", | ||
| BY_EXTENSION: "ByExtension", | ||
| MEDIA_ONLY: "MediaOnly", | ||
| EDITING_ROOMS: "EditingRooms", | ||
| CUSTOM_ROOMS: "CustomRooms", | ||
| OFORM_TEMPLATE_ONLY: "OFormTemplateOnly", | ||
| OFORM_ONLY: "OFormOnly", | ||
| }; | ||
|
|
||
| export default { | ||
| SUBDOMAIN_PLACEHOLDER, | ||
| BASE_URL, | ||
| VERSION_PATH, | ||
| RESOURCE_NAME, | ||
| FILTER_TYPE, | ||
| FILE_PROP_NAMES, | ||
| MULTIPART_FORM_DATA_VALUE_HEADER, | ||
| MULTIPART_FORM_DATA_HEADERS, | ||
| CONTENT_TYPE_KEY_HEADER, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { createReadStream } from "fs"; | ||
| import FormData from "form-data"; | ||
| import constants from "./constants.mjs"; | ||
|
|
||
| function buildFormData(formData, data, parentKey) { | ||
| if (data && typeof(data) === "object") { | ||
| Object.keys(data) | ||
| .forEach((key) => { | ||
| buildFormData(formData, data[key], parentKey && `${parentKey}[${key}]` || key); | ||
| }); | ||
|
|
||
| } else if (data && constants.FILE_PROP_NAMES.some((prop) => parentKey.includes(prop))) { | ||
| formData.append(parentKey, createReadStream(data)); | ||
|
|
||
| } else if (data) { | ||
| formData.append(parentKey, (data).toString()); | ||
| } | ||
| } | ||
|
|
||
| function getFormData(data) { | ||
| try { | ||
| const formData = new FormData(); | ||
| buildFormData(formData, data); | ||
| return formData; | ||
| } catch (error) { | ||
| console.log("FormData Error", error); | ||
| throw error; | ||
| } | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| function hasMultipartHeader(headers) { | ||
| return headers | ||
| && headers[constants.CONTENT_TYPE_KEY_HEADER]?. | ||
| includes(constants.MULTIPART_FORM_DATA_VALUE_HEADER); | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| export default { | ||
| getFormData, | ||
| hasMultipartHeader, | ||
| }; | ||
96 changes: 91 additions & 5 deletions
96
components/onlyoffice_docspace/onlyoffice_docspace.app.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,97 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
| import constants from "./common/constants.mjs"; | ||
| import utils from "./common/utils.mjs"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "onlyoffice_docspace", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| file: { | ||
| type: "string", | ||
| label: "File", | ||
| description: "The file or folder ID.", | ||
| async options({ | ||
| resourcesName = constants.RESOURCE_NAME.FOLDERS, | ||
| mapper = ({ | ||
| id, | ||
| title: label, | ||
| }) => ({ | ||
| value: String(id), | ||
| label, | ||
| }), | ||
| params = { | ||
| filterType: constants.FILTER_TYPE.FOLDERS_ONLY, | ||
| withsubfolders: true, | ||
| }, | ||
| }) { | ||
| const { response: { [resourcesName]: resources } } = | ||
| await this.listMyFilesAndFolders({ | ||
| params, | ||
| }); | ||
| return resources.map(mapper); | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| getUrl(path) { | ||
| const baseUrl = constants.BASE_URL | ||
| .replace(constants.SUBDOMAIN_PLACEHOLDER, this.$auth.subdomain); | ||
| return `${baseUrl}${path}`; | ||
| }, | ||
| getHeaders(headers) { | ||
| return { | ||
| "Content-Type": "application/json", | ||
| "Accept": "application/json", | ||
| "Authorization": this.$auth.oauth_access_token, | ||
| ...headers, | ||
| }; | ||
| }, | ||
| getConfig({ | ||
| headers, data: preData, ...args | ||
| } = {}) { | ||
| const contentType = constants.CONTENT_TYPE_KEY_HEADER; | ||
| const hasMultipartHeader = utils.hasMultipartHeader(headers); | ||
| const data = hasMultipartHeader && utils.getFormData(preData) || preData; | ||
| const currentHeaders = this.getHeaders(headers); | ||
|
|
||
| return { | ||
| headers: hasMultipartHeader | ||
| ? { | ||
| ...currentHeaders, | ||
| [contentType]: data.getHeaders()[contentType.toLowerCase()], | ||
| } | ||
| : currentHeaders, | ||
| data, | ||
| ...args, | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, headers, ...args | ||
| } = {}) { | ||
| const config = this.getConfig({ | ||
| url: this.getUrl(path), | ||
| headers: this.getHeaders(headers), | ||
| ...args, | ||
| }); | ||
| return axios($, config); | ||
| }, | ||
| post(args = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| ...args, | ||
| }); | ||
| }, | ||
| listMyFilesAndFolders(args = {}) { | ||
| return this._makeRequest({ | ||
| path: "/files/@my", | ||
| ...args, | ||
| }); | ||
| }, | ||
| searchUsersByExtendedFilter(args = {}) { | ||
| return this._makeRequest({ | ||
| path: "/people/simple/filter", | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.