@pipedream/dropbox 0.3.1 → 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.
- package/actions/common.mjs +21 -0
- package/actions/create-a-text-file/create-a-text-file.mjs +47 -0
- package/actions/create-folder/create-folder.mjs +47 -0
- package/actions/create-or-append-to-a-text-file/create-or-append-to-a-text-file.mjs +87 -0
- package/actions/create-update-share-link/create-update-share-link.mjs +91 -0
- package/actions/delete-file-folder/delete-file-folder.mjs +27 -0
- package/actions/list-file-folders-in-a-folder/list-file-folders-in-a-folder.mjs +76 -0
- package/actions/list-file-revisions/list-file-revisions.mjs +53 -0
- package/actions/move-file-folder/move-file-folder.mjs +67 -0
- package/actions/rename-file-folder/rename-file-folder.mjs +57 -0
- package/actions/restore-a-file/restore-a-file.mjs +42 -0
- package/actions/search-files-folders/search-files-folders.mjs +117 -0
- package/actions/upload-file/upload-file.mjs +101 -0
- package/config.mjs +11 -0
- package/consts.mjs +52 -0
- package/dropbox.app.mjs +484 -0
- package/package.json +20 -20
- package/sources/all-updates/all-updates.mjs +46 -0
- package/sources/common.mjs +101 -0
- package/sources/new-file/new-file.mjs +72 -0
- package/sources/new-folder/new-folder.mjs +20 -0
- package/dropbox.app.js +0 -117
- package/sources/all-updates/all-updates.js +0 -61
- package/sources/new-file/new-file.js +0 -90
- package/sources/new-folder/new-folder.js +0 -32
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import common from "../common.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
...common,
|
|
5
|
+
dedupe: "unique",
|
|
6
|
+
type: "source",
|
|
7
|
+
key: "dropbox-new-file",
|
|
8
|
+
name: "New File",
|
|
9
|
+
version: "0.0.7",
|
|
10
|
+
description: "Emit new event when a new file is added to your account or a specific folder. Make sure the number of files/folders in the watched folder does not exceed 4000.",
|
|
11
|
+
props: {
|
|
12
|
+
...common.props,
|
|
13
|
+
includeMediaInfo: {
|
|
14
|
+
label: "Include Media Info",
|
|
15
|
+
type: "boolean",
|
|
16
|
+
description: "Emit media info for photos and videos (incurs an additional API call)",
|
|
17
|
+
default: false,
|
|
18
|
+
},
|
|
19
|
+
includeLink: {
|
|
20
|
+
label: "Include Link",
|
|
21
|
+
type: "boolean",
|
|
22
|
+
description: "Emit temporary download link to file (incurs an additional API call)",
|
|
23
|
+
default: false,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
hooks: {
|
|
27
|
+
async activate() {
|
|
28
|
+
const startTime = new Date();
|
|
29
|
+
await this.dropbox.initState(this);
|
|
30
|
+
this._setLastFileModTime(startTime);
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
methods: {
|
|
34
|
+
...common.methods,
|
|
35
|
+
_setLastFileModTime(time) {
|
|
36
|
+
this.db.set("last_file_mod_time", time);
|
|
37
|
+
},
|
|
38
|
+
_getLastFileModTime() {
|
|
39
|
+
return this.db.get("last_file_mod_time");
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
async run() {
|
|
43
|
+
const lastFileModTime = this._getLastFileModTime();
|
|
44
|
+
let currFileModTime = "";
|
|
45
|
+
const updates = await this.dropbox.getUpdates(this);
|
|
46
|
+
for (let update of updates) {
|
|
47
|
+
let file = {
|
|
48
|
+
...update,
|
|
49
|
+
};
|
|
50
|
+
if (update[".tag"] !== "file") {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (update.server_modified > currFileModTime) {
|
|
54
|
+
currFileModTime = update.server_modified;
|
|
55
|
+
}
|
|
56
|
+
const isNewFile = await this.isNewFile(update, lastFileModTime);
|
|
57
|
+
if (!isNewFile) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (this.includeMediaInfo) {
|
|
61
|
+
file = await this.getMediaInfo(update);
|
|
62
|
+
}
|
|
63
|
+
if (this.includeLink) {
|
|
64
|
+
file.link = await this.getTemporaryLink(update);
|
|
65
|
+
}
|
|
66
|
+
this.$emit(file, this.getMeta(file.id, file.path_display || file.id));
|
|
67
|
+
}
|
|
68
|
+
if (currFileModTime != "") {
|
|
69
|
+
this._setLastFileModTime(currFileModTime);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import common from "../common.mjs";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
...common,
|
|
5
|
+
dedupe: "unique",
|
|
6
|
+
type: "source",
|
|
7
|
+
key: "dropbox-new-folder",
|
|
8
|
+
name: "New Folder",
|
|
9
|
+
version: "0.0.7",
|
|
10
|
+
description: "Emit new event when a new folder is created. Make sure the number of files/folders in the watched folder does not exceed 4000.",
|
|
11
|
+
async run() {
|
|
12
|
+
const updates = await this.dropbox.getUpdates(this);
|
|
13
|
+
for (const update of updates) {
|
|
14
|
+
if (update[".tag"] !== "folder") {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
this.$emit(update, this.getMeta(update.id, update.path_display || update.id));
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
};
|
package/dropbox.app.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
const Dropbox = require('dropbox').Dropbox
|
|
2
|
-
const fetch = require('isomorphic-fetch')
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
type: "app",
|
|
6
|
-
app: "dropbox",
|
|
7
|
-
propDefinitions: {
|
|
8
|
-
path: {
|
|
9
|
-
type: "string",
|
|
10
|
-
label: "Path",
|
|
11
|
-
description: "Path to the folder you want to watch for changes.",
|
|
12
|
-
optional: false,
|
|
13
|
-
useQuery: true,
|
|
14
|
-
async options({ query }) {
|
|
15
|
-
return await this.pathOptions(query)
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
recursive: {
|
|
19
|
-
type: "boolean",
|
|
20
|
-
label: "Recursive",
|
|
21
|
-
description: "Also watch sub-directories and their contents.",
|
|
22
|
-
optional: false,
|
|
23
|
-
default: false,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
methods: {
|
|
27
|
-
sdk() {
|
|
28
|
-
return new Dropbox({ accessToken: this.$auth.oauth_access_token, fetch })
|
|
29
|
-
},
|
|
30
|
-
async pathOptions(path) {
|
|
31
|
-
const limit = 50
|
|
32
|
-
let options = []
|
|
33
|
-
let entries, has_more, cursor
|
|
34
|
-
path = (path == "/" ? "" : path)
|
|
35
|
-
try {
|
|
36
|
-
const sdk = this.sdk()
|
|
37
|
-
let files = await sdk.filesListFolder({ path, limit })
|
|
38
|
-
if (files.result) {
|
|
39
|
-
files = files.result
|
|
40
|
-
}
|
|
41
|
-
do {
|
|
42
|
-
({ entries, has_more, cursor } = files)
|
|
43
|
-
for(entry of entries) {
|
|
44
|
-
if (entry[".tag"] == "folder") {
|
|
45
|
-
options.push(entry.path_display)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// TODO break after a certain number of folders has been found??
|
|
49
|
-
if (has_more) {
|
|
50
|
-
files = await sdk.filesListFolderContinue({ cursor })
|
|
51
|
-
if (files.result) {
|
|
52
|
-
files = files.result
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
} while(has_more)
|
|
56
|
-
options = options.sort((a, b) => { return a.toLowerCase().localeCompare(b.toLowerCase()) })
|
|
57
|
-
if (path) {
|
|
58
|
-
options.unshift(require("path").dirname(path))
|
|
59
|
-
}
|
|
60
|
-
options.unshift(path)
|
|
61
|
-
} catch (err) {
|
|
62
|
-
console.log(err)
|
|
63
|
-
throw(`Error connecting to Dropbox API to get directory listing for path: ${path}`)
|
|
64
|
-
}
|
|
65
|
-
return { options }
|
|
66
|
-
},
|
|
67
|
-
async initState(context) {
|
|
68
|
-
const { path, recursive, db } = context
|
|
69
|
-
try {
|
|
70
|
-
let fixedPath = (path == "/" ? "" : path)
|
|
71
|
-
let response = await this.sdk().filesListFolderGetLatestCursor({ path: fixedPath, recursive })
|
|
72
|
-
if (response.result) {
|
|
73
|
-
response = response.result
|
|
74
|
-
}
|
|
75
|
-
let { cursor } = response
|
|
76
|
-
const state = { path, recursive, cursor }
|
|
77
|
-
db.set("dropbox_state", state)
|
|
78
|
-
return state
|
|
79
|
-
} catch(err) {
|
|
80
|
-
console.log(err)
|
|
81
|
-
throw(`Error connecting to Dropbox API to get latest cursor for folder: ${path}${recursive ? " (recursive)" : ""}`)
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
async getState(context) {
|
|
85
|
-
const { path, recursive, db } = context
|
|
86
|
-
let state = db.get("dropbox_state")
|
|
87
|
-
if (state == null || state.path != path || state.recursive != recursive) {
|
|
88
|
-
state = await this.initState(context)
|
|
89
|
-
}
|
|
90
|
-
return state
|
|
91
|
-
},
|
|
92
|
-
async getUpdates(context) {
|
|
93
|
-
let ret = []
|
|
94
|
-
const state = await this.getState(context)
|
|
95
|
-
if (state) {
|
|
96
|
-
try {
|
|
97
|
-
const { dropbox, db } = context
|
|
98
|
-
let [cursor, has_more, entries] = [state.cursor, true, null]
|
|
99
|
-
while(has_more) {
|
|
100
|
-
let response = await this.sdk().filesListFolderContinue({ cursor })
|
|
101
|
-
if (response.result) {
|
|
102
|
-
response = response.result
|
|
103
|
-
}
|
|
104
|
-
({ entries, cursor, has_more } = response)
|
|
105
|
-
ret = ret.concat(entries)
|
|
106
|
-
}
|
|
107
|
-
state.cursor = cursor
|
|
108
|
-
db.set("dropbox_state", state)
|
|
109
|
-
} catch(err) {
|
|
110
|
-
console.log(err)
|
|
111
|
-
throw(`Error connecting to Dropbox API to get list of updated files/folders for cursor: ${state.cursor}`)
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return ret
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
const dropbox = require('../../dropbox.app.js')
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
key: "dropbox-new-or-modified-file-or-folder",
|
|
5
|
-
name: "New or Modified File or Folder",
|
|
6
|
-
version: "0.0.1",
|
|
7
|
-
description: "Emits an event when a file or folder is added or modified. Make sure the number of files/folders in the watched folder does not exceed 4000.",
|
|
8
|
-
props: {
|
|
9
|
-
dropbox,
|
|
10
|
-
path: { propDefinition: [dropbox, "path"]},
|
|
11
|
-
recursive: { propDefinition: [dropbox, "recursive"]},
|
|
12
|
-
includeMediaInfo: {
|
|
13
|
-
type: "boolean",
|
|
14
|
-
description: "Emit media info for photo and video files (incurs an additional API call)",
|
|
15
|
-
default: false,
|
|
16
|
-
},
|
|
17
|
-
includeLink: {
|
|
18
|
-
type: "boolean",
|
|
19
|
-
description: "Emit temporary download link for files (incurs an additional API call)",
|
|
20
|
-
default: false,
|
|
21
|
-
},
|
|
22
|
-
dropboxApphook: {
|
|
23
|
-
type: "$.interface.apphook",
|
|
24
|
-
appProp: "dropbox",
|
|
25
|
-
static: [],
|
|
26
|
-
},
|
|
27
|
-
db: "$.service.db",
|
|
28
|
-
},
|
|
29
|
-
hooks: {
|
|
30
|
-
async activate() {
|
|
31
|
-
await this.dropbox.initState(this)
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
async run(event) {
|
|
35
|
-
let updates = await this.dropbox.getUpdates(this)
|
|
36
|
-
for(update of updates) {
|
|
37
|
-
if (update[".tag"] == "file") {
|
|
38
|
-
if (this.includeMediaInfo) {
|
|
39
|
-
update = await this.dropbox.sdk().filesGetMetadata({
|
|
40
|
-
path: update.path_lower,
|
|
41
|
-
include_media_info: true,
|
|
42
|
-
})
|
|
43
|
-
if (update.result) {
|
|
44
|
-
update = update.result
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (this.includeLink) {
|
|
48
|
-
let response = await this.dropbox.sdk().filesGetTemporaryLink({
|
|
49
|
-
path: update.path_lower,
|
|
50
|
-
})
|
|
51
|
-
if (response.result) {
|
|
52
|
-
response = response.result
|
|
53
|
-
}
|
|
54
|
-
const { link, metadata } = response
|
|
55
|
-
update.link = link
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
this.$emit(update)
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
const dropbox = require('../../dropbox.app.js')
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
key: "dropbox-new-file",
|
|
5
|
-
name: "New File",
|
|
6
|
-
version: "0.0.1",
|
|
7
|
-
description: "Emits an event when a new file is added to your account or a specific folder. Make sure the number of files/folders in the watched folder does not exceed 4000.",
|
|
8
|
-
props: {
|
|
9
|
-
dropbox,
|
|
10
|
-
path: { propDefinition: [dropbox, "path"]},
|
|
11
|
-
recursive: { propDefinition: [dropbox, "recursive"]},
|
|
12
|
-
includeMediaInfo: {
|
|
13
|
-
type: "boolean",
|
|
14
|
-
description: "Emit media info for photos and videos (incurs an additional API call)",
|
|
15
|
-
default: false,
|
|
16
|
-
},
|
|
17
|
-
includeLink: {
|
|
18
|
-
type: "boolean",
|
|
19
|
-
description: "Emit temporary download link to file (incurs an additional API call)",
|
|
20
|
-
default: false,
|
|
21
|
-
},
|
|
22
|
-
dropboxApphook: {
|
|
23
|
-
type: "$.interface.apphook",
|
|
24
|
-
appProp: "dropbox",
|
|
25
|
-
static: [],
|
|
26
|
-
},
|
|
27
|
-
db: "$.service.db",
|
|
28
|
-
},
|
|
29
|
-
hooks: {
|
|
30
|
-
async activate() {
|
|
31
|
-
let startTime = new Date()
|
|
32
|
-
await this.dropbox.initState(this)
|
|
33
|
-
this.db.set("last_file_mod_time", startTime)
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
async run(event) {
|
|
37
|
-
const lastFileModTime = this.db.get("last_file_mod_time")
|
|
38
|
-
let currFileModTime = ""
|
|
39
|
-
let updates = await this.dropbox.getUpdates(this)
|
|
40
|
-
for(update of updates) {
|
|
41
|
-
if (update[".tag"] == "file") {
|
|
42
|
-
if (update.server_modified > currFileModTime) {
|
|
43
|
-
currFileModTime = update.server_modified
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
let revisions = await this.dropbox.sdk().filesListRevisions({
|
|
47
|
-
path: update.id,
|
|
48
|
-
mode: { ".tag": "id" },
|
|
49
|
-
limit: 10,
|
|
50
|
-
})
|
|
51
|
-
if (revisions.result) {
|
|
52
|
-
revisions = revisions.result
|
|
53
|
-
}
|
|
54
|
-
if (revisions.entries.length > 1) {
|
|
55
|
-
let oldest = revisions.entries.pop()
|
|
56
|
-
if (lastFileModTime && lastFileModTime >= oldest.client_modified) {
|
|
57
|
-
continue
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (this.includeMediaInfo) {
|
|
61
|
-
update = await this.dropbox.sdk().filesGetMetadata({
|
|
62
|
-
path: update.path_lower,
|
|
63
|
-
include_media_info: true,
|
|
64
|
-
})
|
|
65
|
-
if (update.result) {
|
|
66
|
-
update = update.result
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (this.includeLink) {
|
|
70
|
-
let response = await this.dropbox.sdk().filesGetTemporaryLink({
|
|
71
|
-
path: update.path_lower,
|
|
72
|
-
})
|
|
73
|
-
if (response.result) {
|
|
74
|
-
response = response.result
|
|
75
|
-
}
|
|
76
|
-
const { link, metadata } = response
|
|
77
|
-
update.link = link
|
|
78
|
-
}
|
|
79
|
-
} catch(err) {
|
|
80
|
-
console.log(err)
|
|
81
|
-
throw(`Error looking up revisions for file: ${update.name}`)
|
|
82
|
-
}
|
|
83
|
-
this.$emit(update)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (currFileModTime != "") {
|
|
87
|
-
this.db.set("last_file_mod_time", currFileModTime)
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const dropbox = require('../../dropbox.app.js')
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
key: "dropbox-new-folder",
|
|
5
|
-
name: "New Folder",
|
|
6
|
-
version: "0.0.1",
|
|
7
|
-
description: "Emits an event when a new folder is created. Make sure the number of files/folders in the watched folder does not exceed 4000.",
|
|
8
|
-
props: {
|
|
9
|
-
dropbox,
|
|
10
|
-
path: { propDefinition: [dropbox, "path"]},
|
|
11
|
-
recursive: { propDefinition: [dropbox, "recursive"]},
|
|
12
|
-
dropboxApphook: {
|
|
13
|
-
type: "$.interface.apphook",
|
|
14
|
-
appProp: "dropbox",
|
|
15
|
-
static: [],
|
|
16
|
-
},
|
|
17
|
-
db: "$.service.db",
|
|
18
|
-
},
|
|
19
|
-
hooks: {
|
|
20
|
-
async activate() {
|
|
21
|
-
await this.dropbox.initState(this)
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
async run(event) {
|
|
25
|
-
let updates = await this.dropbox.getUpdates(this)
|
|
26
|
-
for(update of updates) {
|
|
27
|
-
if (update[".tag"] == "folder") {
|
|
28
|
-
this.$emit(update)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
}
|