2024-06-24 15:26:07 +02:00
backupApp . controller ( 'ImportController' , function ( $rootScope , $scope , $timeout , $location , AppService , DialogService , gettextCatalog ) {
2015-11-29 00:39:43 +01:00
$scope . Connecting = false ;
$scope . Completed = false ;
2017-02-27 00:03:46 +01:00
$scope . restoremode = $location . $$path . indexOf ( '/restore-import' ) == 0 ;
2024-06-24 15:26:07 +02:00
$scope . form = {
config : '' ,
cmdline : false ,
import_metadata : false ,
direct : false ,
passphrase : ''
};
2017-02-27 00:03:46 +01:00
2024-06-24 15:26:07 +02:00
$scope . doSubmit = function () {
var files = document . querySelector ( '#import-form > div > #config' ) ? . files ;
if ( files == null || files . length == 0 ) {
DialogService . dialog ( gettextCatalog . getString ( 'Error' ), gettextCatalog . getString ( 'Please select a file to import' ));
return false ;
}
2017-02-27 00:03:46 +01:00
2024-06-24 15:26:07 +02:00
var reader = new FileReader ();
$scope . Connecting = true ;
reader . onload = function () {
$scope . form . config = btoa ( String . fromCharCode . apply ( null , new Uint8Array ( reader . result )));
AppService . postJson ( '/backups/import' , $scope . form )
. then ( function ( response ) {
$scope . Connecting = false ;
2017-02-27 00:03:46 +01:00
2024-06-28 10:37:33 +02:00
if ( response . data != null && response . data . Id != null ) {
2024-06-24 15:26:07 +02:00
$location . path ( '/' );
} else if ( response . data != null && response . data . data != null ) {
$rootScope . importConfig = response . data . data ;
if ( $scope . restoremode )
$location . path ( '/restoredirect-import' );
else
$location . path ( '/add-import' );
} else {
DialogService . dialog ( gettextCatalog . getString ( 'Error' ), gettextCatalog . getString ( 'Failed to import: {{message}}' , { message : AppService . responseErrorMessage ( response ) }));
}
2024-06-28 10:37:33 +02:00
}, function ( response ) {
2024-06-24 15:26:07 +02:00
$scope . Connecting = false ;
DialogService . dialog ( gettextCatalog . getString ( 'Error' ), gettextCatalog . getString ( 'Failed to import: {{message}}' , { message : AppService . responseErrorMessage ( response ) }));
});
};
reader . onerror = function ( error ) {
$scope . Connecting = false ;
DialogService . dialog ( gettextCatalog . getString ( 'Error' ), gettextCatalog . getString ( 'Failed to read file: {{message}}' , { message : error }));
};
2017-02-27 00:03:46 +01:00
2024-06-24 15:26:07 +02:00
reader . readAsArrayBuffer ( files [ 0 ]);
2015-11-29 00:39:43 +01:00
2024-06-24 15:26:07 +02:00
return false ;
2015-11-29 00:39:43 +01:00
};
2016-09-15 11:39:27 +02:00
});