Skip to content

Commit ecbda37

Browse files
committed
updates
1 parent ffe0e43 commit ecbda37

File tree

4 files changed

+89
-73
lines changed

4 files changed

+89
-73
lines changed

components/egnyte/egnyte.app.mjs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import { axios } from "@pipedream/platform";
2+
import Bottleneck from "bottleneck";
3+
const limiter = new Bottleneck({
4+
minTime: 500, // 2 requests per second
5+
maxConcurrent: 1,
6+
});
7+
const axiosRateLimiter = limiter.wrap(axios);
28

39
export default {
410
type: "app",
@@ -13,28 +19,24 @@ export default {
1319
headers,
1420
...otherOpts
1521
}) {
16-
return axios($ || this, {
22+
const config = {
1723
url: `${this._baseUrl()}${path}`,
1824
headers: {
1925
...headers,
2026
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
2127
},
2228
...otherOpts,
23-
});
29+
};
30+
return axiosRateLimiter($, config);
2431
},
25-
createWebhook(opts = {}) {
32+
getFolder({
33+
folderPath, ...opts
34+
}) {
2635
return this._makeRequest({
27-
method: "POST",
28-
path: "/webhooks",
36+
path: `/fs/${folderPath}`,
2937
...opts,
3038
});
3139
},
32-
deleteWebhook({ hookId }) {
33-
return this._makeRequest({
34-
method: "DELETE",
35-
path: `/webhooks/${hookId}`,
36-
});
37-
},
3840
createFolder({ folderPath }) {
3941
return this._makeRequest({
4042
method: "POST",
Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,80 @@
11
import egnyte from "../../egnyte.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
23

34
export default {
45
props: {
56
egnyte,
67
db: "$.service.db",
7-
http: {
8-
type: "$.interface.http",
9-
customResponse: true,
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
1013
},
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-
}
14+
folderPath: {
15+
type: "string",
16+
label: "Folder Path",
17+
description: "The folder path (example: `/Shared/Documents`) to watch for updates.",
3518
},
3619
},
3720
methods: {
38-
_getHookId() {
39-
return this.db.get("hookId");
21+
_getLastTs() {
22+
return this.db.get("lastTs") || 0;
23+
},
24+
_setLastTs(lastTs) {
25+
this.db.set("lastTs", lastTs);
4026
},
41-
_setHookId(hookId) {
42-
this.db.set("hookId", hookId);
27+
getResourceType() {
28+
throw new Error("getResourceType is not implemented");
4329
},
4430
generateMeta() {
4531
throw new Error("generateMeta is not implemented");
4632
},
47-
getEventType() {
48-
throw new Error("getEventType is not implemented");
49-
},
5033
},
51-
async run(event) {
52-
this.http.respond({
53-
status: 200,
54-
});
34+
async run() {
35+
const lastTs = this._getLastTs();
36+
let maxTs = lastTs;
37+
const resourceType = this.getResourceType();
38+
39+
// Recursively process folder and subfolders
40+
const processFolder = async (folderPath) => {
41+
const results = await this.egnyte.getFolder({
42+
folderPath,
43+
params: {
44+
sort_by: "last_modified",
45+
sort_direction: "descending",
46+
},
47+
});
48+
49+
const items = results[resourceType];
50+
if (!items?.length) {
51+
return;
52+
}
53+
const newItems = [];
54+
55+
for (const item of items) {
56+
const ts = item.uploaded;
57+
if (ts >= lastTs) {
58+
newItems.push(item);
59+
maxTs = Math.max(ts, maxTs);
60+
}
61+
}
62+
63+
const folders = results.folders;
64+
if (folders?.length) {
65+
for (const folder of folders) {
66+
await processFolder(folder.path);
67+
}
68+
}
69+
70+
newItems.reverse().forEach((item) => {
71+
const meta = this.generateMeta(item);
72+
this.$emit(item, meta);
73+
});
74+
};
5575

56-
const { body } = event;
57-
if (!body || !body?.length) {
58-
return;
59-
}
76+
await processFolder(this.folderPath);
6077

61-
for (const item of body) {
62-
const meta = this.generateMeta(item); console.log(meta);
63-
this.$emit(item, meta);
64-
}
78+
this._setLastTs(maxTs);
6579
},
6680
};

components/egnyte/sources/new-file-in-folder/new-file-in-folder.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import common from "../common/base.mjs";
33
export default {
44
...common,
55
key: "egnyte-new-file-in-folder",
6-
name: "New File in Folder (Instant)",
7-
description: "Emit new event when a file is added to the specified folder(s) in Egnyte. [See the documentation](https://storage.googleapis.com/pint-internal-static-hosting/connectWebhooks/index.html#operation/registerWebhook)",
6+
name: "New File in Folder",
7+
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)",
88
version: "0.0.1",
99
type: "source",
1010
dedupe: "unique",
1111
methods: {
1212
...common.methods,
13-
getEventType() {
14-
return "fs:add_file";
13+
getResourceType() {
14+
return "files";
1515
},
16-
generateMeta(event) {
16+
generateMeta(file) {
1717
return {
18-
id: event.id,
19-
summary: "New File Added",
20-
ts: event.timestamp,
18+
id: file.entry_id,
19+
summary: `New file: ${file.name}`,
20+
ts: file.uploaded,
2121
};
2222
},
2323
},

components/egnyte/sources/new-folder-added/new-folder-added.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import common from "../common/base.mjs";
33
export default {
44
...common,
55
key: "egnyte-new-folder-added",
6-
name: "New Folder (Instant)",
7-
description: "Emit new event when a folder is added to the specified folder(s) in Egnyte. [See the documentation](https://storage.googleapis.com/pint-internal-static-hosting/connectWebhooks/index.html#operation/registerWebhook).",
6+
name: "New Folder",
7+
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).",
88
version: "0.0.1",
99
type: "source",
1010
dedupe: "unique",
1111
methods: {
1212
...common.methods,
13-
getEventType() {
14-
return "fs:add_folder";
13+
getResourceType() {
14+
return "folders";
1515
},
16-
generateMeta(event) {
16+
generateMeta(folder) {
1717
return {
18-
id: event.id,
19-
summary: "New Folder Added",
20-
ts: event.timestamp,
18+
id: folder.folder_id,
19+
summary: `New folder: ${folder.name}`,
20+
ts: folder.uploaded,
2121
};
2222
},
2323
},

0 commit comments

Comments
 (0)