Skip to content
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

New Components - egnyte #15301

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions components/egnyte/actions/create-folder/create-folder.mjs
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;
},
};
60 changes: 60 additions & 0 deletions components/egnyte/actions/upload-file/upload-file.mjs
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;
},
};
56 changes: 52 additions & 4 deletions components/egnyte/egnyte.app.mjs
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,
});
},
},
};
11 changes: 9 additions & 2 deletions components/egnyte/package.json
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": [
Expand All @@ -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"
}
}
}
80 changes: 80 additions & 0 deletions components/egnyte/sources/common/base.mjs
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);
},
};
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 components/egnyte/sources/new-folder-added/new-folder-added.mjs
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,
};
},
},
};
25 changes: 24 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading