Skip to content

Commit ddf0835

Browse files
authored
Merging pull request #18495
1 parent 3bda4ca commit ddf0835

File tree

8 files changed

+239
-140
lines changed

8 files changed

+239
-140
lines changed

components/zoho_workdrive/actions/download-file/download-file.mjs

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import app from "../../zoho_workdrive.app.mjs";
22
import { getFilePath } from "../../common/utils.mjs";
33
import { LIMIT } from "../../common/constants.mjs";
4+
import {
5+
additionalFolderProps, findMaxFolderId,
6+
} from "../../common/additionalFolderProps.mjs";
47
import fs from "fs";
58

69
export default {
710
key: "zoho_workdrive-download-file",
811
name: "Download File to Tmp Direcory",
912
description: "Download a file to the /tmp directory. [See the documentation](https://workdrive.zoho.com/apidocs/v1/filesfolders/downloadserverfile)",
10-
version: "0.0.5",
13+
version: "0.0.6",
1114
type: "action",
1215
props: {
1316
app,
@@ -34,21 +37,37 @@ export default {
3437
folderType,
3538
}),
3639
],
37-
label: "Folder Id",
38-
description: "The unique ID of the folder where file is located.",
40+
label: "Folder ID",
41+
description: "The unique ID of the folder where file is located. Select a folder to view its subfolders.",
42+
reloadProps: true,
3943
},
40-
fileId: {
44+
syncDir: {
45+
type: "dir",
46+
accessMode: "write",
47+
sync: true,
48+
},
49+
},
50+
async additionalProps() {
51+
const folderProps = await additionalFolderProps.call(this);
52+
const props = {
53+
...folderProps,
54+
};
55+
props.fileId = {
4156
type: "string",
42-
label: "File Id",
57+
label: "File ID",
4358
description: "The unique ID of the file to download.",
4459
withLabel: true,
45-
async options({ page }) {
60+
options: async ({ page }) => {
61+
const num = this.findMaxFolderId(this);
62+
const limit = this.getLimit();
4663
const { data } = await this.app.listFiles({
47-
folderId: this.folderId,
64+
folderId: num > 0
65+
? this[`folderId${num}`]
66+
: this.folderId,
4867
filter: "allfiles",
4968
params: new URLSearchParams({
50-
"page[limit]": LIMIT,
51-
"page[offset]": LIMIT * page,
69+
"page[limit]": limit,
70+
"page[offset]": limit * page,
5271
}).toString(),
5372
});
5473
return data.map(({
@@ -58,17 +77,19 @@ export default {
5877
label: attributes.name,
5978
}));
6079
},
61-
},
62-
fileName: {
80+
};
81+
props.fileName = {
6382
type: "string",
6483
label: "Filename",
6584
description: "What to name the new file saved to /tmp directory",
6685
optional: true,
67-
},
68-
syncDir: {
69-
type: "dir",
70-
accessMode: "write",
71-
sync: true,
86+
};
87+
return props;
88+
},
89+
methods: {
90+
findMaxFolderId,
91+
getLimit() {
92+
return LIMIT;
7293
},
7394
},
7495
async run({ $ }) {

components/zoho_workdrive/actions/upload-file/upload-file.mjs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { getFileStreamAndMetadata } from "@pipedream/platform";
22
import FormData from "form-data";
33
import app from "../../zoho_workdrive.app.mjs";
4+
import {
5+
additionalFolderProps, findMaxFolderId,
6+
} from "../../common/additionalFolderProps.mjs";
47

58
export default {
69
key: "zoho_workdrive-upload-file",
710
name: "Upload File",
8-
version: "0.0.7",
11+
version: "0.0.8",
912
description: "Upload a new file to your WorkDrive account. [See the documentation](https://workdrive.zoho.com/apidocs/v1/chunkupload/chunkuploadcreatesession)",
1013
type: "action",
1114
props: {
@@ -33,6 +36,7 @@ export default {
3336
folderType,
3437
}),
3538
],
39+
reloadProps: true,
3640
},
3741
filename: {
3842
label: "Filename",
@@ -58,6 +62,9 @@ export default {
5862
optional: true,
5963
},
6064
},
65+
async additionalProps() {
66+
return additionalFolderProps.call(this);
67+
},
6168
async run({ $ }) {
6269
const {
6370
stream, metadata,
@@ -70,7 +77,12 @@ export default {
7077
});
7178
const override = this.overrideNameExist?.toString();
7279

73-
data.append("parent_id", this.parentId);
80+
const num = findMaxFolderId(this);
81+
const parentId = num > 0
82+
? this[`folderId${num}`]
83+
: this.parentId;
84+
85+
data.append("parent_id", parentId);
7486
if (this.filename) data.append("filename", this.filename);
7587
if (override) data.append("override-name-exist", override);
7688

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
async function additionalFolderProps() {
2+
const props = {};
3+
const rootFolderId = this.folderId || this.parentId;
4+
if (!rootFolderId) {
5+
return props;
6+
}
7+
8+
const { data: rootSubfolders } = await this.app.listFiles({
9+
folderId: rootFolderId,
10+
});
11+
12+
if (!rootSubfolders.length) {
13+
return props;
14+
}
15+
16+
props["folderId1"] = {
17+
type: "string",
18+
label: "Folder 2 ID",
19+
description: "The unique ID of the subfolder. Select a folder to view its subfolders.",
20+
options: rootSubfolders.map(({
21+
id, attributes: { name },
22+
}) => ({
23+
value: id,
24+
label: name,
25+
})),
26+
optional: true,
27+
reloadProps: true,
28+
};
29+
30+
const num = findMaxFolderId(this);
31+
32+
if (num < 1) {
33+
return props;
34+
}
35+
36+
for (let i = 2; i <= num + 1; i++) {
37+
const { data: subfolders } = await this.app.listFiles({
38+
folderId: this[`folderId${i - 1}`],
39+
});
40+
41+
if (!subfolders.length) {
42+
return props;
43+
}
44+
45+
props[`folderId${i}`] = {
46+
type: "string",
47+
label: `Folder ${i + 1} ID`,
48+
description: `The unique ID of the subfolder ${i + 1}. Select a folder to view its subfolders.`,
49+
options: subfolders.map(({
50+
id, attributes: { name },
51+
}) => ({
52+
value: id,
53+
label: name,
54+
})),
55+
optional: true,
56+
reloadProps: true,
57+
};
58+
}
59+
60+
return props;
61+
}
62+
63+
function findMaxFolderId(obj) {
64+
let maxNum = -Infinity;
65+
66+
Object.keys(obj).forEach((key) => {
67+
const match = key.match(/^(folderId(\d*)|parentId)$/);
68+
if (match) {
69+
const num = match[2] === undefined || match[2] === ""
70+
? 0
71+
: parseInt(match[2], 10);
72+
if (num > maxNum) {
73+
maxNum = num;
74+
}
75+
}
76+
});
77+
78+
return maxNum;
79+
}
80+
81+
export {
82+
additionalFolderProps,
83+
findMaxFolderId,
84+
};

components/zoho_workdrive/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/zoho_workdrive",
3-
"version": "0.2.6",
3+
"version": "0.2.7",
44
"description": "Pipedream Zoho WorkDrive Components",
55
"main": "zoho_workdrive.app.mjs",
66
"keywords": [
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import app from "../../zoho_workdrive.app.mjs";
3+
import { additionalFolderProps } from "../../common/additionalFolderProps.mjs";
4+
5+
export default {
6+
props: {
7+
app,
8+
db: "$.service.db",
9+
timer: {
10+
label: "Polling interval",
11+
description: "Pipedream will poll the Zoho WorkDrive on this schedule",
12+
type: "$.interface.timer",
13+
default: {
14+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
15+
},
16+
},
17+
teamId: {
18+
propDefinition: [
19+
app,
20+
"teamId",
21+
],
22+
},
23+
},
24+
async additionalProps() {
25+
return additionalFolderProps.call(this);
26+
},
27+
methods: {
28+
_getLastDate() {
29+
return this.db.get("lastDate") || 0;
30+
},
31+
_setLastDate(lastDate) {
32+
this.db.set("lastDate", lastDate);
33+
},
34+
},
35+
async run() {
36+
await this.startEvent();
37+
},
38+
};

0 commit comments

Comments
 (0)