Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropbox - Multiple file upload support #12920

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/cloudpresenter/cloudpresenter.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import dropbox from "../../dropbox.app.mjs";
import consts from "../../common/consts.mjs";
import fs from "fs";
import got from "got";
import { ConfigurationError } from "@pipedream/platform";

export default {
name: "Upload Multiple Files",
description: "Uploads multiple file to a selected folder. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesUpload__anchor)",
key: "dropbox-upload-multiple-files",
version: "0.0.1",
type: "action",
props: {
dropbox,
path: {
propDefinition: [
dropbox,
"path",
() => ({
filter: ({ metadata: { metadata: { [".tag"]: type } } }) => type === "folder",
}),
],
description: "The folder to upload to. Type the folder name to search for it in the user's Dropbox.",
},
fileUrls: {
type: "string[]",
label: "File URLs",
description: "The URLs of the files you want to upload to Dropbox. Must specify either File URLs or File Paths.",
default: [],
optional: true,
},
filePaths: {
type: "string[]",
label: "File Paths",
description: "The paths to the files, e.g. /tmp/myFile.csv . Must specify either File URLs or File Paths.",
default: [],
optional: true,
},
filenames: {
type: "string[]",
label: "File Names",
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.",
},
autorename: {
type: "boolean",
label: "Autorename",
description: "If there's a conflict, have Dropbox try to autorename the file to avoid the conflict.",
optional: true,
},
mute: {
type: "boolean",
label: "Mute",
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.",
optional: true,
},
strictConflict: {
type: "boolean",
label: "Strict Conflict",
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.",
optional: true,
},
mode: {
type: "string",
label: "Mode",
description: "Selects what to do if the file already exists.",
options: consts.UPLOAD_FILE_MODE_OPTIONS,
optional: true,
},
},
async run({ $ }) {
const {
dropbox,
path,
fileUrls,
filePaths,
autorename,
mute,
strictConflict,
mode,
filenames,
} = this;

if (!fileUrls?.length && !filePaths?.length) {
throw new ConfigurationError("Must specify either File URLs or File Paths.");
}

const numFiles = fileUrls.length + filePaths.length;
if (numFiles !== filenames.length) {
throw new ConfigurationError(`Number of filenames must match number of files. Detected ${numFiles} file(s) and ${filenames.length} filename(s)`);
}

const fileInfo = [];
const normalizedPath = dropbox.getNormalizedPath(path, true);
let i = 0;

if (fileUrls?.length) {
for (const url of fileUrls) {
fileInfo.push({
contents: await got.stream(url),
path: `${normalizedPath}${filenames[i]}`,
});
i++;
}
}

if (filePaths?.length) {
for (const filePath of filePaths) {
fileInfo.push({
contents: fs.createReadStream(filePath),
path: `${normalizedPath}${filenames[i]}`,
});
i++;
}
}

const responses = [];
for (const file of fileInfo) {
const { result } = await dropbox.uploadFile({
contents: file.contents,
autorename,
path: file.path,
mode: mode
? {
".tag": mode,
}
: undefined,
mute,
strict_conflict: strictConflict,
});
responses.push(result);
}
$.export("$summary", "Files successfully uploaded");
return responses;
},
};
2 changes: 1 addition & 1 deletion components/dropbox/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/dropbox",
"version": "0.3.20",
"version": "0.4.0",
"description": "Pipedream Dropbox Components",
"main": "dropbox.app.mjs",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion components/jooto/jooto.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/launchnotes/launchnotes.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/mission_mobile/mission_mobile.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/picdefense/picdefense.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/simla_com/simla_com.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
Loading