Skip to content
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
53 changes: 37 additions & 16 deletions components/zoho_workdrive/actions/download-file/download-file.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import app from "../../zoho_workdrive.app.mjs";
import { getFilePath } from "../../common/utils.mjs";
import { LIMIT } from "../../common/constants.mjs";
import {
additionalFolderProps, findMaxFolderId,
} from "../../common/additionalFolderProps.mjs";
import fs from "fs";

export default {
key: "zoho_workdrive-download-file",
name: "Download File to Tmp Direcory",
description: "Download a file to the /tmp directory. [See the documentation](https://workdrive.zoho.com/apidocs/v1/filesfolders/downloadserverfile)",
version: "0.0.5",
version: "0.0.6",
type: "action",
props: {
app,
Expand All @@ -34,21 +37,37 @@ export default {
folderType,
}),
],
label: "Folder Id",
description: "The unique ID of the folder where file is located.",
label: "Folder ID",
description: "The unique ID of the folder where file is located. Select a folder to view its subfolders.",
reloadProps: true,
},
fileId: {
syncDir: {
type: "dir",
accessMode: "write",
sync: true,
},
},
async additionalProps() {
const folderProps = await additionalFolderProps.call(this);
const props = {
...folderProps,
};
props.fileId = {
type: "string",
label: "File Id",
label: "File ID",
description: "The unique ID of the file to download.",
withLabel: true,
async options({ page }) {
options: async ({ page }) => {
const num = this.findMaxFolderId(this);
const limit = this.getLimit();
const { data } = await this.app.listFiles({
folderId: this.folderId,
folderId: num > 0
? this[`folderId${num}`]
: this.folderId,
filter: "allfiles",
params: new URLSearchParams({
"page[limit]": LIMIT,
"page[offset]": LIMIT * page,
"page[limit]": limit,
"page[offset]": limit * page,
}).toString(),
});
return data.map(({
Expand All @@ -58,17 +77,19 @@ export default {
label: attributes.name,
}));
},
},
fileName: {
};
props.fileName = {
type: "string",
label: "Filename",
description: "What to name the new file saved to /tmp directory",
optional: true,
},
syncDir: {
type: "dir",
accessMode: "write",
sync: true,
};
return props;
},
methods: {
findMaxFolderId,
getLimit() {
return LIMIT;
},
},
async run({ $ }) {
Expand Down
16 changes: 14 additions & 2 deletions components/zoho_workdrive/actions/upload-file/upload-file.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { getFileStreamAndMetadata } from "@pipedream/platform";
import FormData from "form-data";
import app from "../../zoho_workdrive.app.mjs";
import {
additionalFolderProps, findMaxFolderId,
} from "../../common/additionalFolderProps.mjs";

export default {
key: "zoho_workdrive-upload-file",
name: "Upload File",
version: "0.0.7",
version: "0.0.8",
description: "Upload a new file to your WorkDrive account. [See the documentation](https://workdrive.zoho.com/apidocs/v1/chunkupload/chunkuploadcreatesession)",
type: "action",
props: {
Expand Down Expand Up @@ -33,6 +36,7 @@ export default {
folderType,
}),
],
reloadProps: true,
},
filename: {
label: "Filename",
Expand All @@ -58,6 +62,9 @@ export default {
optional: true,
},
},
async additionalProps() {
return additionalFolderProps.call(this);
},
async run({ $ }) {
const {
stream, metadata,
Expand All @@ -70,7 +77,12 @@ export default {
});
const override = this.overrideNameExist?.toString();

data.append("parent_id", this.parentId);
const num = findMaxFolderId(this);
const parentId = num > 0
? this[`folderId${num}`]
: this.parentId;

data.append("parent_id", parentId);
if (this.filename) data.append("filename", this.filename);
if (override) data.append("override-name-exist", override);

Expand Down
84 changes: 84 additions & 0 deletions components/zoho_workdrive/common/additionalFolderProps.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
async function additionalFolderProps() {
const props = {};
const rootFolderId = this.folderId || this.parentId;
if (!rootFolderId) {
return props;
}

const { data: rootSubfolders } = await this.app.listFiles({
folderId: rootFolderId,
});

if (!rootSubfolders.length) {
return props;
}

props["folderId1"] = {
type: "string",
label: "Folder 2 ID",
description: "The unique ID of the subfolder. Select a folder to view its subfolders.",
options: rootSubfolders.map(({
id, attributes: { name },
}) => ({
value: id,
label: name,
})),
optional: true,
reloadProps: true,
};

const num = findMaxFolderId(this);

if (num < 1) {
return props;
}

for (let i = 2; i <= num + 1; i++) {
const { data: subfolders } = await this.app.listFiles({
folderId: this[`folderId${i - 1}`],
});

if (!subfolders.length) {
return props;
}

props[`folderId${i}`] = {
type: "string",
label: `Folder ${i + 1} ID`,
description: `The unique ID of the subfolder ${i + 1}. Select a folder to view its subfolders.`,
options: subfolders.map(({
id, attributes: { name },
}) => ({
value: id,
label: name,
})),
optional: true,
reloadProps: true,
};
}

return props;
}

function findMaxFolderId(obj) {
let maxNum = -Infinity;

Object.keys(obj).forEach((key) => {
const match = key.match(/^(folderId(\d*)|parentId)$/);
if (match) {
const num = match[2] === undefined || match[2] === ""
? 0
: parseInt(match[2], 10);
if (num > maxNum) {
maxNum = num;
}
}
});

return maxNum;
}

export {
additionalFolderProps,
findMaxFolderId,
};
2 changes: 1 addition & 1 deletion components/zoho_workdrive/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/zoho_workdrive",
"version": "0.2.6",
"version": "0.2.7",
"description": "Pipedream Zoho WorkDrive Components",
"main": "zoho_workdrive.app.mjs",
"keywords": [
Expand Down
38 changes: 38 additions & 0 deletions components/zoho_workdrive/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import app from "../../zoho_workdrive.app.mjs";
import { additionalFolderProps } from "../../common/additionalFolderProps.mjs";

export default {
props: {
app,
db: "$.service.db",
timer: {
label: "Polling interval",
description: "Pipedream will poll the Zoho WorkDrive on this schedule",
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
teamId: {
propDefinition: [
app,
"teamId",
],
},
},
async additionalProps() {
return additionalFolderProps.call(this);
},
methods: {
_getLastDate() {
return this.db.get("lastDate") || 0;
},
_setLastDate(lastDate) {
this.db.set("lastDate", lastDate);
},
},
async run() {
await this.startEvent();
},
};
Loading
Loading