@pipedream/dropbox 0.3.20 → 0.4.0
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.
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import dropbox from "../../dropbox.app.mjs";
|
|
2
|
+
import consts from "../../common/consts.mjs";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import got from "got";
|
|
5
|
+
import { ConfigurationError } from "@pipedream/platform";
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
name: "Upload Multiple Files",
|
|
9
|
+
description: "Uploads multiple file to a selected folder. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesUpload__anchor)",
|
|
10
|
+
key: "dropbox-upload-multiple-files",
|
|
11
|
+
version: "0.0.1",
|
|
12
|
+
type: "action",
|
|
13
|
+
props: {
|
|
14
|
+
dropbox,
|
|
15
|
+
path: {
|
|
16
|
+
propDefinition: [
|
|
17
|
+
dropbox,
|
|
18
|
+
"path",
|
|
19
|
+
() => ({
|
|
20
|
+
filter: ({ metadata: { metadata: { [".tag"]: type } } }) => type === "folder",
|
|
21
|
+
}),
|
|
22
|
+
],
|
|
23
|
+
description: "The folder to upload to. Type the folder name to search for it in the user's Dropbox.",
|
|
24
|
+
},
|
|
25
|
+
fileUrls: {
|
|
26
|
+
type: "string[]",
|
|
27
|
+
label: "File URLs",
|
|
28
|
+
description: "The URLs of the files you want to upload to Dropbox. Must specify either File URLs or File Paths.",
|
|
29
|
+
default: [],
|
|
30
|
+
optional: true,
|
|
31
|
+
},
|
|
32
|
+
filePaths: {
|
|
33
|
+
type: "string[]",
|
|
34
|
+
label: "File Paths",
|
|
35
|
+
description: "The paths to the files, e.g. /tmp/myFile.csv . Must specify either File URLs or File Paths.",
|
|
36
|
+
default: [],
|
|
37
|
+
optional: true,
|
|
38
|
+
},
|
|
39
|
+
filenames: {
|
|
40
|
+
type: "string[]",
|
|
41
|
+
label: "File Names",
|
|
42
|
+
description: "An array of filenames for the new files. Please provide a name for each URL and/or Path. Make sure to include the file extensions.",
|
|
43
|
+
},
|
|
44
|
+
autorename: {
|
|
45
|
+
type: "boolean",
|
|
46
|
+
label: "Autorename",
|
|
47
|
+
description: "If there's a conflict, have Dropbox try to autorename the file to avoid the conflict.",
|
|
48
|
+
optional: true,
|
|
49
|
+
},
|
|
50
|
+
mute: {
|
|
51
|
+
type: "boolean",
|
|
52
|
+
label: "Mute",
|
|
53
|
+
description: "Normally, users are made aware of any file modifications in their Dropbox account via notifications in the client software. If `true`, this will not result in a user notification.",
|
|
54
|
+
optional: true,
|
|
55
|
+
},
|
|
56
|
+
strictConflict: {
|
|
57
|
+
type: "boolean",
|
|
58
|
+
label: "Strict Conflict",
|
|
59
|
+
description: "Be more strict about how each WriteMode detects conflict. For example, always return a conflict error when mode = WriteMode.update and the given \"rev\" doesn't match the existing file's \"rev\", even if the existing file has been deleted. This also forces a conflict even when the target path refers to a file with identical contents.",
|
|
60
|
+
optional: true,
|
|
61
|
+
},
|
|
62
|
+
mode: {
|
|
63
|
+
type: "string",
|
|
64
|
+
label: "Mode",
|
|
65
|
+
description: "Selects what to do if the file already exists.",
|
|
66
|
+
options: consts.UPLOAD_FILE_MODE_OPTIONS,
|
|
67
|
+
optional: true,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
async run({ $ }) {
|
|
71
|
+
const {
|
|
72
|
+
dropbox,
|
|
73
|
+
path,
|
|
74
|
+
fileUrls,
|
|
75
|
+
filePaths,
|
|
76
|
+
autorename,
|
|
77
|
+
mute,
|
|
78
|
+
strictConflict,
|
|
79
|
+
mode,
|
|
80
|
+
filenames,
|
|
81
|
+
} = this;
|
|
82
|
+
|
|
83
|
+
if (!fileUrls?.length && !filePaths?.length) {
|
|
84
|
+
throw new ConfigurationError("Must specify either File URLs or File Paths.");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const numFiles = fileUrls.length + filePaths.length;
|
|
88
|
+
if (numFiles !== filenames.length) {
|
|
89
|
+
throw new ConfigurationError(`Number of filenames must match number of files. Detected ${numFiles} file(s) and ${filenames.length} filename(s)`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const fileInfo = [];
|
|
93
|
+
const normalizedPath = dropbox.getNormalizedPath(path, true);
|
|
94
|
+
let i = 0;
|
|
95
|
+
|
|
96
|
+
if (fileUrls?.length) {
|
|
97
|
+
for (const url of fileUrls) {
|
|
98
|
+
fileInfo.push({
|
|
99
|
+
contents: await got.stream(url),
|
|
100
|
+
path: `${normalizedPath}${filenames[i]}`,
|
|
101
|
+
});
|
|
102
|
+
i++;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (filePaths?.length) {
|
|
107
|
+
for (const filePath of filePaths) {
|
|
108
|
+
fileInfo.push({
|
|
109
|
+
contents: fs.createReadStream(filePath),
|
|
110
|
+
path: `${normalizedPath}${filenames[i]}`,
|
|
111
|
+
});
|
|
112
|
+
i++;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const responses = [];
|
|
117
|
+
for (const file of fileInfo) {
|
|
118
|
+
const { result } = await dropbox.uploadFile({
|
|
119
|
+
contents: file.contents,
|
|
120
|
+
autorename,
|
|
121
|
+
path: file.path,
|
|
122
|
+
mode: mode
|
|
123
|
+
? {
|
|
124
|
+
".tag": mode,
|
|
125
|
+
}
|
|
126
|
+
: undefined,
|
|
127
|
+
mute,
|
|
128
|
+
strict_conflict: strictConflict,
|
|
129
|
+
});
|
|
130
|
+
responses.push(result);
|
|
131
|
+
}
|
|
132
|
+
$.export("$summary", "Files successfully uploaded");
|
|
133
|
+
return responses;
|
|
134
|
+
},
|
|
135
|
+
};
|