Skip to content

Commit

Permalink
#938 - pCloud new actions and source (#3240)
Browse files Browse the repository at this point in the history
* [App:pCloud] Importing changes from PR #1392

* [App:pCloud] Description adjustments

* [App:pCloud] Syntax adjustments

* [App:pCloud] Linking doc in description

* [App:pCloud] Creating common action and $summary

* [App;pCloud] Improving prop sharing and naming

* [App:pCloud] Further refining descriptions, plus fixes

* [App:pCloud] Prop sharing improvements

* [App:pCloud] Customizing shared prop descriptions per component

* [App:pCloud] Creating location validation

* Initial PR adjustments

* [App:pCloud] Creating file validation

* [App:pCloud] Watch folder improvements

* [App:pCloud] Description updates

* [App:pCloud] Including docs in descriptions

* pnpm-lock.yaml pCloud #938

* [App:pCloud] Code review requested adjustments #1

* [App:pCloud] Adjusting custom description props

* [App:pCloud] Changing common props to propDefinitions

* [App:pCloud] Code review adjustments

* [App:pCloud] Fixing await inside try/catch
  • Loading branch information
GTFalcao committed Jul 1, 2022
1 parent 23c7caf commit ee6395d
Show file tree
Hide file tree
Showing 11 changed files with 2,186 additions and 103 deletions.
43 changes: 43 additions & 0 deletions components/pcloud/actions/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pcloud from "../../pcloud.app.mjs";

export default {
props: {
pcloud,
},
methods: {
validateLocationId() {
const VALID_LOCATIONS = [
"0",
"1",
];
const locationId = this.pcloud.$auth.locationid;

if (!VALID_LOCATIONS.includes(locationId)) {
return "Unable to retrieve your account's Location ID - try reconnecting your pCloud account to Pipedream";
}

return true;
},
async validateInputs() {
return true;
},
},
async run({ $ }) {
const validations = [
this.validateLocationId(),
await this.validateInputs(),
];

const errors = validations.filter((result) => result !== true);
if (errors.length) {
throw new Error(errors.join("; "));
}

const requestMethod = this.requestMethod;
const response = await this.pcloud._withRetries(() => requestMethod());

$.export("$summary", this.getSummary());

return response;
},
};
76 changes: 76 additions & 0 deletions components/pcloud/actions/copy-file/copy-file.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import pcloud from "../../pcloud.app.mjs";
import common from "../common/base.mjs";

export default {
...common,
key: "pcloud-copy-file",
name: "Copy File",
description:
"Copy a file to the specified destination. [See the docs here](https://docs.pcloud.com/methods/file/copyfile.html)",
version: "0.0.1",
type: "action",
props: {
...common.props,
fileId: {
propDefinition: [
pcloud,
"fileId",
],
description: `Select a **File** to copy.
\\
Alternatively, you can provide a custom *File ID*.`,
},
toFolderId: {
propDefinition: [
pcloud,
"folderId",
],
label: "Destination Folder ID",
description: `Select a **Destination Folder** to receive the copied file.
\\
Alternatively, you can provide a custom *Folder ID*.`,
},
name: {
propDefinition: [
pcloud,
"name",
],
label: "New File Name",
description: "Name of the destination file.",
},
overwrite: {
propDefinition: [
pcloud,
"overwrite",
],
},
modifiedTime: {
propDefinition: [
pcloud,
"modifiedTime",
],
},
createdTime: {
propDefinition: [
pcloud,
"createdTime",
],
},
},
methods: {
...common.methods,
getSummary() {
return `Copied file "${this.name}" successfully`;
},
async requestMethod() {
return this.pcloud.copyFile(
this.fileId,
this.toFolderId,
this.name,
!this.overwrite,
this.modifiedTime,
this.createdTime,
);
},
},
};
61 changes: 61 additions & 0 deletions components/pcloud/actions/copy-folder/copy-folder.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import pcloud from "../../pcloud.app.mjs";
import common from "../common/base.mjs";

export default {
...common,
key: "pcloud-copy-folder",
name: "Copy Folder",
description: "Copy a folder to the specified folder. [See the docs here](https://docs.pcloud.com/methods/folder/copyfolder.html)",
version: "0.0.1",
type: "action",
props: {
...common.props,
folderId: {
propDefinition: [
pcloud,
"folderId",
],
description: `Select a **Folder** to copy.
\\
Alternatively, you can provide a custom *Folder ID*.`,
},
toFolderId: {
propDefinition: [
pcloud,
"folderId",
],
label: "Destination Folder ID",
description: `Select a **Destination Folder** where the folder will be copied to.
\\
Alternatively, you can provide a custom *Folder ID*.`,
},
overwrite: {
propDefinition: [
pcloud,
"overwrite",
],
},
copyContentOnly: {
type: "boolean",
label: "Copy Content Only?",
description:
"If true, only the contents of source folder will be copied, otherwise the folder itself is copied.",
default: false,
optional: true,
},
},
methods: {
...common.methods,
getSummary() {
return "Copied folder successfully";
},
async requestMethod() {
return this.pcloud.copyFolder(
this.folderId,
this.toFolderId,
!this.overwrite,
this.copyContentOnly,
);
},
},
};
40 changes: 40 additions & 0 deletions components/pcloud/actions/create-folder/create-folder.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pcloud from "../../pcloud.app.mjs";
import common from "../common/base.mjs";

export default {
...common,
key: "pcloud-create-folder",
name: "Create Folder",
description:
"Create a folder in the specified folder. [See the docs here](https://docs.pcloud.com/methods/folder/createfolder.html)",
version: "0.0.1",
type: "action",
props: {
...common.props,
folderId: {
propDefinition: [
pcloud,
"folderId",
],
description: `Select a **Folder** to create the new folder within.
\\
Alternatively, you can provide a custom *Folder ID*.`,
label: "Parent Folder ID",
},
name: {
propDefinition: [
pcloud,
"name",
],
},
},
methods: {
...common.methods,
getSummary() {
return `Created folder "${this.name}" successfully`;
},
async requestMethod() {
return this.pcloud.createFolder(this.name, this.folderId);
},
},
};
37 changes: 37 additions & 0 deletions components/pcloud/actions/download-files/download-files.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pcloud from "../../pcloud.app.mjs";
import common from "../common/base.mjs";

export default {
...common,
key: "pcloud-download-files",
name: "Download File(s)",
description: "Download one or more files to a folder. [See the docs here](https://docs.pcloud.com/methods/file/downloadfile.html)",
version: "0.0.1",
type: "action",
props: {
...common.props,
urls: {
type: "string[]",
label: "URLs",
description: "URL(s) of the files to download.",
},
folderId: {
propDefinition: [
pcloud,
"folderId",
],
description: `Select a **Folder** to receive the downloaded files.
\\
Alternatively, you can provide a custom *Folder ID*.`,
},
},
methods: {
...common.methods,
getSummary() {
return `Downloaded ${this.urls.length} files successfully`;
},
async requestMethod() {
return this.pcloud.downloadFiles(this.urls, this.folderId);
},
},
};
64 changes: 64 additions & 0 deletions components/pcloud/actions/list-contents/list-contents.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import pcloud from "../../pcloud.app.mjs";
import common from "../common/base.mjs";

export default {
...common,
key: "pcloud-list-contents",
name: "List Contents",
description: "Get the contents of the specified folder. [See the docs here](https://docs.pcloud.com/methods/folder/listfolder.html)",
version: "0.0.1",
type: "action",
props: {
...common.props,
folderId: {
propDefinition: [
pcloud,
"folderId",
],
description: `Select a **Folder** to get the contents of.
\\
Alternatively, you can provide a custom *Folder ID*.`,
},
recursive: {
type: "boolean",
label: "Recursive?",
description:
"If true, returns contents of the folder **and all subfolders,** recursively.",
default: false,
},
showDeleted: {
propDefinition: [
pcloud,
"showDeleted",
],
},
noFiles: {
type: "boolean",
label: "Folders Only?",
description:
"If true, only the **folder** (sub)structure will be returned.",
default: false,
},
noShares: {
type: "boolean",
label: "Exclude Shares?",
description: "If true, excludes shared files and folders.",
default: true,
},
},
methods: {
...common.methods,
getSummary() {
return "Listed folder contents successfully";
},
async requestMethod() {
return this.pcloud.listContents(
this.folderId,
this.recursive,
this.showDeleted,
this.noFiles,
this.noShares,
);
},
},
};

1 comment on commit ee6395d

@vercel
Copy link

@vercel vercel bot commented on ee6395d Jul 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.