Skip to content

Commit bc4069a

Browse files
authored
Feature/export confirmation (#144)
* feat(export): add confirmation and warning dialong before exporting * refactor(export): clean up code and messages - update: move download logic to a separate function - update: use metadata wording * chore: fix code style --------- Co-authored-by: mahiarirani <[email protected]>
1 parent 1bc2943 commit bc4069a

File tree

2 files changed

+47
-29
lines changed

2 files changed

+47
-29
lines changed

src/app/files/actions/export.js

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { FileAction, registerFileAction } from "@nextcloud/files";
22
import axios from "@nextcloud/axios";
33
import { showError, showSuccess } from "@nextcloud/dialogs";
4-
import { emit } from "@nextcloud/event-bus";
4+
import { getDialogBuilder } from "@nextcloud/dialogs";
55
import DownloadSvg from "@material-design-icons/svg/filled/download.svg";
66
import FilesHelper from "@/util/FilesHelper";
77
import SvgHelper from "@/util/SvgHelper";
88

99
registerFileAction(
1010
new FileAction({
1111
id: "exportAction",
12-
displayName(nodes) {
12+
displayName() {
1313
return t(
1414
"files_external_ethswarm",
1515
"Export"
1616
);
1717
},
18-
iconSvgInline(nodes) {
18+
iconSvgInline() {
1919
return SvgHelper.convert(DownloadSvg);
2020
},
2121
enabled(files) {
@@ -25,26 +25,44 @@ registerFileAction(
2525
return false;
2626
},
2727
async exec(node) {
28-
await axios({
29-
method: "post",
30-
url: node.encodedSource,
31-
headers: {
32-
"Hejbit-Action": "export",
33-
},
34-
}).then((response) => {
35-
if (response.data.status === true) {
36-
const blob = new Blob([JSON.stringify(response.data.data)], {
37-
type: "application/json",
38-
});
39-
const storageName = FilesHelper.getStoragePath(node.path);
40-
const date = new Date().toISOString().split("T")[0];
41-
FilesHelper.downloadFile(blob, `hejbit-export-${storageName}-${date}.json`);
42-
showSuccess("Exported references successfully");
43-
} else {
44-
console.error("Error while exporting references", response);
45-
showError(response.data.message);
46-
}
47-
});
28+
await getDialogBuilder("Export HejBit Storage Metadata")
29+
.setSeverity("warning")
30+
.setText(`
31+
This action will export your HejBit storage metadata such as Swarm references for this storage to a JSON file.
32+
You're responsible for keeping this file secure. Are you sure you want to export your HejBit storage metadata?
33+
`)
34+
.addButton({
35+
label: "Cancel",
36+
})
37+
.addButton({
38+
label: "Export",
39+
callback: async () => downloadMetadata(node),
40+
})
41+
.build()
42+
.show();
4843
},
4944
})
5045
);
46+
47+
const downloadMetadata = async (node) => {
48+
await axios({
49+
method: "post",
50+
url: node.encodedSource,
51+
headers: {
52+
"Hejbit-Action": "export",
53+
},
54+
}).then((response) => {
55+
if (response.data.status === true) {
56+
const blob = new Blob([JSON.stringify(response.data.data)], {
57+
type: "application/json",
58+
});
59+
const storageName = FilesHelper.getStoragePath(node.path);
60+
const date = new Date().toISOString().split("T")[0];
61+
FilesHelper.downloadFile(blob, `hejbit-export-${storageName}-${date}.json`);
62+
showSuccess("Exported storage metadata successfully");
63+
} else {
64+
console.error("Error while exporting metadata of the storage", response);
65+
showError(response.data.message);
66+
}
67+
});
68+
}

vendor-bin/sentry/composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)