@pipedream/pcloud 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/common/base.mjs +1 -1
- package/actions/copy-file/copy-file.mjs +1 -1
- package/actions/copy-folder/copy-folder.mjs +1 -1
- package/actions/create-folder/create-folder.mjs +1 -1
- package/actions/download-files/download-files.mjs +1 -1
- package/actions/list-contents/list-contents.mjs +1 -1
- package/actions/move-file/move-file.mjs +45 -0
- package/actions/move-folder/move-folder.mjs +45 -0
- package/actions/rename-file/rename-file.mjs +43 -0
- package/actions/rename-folder/rename-folder.mjs +43 -0
- package/actions/upload-file/upload-file.mjs +1 -1
- package/package.json +1 -1
- package/pcloud.app.mjs +90 -0
- package/sources/watch-folder/watch-folder.mjs +47 -44
package/actions/common/base.mjs
CHANGED
|
@@ -6,7 +6,7 @@ export default {
|
|
|
6
6
|
key: "pcloud-copy-folder",
|
|
7
7
|
name: "Copy Folder",
|
|
8
8
|
description: "Copy a folder to the specified folder. [See the docs here](https://docs.pcloud.com/methods/folder/copyfolder.html)",
|
|
9
|
-
version: "0.0.
|
|
9
|
+
version: "0.0.3",
|
|
10
10
|
type: "action",
|
|
11
11
|
props: {
|
|
12
12
|
...common.props,
|
|
@@ -7,7 +7,7 @@ export default {
|
|
|
7
7
|
name: "Create Folder",
|
|
8
8
|
description:
|
|
9
9
|
"Create a folder in the specified folder. [See the docs here](https://docs.pcloud.com/methods/folder/createfolder.html)",
|
|
10
|
-
version: "0.0.
|
|
10
|
+
version: "0.0.3",
|
|
11
11
|
type: "action",
|
|
12
12
|
props: {
|
|
13
13
|
...common.props,
|
|
@@ -6,7 +6,7 @@ export default {
|
|
|
6
6
|
key: "pcloud-download-files",
|
|
7
7
|
name: "Download File(s)",
|
|
8
8
|
description: "Download one or more files to a folder. [See the docs here](https://docs.pcloud.com/methods/file/downloadfile.html)",
|
|
9
|
-
version: "0.0.
|
|
9
|
+
version: "0.0.3",
|
|
10
10
|
type: "action",
|
|
11
11
|
props: {
|
|
12
12
|
...common.props,
|
|
@@ -6,7 +6,7 @@ export default {
|
|
|
6
6
|
key: "pcloud-list-contents",
|
|
7
7
|
name: "List Contents",
|
|
8
8
|
description: "Get the contents of the specified folder. [See the docs here](https://docs.pcloud.com/methods/folder/listfolder.html)",
|
|
9
|
-
version: "0.0.
|
|
9
|
+
version: "0.0.3",
|
|
10
10
|
type: "action",
|
|
11
11
|
props: {
|
|
12
12
|
...common.props,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import pcloud from "../../pcloud.app.mjs";
|
|
2
|
+
import common from "../common/base.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
...common,
|
|
6
|
+
key: "pcloud-move-file",
|
|
7
|
+
name: "Move File",
|
|
8
|
+
description: "Moves a file to the specified destination. [See the docs here](https://docs.pcloud.com/methods/file/renamefile.html)",
|
|
9
|
+
version: "0.0.1",
|
|
10
|
+
type: "action",
|
|
11
|
+
props: {
|
|
12
|
+
...common.props,
|
|
13
|
+
fileId: {
|
|
14
|
+
propDefinition: [
|
|
15
|
+
pcloud,
|
|
16
|
+
"fileId",
|
|
17
|
+
],
|
|
18
|
+
description: `Select a **File** to move.
|
|
19
|
+
\\
|
|
20
|
+
Alternatively, you can provide a custom *File ID*.`,
|
|
21
|
+
},
|
|
22
|
+
toFolderId: {
|
|
23
|
+
propDefinition: [
|
|
24
|
+
pcloud,
|
|
25
|
+
"folderId",
|
|
26
|
+
],
|
|
27
|
+
label: "Destination Folder ID",
|
|
28
|
+
description: `Select a **Destination Folder** to put the file.
|
|
29
|
+
\\
|
|
30
|
+
Alternatively, you can provide a custom *Folder ID*.`,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
methods: {
|
|
34
|
+
...common.methods,
|
|
35
|
+
getSummary() {
|
|
36
|
+
return "Moved file successfully";
|
|
37
|
+
},
|
|
38
|
+
async requestMethod() {
|
|
39
|
+
return this.pcloud.moveFile(
|
|
40
|
+
this.fileId,
|
|
41
|
+
this.toFolderId,
|
|
42
|
+
);
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import pcloud from "../../pcloud.app.mjs";
|
|
2
|
+
import common from "../common/base.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
...common,
|
|
6
|
+
key: "pcloud-move-folder",
|
|
7
|
+
name: "Move Folder",
|
|
8
|
+
description: "Moves a folder to the specified destination. [See the docs here](https://docs.pcloud.com/methods/folder/renamefolder.html)",
|
|
9
|
+
version: "0.0.1",
|
|
10
|
+
type: "action",
|
|
11
|
+
props: {
|
|
12
|
+
...common.props,
|
|
13
|
+
folderId: {
|
|
14
|
+
propDefinition: [
|
|
15
|
+
pcloud,
|
|
16
|
+
"folderId",
|
|
17
|
+
],
|
|
18
|
+
description: `Select a **Folder** to move.
|
|
19
|
+
\\
|
|
20
|
+
Alternatively, you can provide a custom *Folder ID*.`,
|
|
21
|
+
},
|
|
22
|
+
toFolderId: {
|
|
23
|
+
propDefinition: [
|
|
24
|
+
pcloud,
|
|
25
|
+
"folderId",
|
|
26
|
+
],
|
|
27
|
+
label: "Destination Folder ID",
|
|
28
|
+
description: `Select a **Destination Folder** to put the folder.
|
|
29
|
+
\\
|
|
30
|
+
Alternatively, you can provide a custom *Folder ID*.`,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
methods: {
|
|
34
|
+
...common.methods,
|
|
35
|
+
getSummary() {
|
|
36
|
+
return "Moved folder successfully";
|
|
37
|
+
},
|
|
38
|
+
async requestMethod() {
|
|
39
|
+
return this.pcloud.moveFolder(
|
|
40
|
+
this.folderId,
|
|
41
|
+
this.toFolderId,
|
|
42
|
+
);
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import pcloud from "../../pcloud.app.mjs";
|
|
2
|
+
import common from "../common/base.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
...common,
|
|
6
|
+
key: "pcloud-rename-file",
|
|
7
|
+
name: "Rename File",
|
|
8
|
+
description: "Renames a file. [See the docs here](https://docs.pcloud.com/methods/file/renamefile.html)",
|
|
9
|
+
version: "0.0.1",
|
|
10
|
+
type: "action",
|
|
11
|
+
props: {
|
|
12
|
+
...common.props,
|
|
13
|
+
fileId: {
|
|
14
|
+
propDefinition: [
|
|
15
|
+
pcloud,
|
|
16
|
+
"fileId",
|
|
17
|
+
],
|
|
18
|
+
description: `Select a **File** to rename.
|
|
19
|
+
\\
|
|
20
|
+
Alternatively, you can provide a custom *File ID*.`,
|
|
21
|
+
},
|
|
22
|
+
toName: {
|
|
23
|
+
propDefinition: [
|
|
24
|
+
pcloud,
|
|
25
|
+
"name",
|
|
26
|
+
],
|
|
27
|
+
label: "New File Name",
|
|
28
|
+
description: "New name of the file.",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
methods: {
|
|
32
|
+
...common.methods,
|
|
33
|
+
getSummary() {
|
|
34
|
+
return `Successfully renamed file to ${this.toName}`;
|
|
35
|
+
},
|
|
36
|
+
async requestMethod() {
|
|
37
|
+
return this.pcloud.renameFile(
|
|
38
|
+
this.fileId,
|
|
39
|
+
this.toName,
|
|
40
|
+
);
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import pcloud from "../../pcloud.app.mjs";
|
|
2
|
+
import common from "../common/base.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
...common,
|
|
6
|
+
key: "pcloud-rename-folder",
|
|
7
|
+
name: "Rename Folder",
|
|
8
|
+
description: "Renames a folder. [See the docs here](https://docs.pcloud.com/methods/folder/renamefolder.html)",
|
|
9
|
+
version: "0.0.1",
|
|
10
|
+
type: "action",
|
|
11
|
+
props: {
|
|
12
|
+
...common.props,
|
|
13
|
+
folderId: {
|
|
14
|
+
propDefinition: [
|
|
15
|
+
pcloud,
|
|
16
|
+
"folderId",
|
|
17
|
+
],
|
|
18
|
+
description: `Select a **Folder** to rename.
|
|
19
|
+
\\
|
|
20
|
+
Alternatively, you can provide a custom *Folder ID*.`,
|
|
21
|
+
},
|
|
22
|
+
toName: {
|
|
23
|
+
propDefinition: [
|
|
24
|
+
pcloud,
|
|
25
|
+
"name",
|
|
26
|
+
],
|
|
27
|
+
label: "New Folder Name",
|
|
28
|
+
description: "New name of the folder.",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
methods: {
|
|
32
|
+
...common.methods,
|
|
33
|
+
getSummary() {
|
|
34
|
+
return `Successfully renamed folder to ${this.toName}`;
|
|
35
|
+
},
|
|
36
|
+
async requestMethod() {
|
|
37
|
+
return this.pcloud.renameFolder(
|
|
38
|
+
this.folderId,
|
|
39
|
+
this.toName,
|
|
40
|
+
);
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -8,7 +8,7 @@ export default {
|
|
|
8
8
|
name: "Upload File",
|
|
9
9
|
description:
|
|
10
10
|
"Upload a file to the specified folder. [See the docs here](https://docs.pcloud.com/methods/file/uploadfile.html)",
|
|
11
|
-
version: "0.0.
|
|
11
|
+
version: "0.0.3",
|
|
12
12
|
type: "action",
|
|
13
13
|
props: {
|
|
14
14
|
...common.props,
|
package/package.json
CHANGED
package/pcloud.app.mjs
CHANGED
|
@@ -84,6 +84,8 @@ export default {
|
|
|
84
84
|
const retryOpts = {
|
|
85
85
|
retries: 3,
|
|
86
86
|
factor: 2,
|
|
87
|
+
minTimeout: 500,
|
|
88
|
+
maxTimeout: 1500,
|
|
87
89
|
};
|
|
88
90
|
return retry(async (bail) => {
|
|
89
91
|
try {
|
|
@@ -159,6 +161,50 @@ export default {
|
|
|
159
161
|
params,
|
|
160
162
|
});
|
|
161
163
|
},
|
|
164
|
+
/**
|
|
165
|
+
* Takes one file and moves it to another location in the user's filesystem.
|
|
166
|
+
* pCloud API domain URL depends on the location of pCLoud data center associated to the
|
|
167
|
+
* account.
|
|
168
|
+
* @params {integer} fileId - ID of the file to move.
|
|
169
|
+
* @params {integer} toFolderId - ID of the destination folder.
|
|
170
|
+
* @returns {metadata: array, result: integer } An array with the [metadata](https://docs.pcloud.com/structures/metadata.html) of the newly copied file. A `result` integer that indicates the results of the API operation, 0 means success, a non-zero result means an error occurred, when the result is non-zero an `error` message is included.
|
|
171
|
+
*/
|
|
172
|
+
async moveFile(
|
|
173
|
+
fileId,
|
|
174
|
+
toFolderId,
|
|
175
|
+
) {
|
|
176
|
+
const params = {
|
|
177
|
+
fileid: fileId,
|
|
178
|
+
tofolderid: toFolderId,
|
|
179
|
+
};
|
|
180
|
+
return (
|
|
181
|
+
await this.api()
|
|
182
|
+
).api("renamefile", {
|
|
183
|
+
params,
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
/**
|
|
187
|
+
* Takes one file and renames it.
|
|
188
|
+
* pCloud API domain URL depends on the location of pCLoud data center associated to the
|
|
189
|
+
* account.
|
|
190
|
+
* @params {integer} fileId - ID of the file to rename.
|
|
191
|
+
* @params {string} toName - New name for the file.
|
|
192
|
+
* @returns {metadata: array, result: integer } An array with the [metadata](https://docs.pcloud.com/structures/metadata.html) of the newly copied file. A `result` integer that indicates the results of the API operation, 0 means success, a non-zero result means an error occurred, when the result is non-zero an `error` message is included.
|
|
193
|
+
*/
|
|
194
|
+
async renameFile(
|
|
195
|
+
fileId,
|
|
196
|
+
toName,
|
|
197
|
+
) {
|
|
198
|
+
const params = {
|
|
199
|
+
fileid: fileId,
|
|
200
|
+
toname: toName,
|
|
201
|
+
};
|
|
202
|
+
return (
|
|
203
|
+
await this.api()
|
|
204
|
+
).api("renamefile", {
|
|
205
|
+
params,
|
|
206
|
+
});
|
|
207
|
+
},
|
|
162
208
|
/**
|
|
163
209
|
* Copies a folder to the specified folder.
|
|
164
210
|
* @params {integer} folderId - ID of the folder to copy.
|
|
@@ -194,6 +240,50 @@ export default {
|
|
|
194
240
|
async createFolder(name, folderId) {
|
|
195
241
|
return (await this.api()).createfolder(name, folderId);
|
|
196
242
|
},
|
|
243
|
+
/**
|
|
244
|
+
* Takes one folder and moves it to another location in the user's filesystem.
|
|
245
|
+
* pCloud API domain URL depends on the location of pCLoud data center associated to the
|
|
246
|
+
* account.
|
|
247
|
+
* @params {integer} folderId - ID of the folder to move.
|
|
248
|
+
* @params {integer} toFolderId - ID of the destination folder.
|
|
249
|
+
* @returns {metadata: array, result: integer } An array with the [metadata](https://docs.pcloud.com/structures/metadata.html) of the newly copied file. A `result` integer that indicates the results of the API operation, 0 means success, a non-zero result means an error occurred, when the result is non-zero an `error` message is included.
|
|
250
|
+
*/
|
|
251
|
+
async moveFolder(
|
|
252
|
+
folderId,
|
|
253
|
+
toFolderId,
|
|
254
|
+
) {
|
|
255
|
+
const params = {
|
|
256
|
+
folderid: folderId,
|
|
257
|
+
tofolderid: toFolderId,
|
|
258
|
+
};
|
|
259
|
+
return (
|
|
260
|
+
await this.api()
|
|
261
|
+
).api("renamefolder", {
|
|
262
|
+
params,
|
|
263
|
+
});
|
|
264
|
+
},
|
|
265
|
+
/**
|
|
266
|
+
* Takes one folder and renames it.
|
|
267
|
+
* pCloud API domain URL depends on the location of pCLoud data center associated to the
|
|
268
|
+
* account.
|
|
269
|
+
* @params {integer} folderId - ID of the folder to rename.
|
|
270
|
+
* @params {string} toName - New name for the folder.
|
|
271
|
+
* @returns {metadata: array, result: integer } An array with the [metadata](https://docs.pcloud.com/structures/metadata.html) of the newly copied file. A `result` integer that indicates the results of the API operation, 0 means success, a non-zero result means an error occurred, when the result is non-zero an `error` message is included.
|
|
272
|
+
*/
|
|
273
|
+
async renameFolder(
|
|
274
|
+
folderId,
|
|
275
|
+
toName,
|
|
276
|
+
) {
|
|
277
|
+
const params = {
|
|
278
|
+
folderid: folderId,
|
|
279
|
+
toname: toName,
|
|
280
|
+
};
|
|
281
|
+
return (
|
|
282
|
+
await this.api()
|
|
283
|
+
).api("renamefolder", {
|
|
284
|
+
params,
|
|
285
|
+
});
|
|
286
|
+
},
|
|
197
287
|
/**
|
|
198
288
|
* Downloads one or more files from links supplied in the url parameter.
|
|
199
289
|
* @params {array} urls - URL(s) of the files to download.
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import pcloud from "../../pcloud.app.mjs";
|
|
2
|
-
import get from "lodash/get.js";
|
|
3
2
|
|
|
4
3
|
export default {
|
|
5
4
|
key: "pcloud-watch-folder",
|
|
6
5
|
name: "Watch Folder",
|
|
7
|
-
description:
|
|
8
|
-
|
|
9
|
-
version: "0.0.1",
|
|
6
|
+
description: "Emit new event when a file is created or modified in the specified folder.",
|
|
7
|
+
version: "0.0.3",
|
|
10
8
|
type: "source",
|
|
11
|
-
dedupe: "
|
|
9
|
+
dedupe: "unique",
|
|
12
10
|
props: {
|
|
13
11
|
pcloud,
|
|
14
12
|
db: "$.service.db",
|
|
@@ -25,9 +23,7 @@ export default {
|
|
|
25
23
|
pcloud,
|
|
26
24
|
"folderId",
|
|
27
25
|
],
|
|
28
|
-
description:
|
|
29
|
-
\\
|
|
30
|
-
Alternatively, you can provide a custom *Folder ID*.`,
|
|
26
|
+
description: "Select a **Folder** to watch for changes. Alternatively, you can provide a custom *Folder ID*.",
|
|
31
27
|
},
|
|
32
28
|
event: {
|
|
33
29
|
type: "string",
|
|
@@ -36,8 +32,7 @@ export default {
|
|
|
36
32
|
"Created",
|
|
37
33
|
"Modified",
|
|
38
34
|
],
|
|
39
|
-
description:
|
|
40
|
-
"Specify when to emit an event related to a given folder. Note that pCloud preserves files' `created` and `modified` timestamps on upload. If manually uploading via pCloud's `uploadfile` API, these timestamps can be set by specifying the `mtime` and `ctime` parameters, respectively.",
|
|
35
|
+
description: "Specify when to emit an event related to a given folder.",
|
|
41
36
|
default: "Created",
|
|
42
37
|
},
|
|
43
38
|
showDeleted: {
|
|
@@ -50,27 +45,38 @@ export default {
|
|
|
50
45
|
hooks: {
|
|
51
46
|
async deploy() {
|
|
52
47
|
const files = [];
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
48
|
+
const { contents } = await this.getContents();
|
|
49
|
+
if (!contents) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
for (const folderItem of contents) {
|
|
53
|
+
if (this.isRelevant(folderItem)) {
|
|
54
|
+
files.push(folderItem);
|
|
55
|
+
if (files.length == 10) {
|
|
56
|
+
break;
|
|
64
57
|
}
|
|
65
58
|
}
|
|
66
|
-
} else {
|
|
67
|
-
console.log("No data available, skipping iteration");
|
|
68
59
|
}
|
|
69
60
|
files.forEach(this.emitpCloudEvent);
|
|
70
|
-
this.
|
|
61
|
+
this._setPreviousFiles(contents);
|
|
71
62
|
},
|
|
72
63
|
},
|
|
73
64
|
methods: {
|
|
65
|
+
_getPreviousFiles() {
|
|
66
|
+
return this.db.get("previousFiles");
|
|
67
|
+
},
|
|
68
|
+
_setPreviousFiles(files) {
|
|
69
|
+
const key = this.getFileKey();
|
|
70
|
+
const previousFiles = files.filter((file) => file[key]).map((file) => ({
|
|
71
|
+
[file[key]]: true,
|
|
72
|
+
}));
|
|
73
|
+
this.db.set("previousFiles", previousFiles);
|
|
74
|
+
},
|
|
75
|
+
getFileKey() {
|
|
76
|
+
return this.event === "Created"
|
|
77
|
+
? "fileid"
|
|
78
|
+
: "hash";
|
|
79
|
+
},
|
|
74
80
|
async getContents() {
|
|
75
81
|
return this.pcloud._withRetries(() =>
|
|
76
82
|
this.pcloud.listContents(
|
|
@@ -86,35 +92,32 @@ export default {
|
|
|
86
92
|
this.$emit(pCloudEvent, metadata);
|
|
87
93
|
},
|
|
88
94
|
getEventData(pcloudEvent) {
|
|
89
|
-
const
|
|
90
|
-
const ts = +new Date(eventDate);
|
|
95
|
+
const key = this.getFileKey();
|
|
91
96
|
return {
|
|
92
|
-
id:
|
|
97
|
+
id: pcloudEvent[key],
|
|
93
98
|
summary: `${this.event} file "${pcloudEvent.name}"`,
|
|
94
|
-
ts,
|
|
99
|
+
ts: Date.now(),
|
|
95
100
|
};
|
|
96
101
|
},
|
|
102
|
+
isRelevant(folderItem, previousFiles = []) {
|
|
103
|
+
const key = this.getFileKey();
|
|
104
|
+
return !folderItem.isFolder && !previousFiles[folderItem[key]];
|
|
105
|
+
},
|
|
97
106
|
},
|
|
98
107
|
async run() {
|
|
99
|
-
const
|
|
108
|
+
const previousFiles = this._getPreviousFiles();
|
|
100
109
|
const files = [];
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
"contents",
|
|
104
|
-
]);
|
|
105
|
-
if (hasContents) {
|
|
106
|
-
for (const folderItem of pCloudContentsData.contents) {
|
|
107
|
-
if (!folderItem.isfolder) {
|
|
108
|
-
let fileTime = +new Date(folderItem[this.event.toLowerCase()]);
|
|
109
|
-
if (fileTime > lastPolledTime) {
|
|
110
|
-
files.push(folderItem);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
110
|
+
const { contents } = await this.getContents();
|
|
111
|
+
if (!contents) {
|
|
115
112
|
console.log("No data available, skipping iteration");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
for (const folderItem of contents) {
|
|
116
|
+
if (this.isRelevant(folderItem, previousFiles)) {
|
|
117
|
+
files.push(folderItem);
|
|
118
|
+
}
|
|
116
119
|
}
|
|
117
120
|
files.forEach(this.emitpCloudEvent);
|
|
118
|
-
this.
|
|
121
|
+
this._setPreviousFiles(contents);
|
|
119
122
|
},
|
|
120
123
|
};
|