-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* egnyte init * new components * updates * add bottleneck dependency * pnpm-lock.yaml * pnpm-lock.yaml
- Loading branch information
1 parent
781d6ec
commit ac79b00
Showing
8 changed files
with
301 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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}`; | ||
|
||
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); | ||
} | ||
|
||
const response = await this.egnyte.uploadFile({ | ||
$, | ||
folderPath, | ||
filename, | ||
data: form, | ||
headers: form.getHeaders(), | ||
}); | ||
|
||
$.export("$summary", `Successfully uploaded file ${filename}`); | ||
return response; | ||
}, | ||
}; |
This file contains 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); | ||
}, | ||
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 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" | ||
} | ||
} | ||
} |
This file contains 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.", | ||
}, | ||
}, | ||
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); | ||
}); | ||
}; | ||
|
||
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 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 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.