Skip to content

Commit ffe0e43

Browse files
committed
new components
1 parent 64e26d9 commit ffe0e43

File tree

8 files changed

+190
-310
lines changed

8 files changed

+190
-310
lines changed
Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
import egnyte from "../../egnyte.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "egnyte-create-folder",
65
name: "Create Folder",
7-
description: "Creates a new folder in your Egnyte workspace. [See the documentation]()",
8-
version: "0.0.{{ts}}",
6+
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)",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
egnyte,
12-
newFolderName: {
13-
propDefinition: [
14-
egnyte,
15-
"newFolderName",
16-
],
17-
},
18-
parentFolderId: {
19-
propDefinition: [
20-
egnyte,
21-
"parentFolderId",
22-
],
23-
optional: true,
11+
folderPath: {
12+
type: "string",
13+
label: "Folder Path",
14+
description: "The full path to the new folder. Example: `/Shared/test`",
2415
},
2516
},
2617
async run({ $ }) {
18+
const folderPath = this.folderPath[0] === "/"
19+
? this.folderPath.slice(1)
20+
: this.folderPath;
2721
const response = await this.egnyte.createFolder({
28-
folderName: this.newFolderName,
29-
parentFolderId: this.parentFolderId,
22+
$,
23+
folderPath,
3024
});
31-
$.export("$summary", `Created folder "${this.newFolderName}"`);
25+
$.export("$summary", `Created folder "${this.folderPath}"`);
3226
return response;
3327
},
3428
};
Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,60 @@
11
import egnyte from "../../egnyte.app.mjs";
2-
import { axios } from "@pipedream/platform";
2+
import FormData from "form-data";
3+
import fs from "fs";
4+
import path from "path";
5+
import mime from "mime";
36

47
export default {
58
key: "egnyte-upload-file",
69
name: "Upload File",
7-
description: "Uploads a file to a specified folder in Egnyte. [See the documentation]()",
8-
version: "0.0.{{ts}}",
10+
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)",
11+
version: "0.0.1",
912
type: "action",
1013
props: {
1114
egnyte,
12-
uploadFileContent: {
13-
propDefinition: [
14-
egnyte,
15-
"uploadFileContent",
16-
],
15+
filePath: {
16+
type: "string",
17+
label: "File Path",
18+
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)",
1719
},
18-
uploadFolderId: {
19-
propDefinition: [
20-
egnyte,
21-
"uploadFolderId",
22-
],
23-
},
24-
uploadFileName: {
25-
propDefinition: [
26-
egnyte,
27-
"uploadFileName",
28-
],
29-
optional: true,
20+
folderPath: {
21+
type: "string",
22+
label: "Folder Path",
23+
description: "The full path to the folder where the file should be uploaded. Example: `/Shared/Documents",
3024
},
3125
},
3226
async run({ $ }) {
27+
const form = new FormData();
28+
29+
const filePath = this.filePath.includes("tmp/")
30+
? this.filePath
31+
: `/tmp/${this.filePath}`;
32+
33+
const filename = path.basename(filePath);
34+
const contentType = mime.getType(filePath) || "application/octet-stream";
35+
36+
form.append("file", fs.createReadStream(filePath), {
37+
filename,
38+
contentType,
39+
});
40+
41+
let folderPath = this.folderPath;
42+
if (folderPath.startsWith("/")) {
43+
folderPath = folderPath.slice(1);
44+
}
45+
if (folderPath.endsWith("/")) {
46+
folderPath = folderPath.slice(0, -1);
47+
}
48+
3349
const response = await this.egnyte.uploadFile({
34-
fileContent: this.uploadFileContent,
35-
uploadFolderId: this.uploadFolderId,
36-
fileName: this.uploadFileName,
50+
$,
51+
folderPath,
52+
filename,
53+
data: form,
54+
headers: form.getHeaders(),
3755
});
38-
$.export("$summary", `Uploaded file ${this.uploadFileName || "uploaded_file"} to folder ID ${this.uploadFolderId}`);
56+
57+
$.export("$summary", `Successfully uploaded file ${filename}`);
3958
return response;
4059
},
4160
};

components/egnyte/egnyte.app.mjs

Lines changed: 24 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -3,125 +3,55 @@ import { axios } from "@pipedream/platform";
33
export default {
44
type: "app",
55
app: "egnyte",
6-
version: "0.0.{{ts}}",
7-
propDefinitions: {
8-
monitoredFolderPath: {
9-
type: "string",
10-
label: "Folder Path to Monitor",
11-
description: "The path of the folder to monitor for new files, e.g., /Shared/Documents.",
12-
},
13-
newFolderName: {
14-
type: "string",
15-
label: "Folder Name",
16-
description: "The name of the new folder to create.",
17-
},
18-
parentFolderId: {
19-
type: "string",
20-
label: "Parent Folder ID",
21-
description: "The ID of the parent folder. Leave blank to create in the root directory.",
22-
optional: true,
23-
},
24-
uploadFileContent: {
25-
type: "string",
26-
label: "File Content",
27-
description: "The base64 encoded content of the file to upload.",
28-
},
29-
uploadFolderId: {
30-
type: "string",
31-
label: "Upload Folder ID",
32-
description: "The ID of the folder where the file will be uploaded.",
33-
},
34-
uploadFileName: {
35-
type: "string",
36-
label: "File Name",
37-
description: "The name of the file. Leave blank to use a default name.",
38-
optional: true,
39-
},
40-
},
416
methods: {
42-
authKeys() {
43-
console.log(Object.keys(this.$auth));
44-
},
457
_baseUrl() {
46-
return `https://${this.$auth.domain}.egnyte.com/pubapi/v1`;
8+
return `https://${this.$auth.subdomain}.egnyte.com/pubapi/v1`;
479
},
48-
async _makeRequest(opts = {}) {
49-
const {
50-
$, method = "GET", path = "/", headers, ...otherOpts
51-
} = opts;
10+
_makeRequest({
11+
$ = this,
12+
path,
13+
headers,
14+
...otherOpts
15+
}) {
5216
return axios($ || this, {
53-
method,
54-
url: this._baseUrl() + path,
17+
url: `${this._baseUrl()}${path}`,
5518
headers: {
5619
...headers,
5720
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
5821
},
5922
...otherOpts,
6023
});
6124
},
62-
async listSharedFolders(opts = {}) {
25+
createWebhook(opts = {}) {
6326
return this._makeRequest({
64-
method: "GET",
65-
path: "/fs/shared",
27+
method: "POST",
28+
path: "/webhooks",
6629
...opts,
6730
});
6831
},
69-
async monitorFolder({ folderPath }) {
32+
deleteWebhook({ hookId }) {
7033
return this._makeRequest({
71-
method: "GET",
72-
path: `/fs/${encodeURIComponent(folderPath)}/files`,
34+
method: "DELETE",
35+
path: `/webhooks/${hookId}`,
7336
});
7437
},
75-
async createFolder({
76-
folderName, parentFolderId,
77-
}) {
78-
const path = parentFolderId
79-
? `/fs/${encodeURIComponent(parentFolderId)}/folders`
80-
: "/fs/shared/folders";
81-
const data = {
82-
name: folderName,
83-
};
38+
createFolder({ folderPath }) {
8439
return this._makeRequest({
8540
method: "POST",
86-
path,
87-
data,
88-
});
89-
},
90-
async uploadFile({
91-
fileContent, uploadFolderId, fileName,
92-
}) {
93-
const name = fileName || "uploaded_file";
94-
const path = `/fs/${encodeURIComponent(uploadFolderId)}/files/${encodeURIComponent(name)}`;
95-
return this._makeRequest({
96-
method: "PUT",
97-
path,
98-
data: Buffer.from(fileContent, "base64"),
99-
headers: {
100-
"Content-Type": "application/octet-stream",
41+
path: `/fs/${folderPath}`,
42+
data: {
43+
action: "add_folder",
10144
},
10245
});
10346
},
104-
async listFolders({ folderPath }) {
105-
const path = `/fs/${encodeURIComponent(folderPath)}/folders`;
47+
uploadFile({
48+
folderPath, filename, ...opts
49+
}) {
10650
return this._makeRequest({
107-
method: "GET",
108-
path,
51+
method: "POST",
52+
path: `/fs-content/${folderPath}/${filename}`,
53+
...opts,
10954
});
11055
},
111-
async paginate(fn, ...opts) {
112-
let results = [];
113-
let response;
114-
let page = 1;
115-
while (true) {
116-
response = await fn({
117-
page,
118-
...opts,
119-
});
120-
if (!response.items || response.items.length === 0) break;
121-
results = results.concat(response.items);
122-
page += 1;
123-
}
124-
return results;
125-
},
12656
},
12757
};

components/egnyte/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/egnyte",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Egnyte Components",
55
"main": "egnyte.app.mjs",
66
"keywords": [
@@ -11,5 +11,11 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3",
17+
"form-data": "^4.0.1",
18+
"mime": "^4.0.6",
19+
"path": "^0.12.7"
1420
}
1521
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import egnyte from "../../egnyte.app.mjs";
2+
3+
export default {
4+
props: {
5+
egnyte,
6+
db: "$.service.db",
7+
http: {
8+
type: "$.interface.http",
9+
customResponse: true,
10+
},
11+
folderPaths: {
12+
type: "string[]",
13+
label: "Folder Paths",
14+
description: "An array of folder paths (example: `/Shared/Documents`) to watch for updates. You may specify up to 100 paths.",
15+
},
16+
},
17+
hooks: {
18+
async activate() {
19+
const { webhookId } = await this.egnyte.createWebhook({
20+
data: {
21+
url: this.http.endpoint,
22+
eventType: this.getEventType(),
23+
path: this.folderPaths.join(","),
24+
},
25+
});
26+
this._setHookId(webhookId);
27+
},
28+
async deactivate() {
29+
const hookId = this._getHookId();
30+
if (hookId) {
31+
await this.egnyte.deleteWebhook({
32+
hookId,
33+
});
34+
}
35+
},
36+
},
37+
methods: {
38+
_getHookId() {
39+
return this.db.get("hookId");
40+
},
41+
_setHookId(hookId) {
42+
this.db.set("hookId", hookId);
43+
},
44+
generateMeta() {
45+
throw new Error("generateMeta is not implemented");
46+
},
47+
getEventType() {
48+
throw new Error("getEventType is not implemented");
49+
},
50+
},
51+
async run(event) {
52+
this.http.respond({
53+
status: 200,
54+
});
55+
56+
const { body } = event;
57+
if (!body || !body?.length) {
58+
return;
59+
}
60+
61+
for (const item of body) {
62+
const meta = this.generateMeta(item); console.log(meta);
63+
this.$emit(item, meta);
64+
}
65+
},
66+
};

0 commit comments

Comments
 (0)