@pipedream/pcloud 0.3.3 → 0.3.4

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.
@@ -7,7 +7,7 @@ export default {
7
7
  name: "Copy File",
8
8
  description:
9
9
  "Copy a file to the specified destination. [See the docs here](https://docs.pcloud.com/methods/file/copyfile.html)",
10
- version: "0.0.1",
10
+ version: "0.0.2",
11
11
  type: "action",
12
12
  props: {
13
13
  ...common.props,
@@ -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.1",
9
+ version: "0.0.2",
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.1",
10
+ version: "0.0.2",
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.1",
9
+ version: "0.0.2",
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.1",
9
+ version: "0.0.2",
10
10
  type: "action",
11
11
  props: {
12
12
  ...common.props,
@@ -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.1",
11
+ version: "0.0.2",
12
12
  type: "action",
13
13
  props: {
14
14
  ...common.props,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/pcloud",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Pipedream pCloud Components",
5
5
  "main": "pcloud.app.mjs",
6
6
  "keywords": [
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 {
@@ -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
- "Emit new event when a file is created or modified in the specified folder.",
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.2",
10
8
  type: "source",
11
- dedupe: "last",
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: `Select a **Folder** to watch for changes.
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 pCloudContentsData = await this.getContents();
54
- const hasContents = get(pCloudContentsData, [
55
- "contents",
56
- ]);
57
- if (hasContents) {
58
- for (const folderItem of pCloudContentsData.contents) {
59
- if (!folderItem.isfolder) {
60
- files.push(folderItem);
61
- if (files.length == 10) {
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.db.set("lastPolledTime", +Date.now());
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 eventDate = pcloudEvent[this.event.toLowerCase()];
90
- const ts = +new Date(eventDate);
95
+ const key = this.getFileKey();
91
96
  return {
92
- id: ts,
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 lastPolledTime = this.db.get("lastPolledTime");
108
+ const previousFiles = this._getPreviousFiles();
100
109
  const files = [];
101
- const pCloudContentsData = await this.getContents();
102
- const hasContents = get(pCloudContentsData, [
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.db.set("lastPolledTime", +Date.now());
121
+ this._setPreviousFiles(contents);
119
122
  },
120
123
  };