-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - egnyte #15301
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
Merged
New Components - egnyte #15301
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
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,28 @@ | ||
import egnyte from "../../egnyte.app.mjs"; | ||
|
||
export default { | ||
key: "egnyte-create-folder", | ||
name: "Create Folder", | ||
description: "Creates a new folder in your Egnyte workspace. [See the documentation](https://developers.egnyte.com/docs/File_System_Management_API_Documentation#Create-a-Folder)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
egnyte, | ||
folderPath: { | ||
type: "string", | ||
label: "Folder Path", | ||
description: "The full path to the new folder. Example: `/Shared/test`", | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const folderPath = this.folderPath[0] === "/" | ||
? this.folderPath.slice(1) | ||
: this.folderPath; | ||
const response = await this.egnyte.createFolder({ | ||
$, | ||
folderPath, | ||
}); | ||
$.export("$summary", `Created folder "${this.folderPath}"`); | ||
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,60 @@ | ||
import egnyte from "../../egnyte.app.mjs"; | ||
import FormData from "form-data"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import mime from "mime"; | ||
|
||
export default { | ||
key: "egnyte-upload-file", | ||
name: "Upload File", | ||
description: "Uploads a file to a specified folder in Egnyte. [See the documentation](https://developers.egnyte.com/docs/File_System_Management_API_Documentation#Upload-a-File)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
egnyte, | ||
filePath: { | ||
type: "string", | ||
label: "File Path", | ||
description: "The path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)", | ||
}, | ||
folderPath: { | ||
type: "string", | ||
label: "Folder Path", | ||
description: "The full path to the folder where the file should be uploaded. Example: `/Shared/Documents", | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const form = new FormData(); | ||
|
||
const filePath = this.filePath.includes("tmp/") | ||
? this.filePath | ||
: `/tmp/${this.filePath}`; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const filename = path.basename(filePath); | ||
const contentType = mime.getType(filePath) || "application/octet-stream"; | ||
|
||
form.append("file", fs.createReadStream(filePath), { | ||
filename, | ||
contentType, | ||
}); | ||
|
||
let folderPath = this.folderPath; | ||
if (folderPath.startsWith("/")) { | ||
folderPath = folderPath.slice(1); | ||
} | ||
if (folderPath.endsWith("/")) { | ||
folderPath = folderPath.slice(0, -1); | ||
} | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const response = await this.egnyte.uploadFile({ | ||
$, | ||
folderPath, | ||
filename, | ||
data: form, | ||
headers: form.getHeaders(), | ||
}); | ||
|
||
$.export("$summary", `Successfully uploaded file ${filename}`); | ||
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 |
---|---|---|
@@ -1,11 +1,59 @@ | ||
import { axios } from "@pipedream/platform"; | ||
import Bottleneck from "bottleneck"; | ||
const limiter = new Bottleneck({ | ||
minTime: 500, // 2 requests per second | ||
maxConcurrent: 1, | ||
}); | ||
const axiosRateLimiter = limiter.wrap(axios); | ||
|
||
export default { | ||
type: "app", | ||
app: "egnyte", | ||
propDefinitions: {}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return `https://${this.$auth.subdomain}.egnyte.com/pubapi/v1`; | ||
}, | ||
_makeRequest({ | ||
$ = this, | ||
path, | ||
headers, | ||
...otherOpts | ||
}) { | ||
const config = { | ||
url: `${this._baseUrl()}${path}`, | ||
headers: { | ||
...headers, | ||
Authorization: `Bearer ${this.$auth.oauth_access_token}`, | ||
}, | ||
...otherOpts, | ||
}; | ||
return axiosRateLimiter($, config); | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
getFolder({ | ||
folderPath, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/fs/${folderPath}`, | ||
...opts, | ||
}); | ||
}, | ||
createFolder({ folderPath }) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: `/fs/${folderPath}`, | ||
data: { | ||
action: "add_folder", | ||
}, | ||
}); | ||
}, | ||
uploadFile({ | ||
folderPath, filename, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: `/fs-content/${folderPath}/${filename}`, | ||
...opts, | ||
}); | ||
}, | ||
}, | ||
}; |
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,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/egnyte", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream Egnyte Components", | ||
"main": "egnyte.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,12 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3", | ||
"bottleneck": "^2.19.5", | ||
"form-data": "^4.0.1", | ||
"mime": "^4.0.6", | ||
"path": "^0.12.7" | ||
} | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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,80 @@ | ||
import egnyte from "../../egnyte.app.mjs"; | ||
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
|
||
export default { | ||
props: { | ||
egnyte, | ||
db: "$.service.db", | ||
timer: { | ||
type: "$.interface.timer", | ||
default: { | ||
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
}, | ||
}, | ||
folderPath: { | ||
type: "string", | ||
label: "Folder Path", | ||
description: "The folder path (example: `/Shared/Documents`) to watch for updates.", | ||
}, | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
methods: { | ||
_getLastTs() { | ||
return this.db.get("lastTs") || 0; | ||
}, | ||
_setLastTs(lastTs) { | ||
this.db.set("lastTs", lastTs); | ||
}, | ||
getResourceType() { | ||
throw new Error("getResourceType is not implemented"); | ||
}, | ||
generateMeta() { | ||
throw new Error("generateMeta is not implemented"); | ||
}, | ||
}, | ||
async run() { | ||
const lastTs = this._getLastTs(); | ||
let maxTs = lastTs; | ||
const resourceType = this.getResourceType(); | ||
|
||
// Recursively process folder and subfolders | ||
const processFolder = async (folderPath) => { | ||
const results = await this.egnyte.getFolder({ | ||
folderPath, | ||
params: { | ||
sort_by: "last_modified", | ||
sort_direction: "descending", | ||
}, | ||
}); | ||
|
||
const items = results[resourceType]; | ||
if (!items?.length) { | ||
return; | ||
} | ||
const newItems = []; | ||
|
||
for (const item of items) { | ||
const ts = item.uploaded; | ||
if (ts >= lastTs) { | ||
newItems.push(item); | ||
maxTs = Math.max(ts, maxTs); | ||
} | ||
} | ||
|
||
const folders = results.folders; | ||
if (folders?.length) { | ||
for (const folder of folders) { | ||
await processFolder(folder.path); | ||
} | ||
} | ||
|
||
newItems.reverse().forEach((item) => { | ||
const meta = this.generateMeta(item); | ||
this.$emit(item, meta); | ||
}); | ||
}; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
await processFolder(this.folderPath); | ||
|
||
this._setLastTs(maxTs); | ||
}, | ||
}; |
24 changes: 24 additions & 0 deletions
24
components/egnyte/sources/new-file-in-folder/new-file-in-folder.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,24 @@ | ||
import common from "../common/base.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "egnyte-new-file-in-folder", | ||
name: "New File in Folder", | ||
description: "Emit new event when a file is added within the specified folder in Egnyte. [See the documentation](https://developers.egnyte.com/docs/read/File_System_Management_API_Documentation#List-File-or-Folder)", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
methods: { | ||
...common.methods, | ||
getResourceType() { | ||
return "files"; | ||
}, | ||
generateMeta(file) { | ||
return { | ||
id: file.entry_id, | ||
summary: `New file: ${file.name}`, | ||
ts: file.uploaded, | ||
}; | ||
}, | ||
}, | ||
}; |
24 changes: 24 additions & 0 deletions
24
components/egnyte/sources/new-folder-added/new-folder-added.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,24 @@ | ||
import common from "../common/base.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "egnyte-new-folder-added", | ||
name: "New Folder", | ||
description: "Emit new event when a folder is added within the specified folder in Egnyte. [See the documentation](https://developers.egnyte.com/docs/read/File_System_Management_API_Documentation#List-File-or-Folder).", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
methods: { | ||
...common.methods, | ||
getResourceType() { | ||
return "folders"; | ||
}, | ||
generateMeta(folder) { | ||
return { | ||
id: folder.folder_id, | ||
summary: `New folder: ${folder.name}`, | ||
ts: folder.uploaded, | ||
}; | ||
}, | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.