11import { FileAction , registerFileAction } from "@nextcloud/files" ;
22import axios from "@nextcloud/axios" ;
33import { showError , showSuccess } from "@nextcloud/dialogs" ;
4- import { emit } from "@nextcloud/event-bus " ;
4+ import { getDialogBuilder } from "@nextcloud/dialogs " ;
55import DownloadSvg from "@material-design-icons/svg/filled/download.svg" ;
66import FilesHelper from "@/util/FilesHelper" ;
77import SvgHelper from "@/util/SvgHelper" ;
88
99registerFileAction (
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+ }
0 commit comments