Skip to content

Commit a7211d1

Browse files
authored
[BUG] Dropbox → Download File to TMP action is very inefficient #16874 (#16894)
* [BUG] Dropbox → Download File to TMP action is very inefficient #16874 Actions - Download To TMP * pnpm update * remove duplicating extension * some adjusts
1 parent 2807e4a commit a7211d1

File tree

21 files changed

+88
-73
lines changed

21 files changed

+88
-73
lines changed

components/dropbox/actions/create-a-text-file/create-a-text-file.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
name: "Create a Text File",
55
description: "Creates a brand new text file from plain text content you specify. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesUpload__anchor)",
66
key: "dropbox-create-a-text-file",
7-
version: "0.0.10",
7+
version: "0.0.11",
88
type: "action",
99
props: {
1010
dropbox,

components/dropbox/actions/create-folder/create-folder.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
name: "Create folder",
55
description: "Create a Folder. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesCreateFolderV2__anchor)",
66
key: "dropbox-create-folder",
7-
version: "0.0.10",
7+
version: "0.0.11",
88
type: "action",
99
props: {
1010
dropbox,

components/dropbox/actions/create-or-append-to-a-text-file/create-or-append-to-a-text-file.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
name: "Create or Append to a Text File",
55
description: "Adds a new line to an existing text file, or creates a file if it doesn't exist. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesUpload__anchor)",
66
key: "dropbox-create-or-append-to-a-text-file",
7-
version: "0.0.10",
7+
version: "0.0.11",
88
type: "action",
99
props: {
1010
dropbox,

components/dropbox/actions/create-update-share-link/create-update-share-link.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import common from "./common.mjs";
21
import consts from "../../common/consts.mjs";
2+
import common from "./common.mjs";
33

44
export default {
55
name: "Create/Update a Share Link",
66
description: "Creates or updates a public share link to the file or folder (It allows you to share the file or folder with anyone). [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#sharingCreateSharedLinkWithSettings__anchor)",
77
key: "dropbox-create-update-share-link",
8-
version: "0.0.10",
8+
version: "0.0.11",
99
type: "action",
1010
props: {
1111
...common.props,

components/dropbox/actions/delete-file-folder/delete-file-folder.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
name: "Delete a File/Folder",
55
description: "Permanently removes a file/folder from the server. [See documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesDeleteV2__anchor)",
66
key: "dropbox-delete-file-folder",
7-
version: "0.0.10",
7+
version: "0.0.11",
88
type: "action",
99
props: {
1010
dropbox,
Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import dropbox from "../../dropbox.app.mjs";
21
import fs from "fs";
3-
import { file } from "tmp-promise";
2+
import got from "got";
3+
import stream from "stream";
4+
import { promisify } from "util";
5+
import { checkTmp } from "../../common/utils.mjs";
6+
import dropbox from "../../dropbox.app.mjs";
47

58
export default {
69
name: "Download File to TMP",
710
description: "Download a specific file to the temporary directory. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesDownload__anchor).",
811
key: "dropbox-download-file-to-tmp",
9-
version: "0.0.6",
12+
version: "0.0.7",
1013
type: "action",
1114
props: {
1215
dropbox,
@@ -27,30 +30,40 @@ export default {
2730
},
2831
},
2932
async run({ $ }) {
30-
const { result } = await this.dropbox.downloadFile({
31-
path: this.dropbox.getNormalizedPath(this.path, false),
32-
});
33+
try {
34+
const linkResponse = await this.dropbox.filesGetTemporaryLink({
35+
path: this.dropbox.getNormalizedPath(this.path, false),
36+
});
37+
38+
console.log("linkResponse: ", linkResponse);
3339

34-
const {
35-
path, cleanup,
36-
} = await file();
40+
if (!linkResponse || !linkResponse.result) {
41+
throw new Error("Failed to get temporary download link from Dropbox");
42+
}
3743

38-
const extension = result.name.split(".").pop();
44+
const {
45+
link, metadata,
46+
} = linkResponse.result;
3947

40-
const tmpPath = this.name
41-
? `/tmp/${this.name}`
42-
: `${path}.${extension}`;
48+
const fileName = this.name || metadata.name;
49+
const cleanFileName = fileName.replace(/[?$#&{}[]<>\*!@:\+\\\/]/g, "");
4350

44-
await fs.promises.appendFile(tmpPath, Buffer.from(result.fileBinary));
45-
await cleanup();
51+
const tmpPath = checkTmp(cleanFileName);
52+
const pipeline = promisify(stream.pipeline);
4653

47-
delete result.fileBinary;
54+
await pipeline(
55+
got.stream(link),
56+
fs.createWriteStream(tmpPath),
57+
);
4858

49-
$.export("$summary", `File successfully saved in "${tmpPath}"`);
59+
$.export("$summary", `File successfully saved in "${tmpPath}"`);
5060

51-
return {
52-
tmpPath,
53-
...result,
54-
};
61+
return {
62+
tmpPath,
63+
...metadata,
64+
};
65+
} catch (error) {
66+
throw new Error(`Failed to download file: ${error.message}`);
67+
}
5568
},
5669
};

components/dropbox/actions/list-file-folders-in-a-folder/list-file-folders-in-a-folder.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
name: "List All Files/Subfolders in a Folder",
55
description: "Retrieves a list of files or subfolders in a specified folder [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesListFolder__anchor)",
66
key: "dropbox-list-file-folders-in-a-folder",
7-
version: "0.0.10",
7+
version: "0.0.11",
88
type: "action",
99
props: {
1010
dropbox,

components/dropbox/actions/list-file-revisions/list-file-revisions.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "List File Revisions",
66
description: "Retrieves a list of file revisions needed to recover previous content. [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesListRevisions__anchor)",
77
key: "dropbox-list-file-revisions",
8-
version: "0.0.10",
8+
version: "0.0.11",
99
type: "action",
1010
props: {
1111
dropbox,

components/dropbox/actions/move-file-folder/move-file-folder.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
name: "Move a File/Folder",
55
description: "Moves a file or folder to a different location in the user's Dropbox [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesMoveV2__anchor)",
66
key: "dropbox-move-file-folder",
7-
version: "0.0.11",
7+
version: "0.0.12",
88
type: "action",
99
props: {
1010
dropbox,

components/dropbox/actions/rename-file-folder/rename-file-folder.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
name: "Rename a File/Folder",
55
description: "Renames a file or folder in the user's Dropbox [See the documentation](https://dropbox.github.io/dropbox-sdk-js/Dropbox.html#filesMoveV2__anchor)",
66
key: "dropbox-rename-file-folder",
7-
version: "0.0.10",
7+
version: "0.0.11",
88
type: "action",
99
props: {
1010
dropbox,

0 commit comments

Comments
 (0)