-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathbackup.js
77 lines (64 loc) · 2.84 KB
/
backup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
angular
.module('nzbhydraApp')
.directive('hydrabackup', hydrabackup);
function hydrabackup() {
return {
templateUrl: 'static/html/directives/backup.html',
controller: controller
};
function controller($scope, BackupService, Upload, FileDownloadService, $http, RequestsErrorHandler, growl, RestartService) {
$scope.refreshBackupList = function () {
BackupService.getBackupsList().then(function (backups) {
$scope.backups = backups;
});
};
$scope.refreshBackupList();
$scope.uploadActive = false;
$scope.createBackupFile = function () {
$http.get("internalapi/backup/backuponly", {params: {dontdownload: true}}).then(function () {
$scope.refreshBackupList();
});
};
$scope.createAndDownloadBackupFile = function () {
FileDownloadService.downloadFile("internalapi/backup/backup", "nzbhydra-backup-" + moment().format("YYYY-MM-DD-HH-mm") + ".zip", "GET").then(function () {
$scope.refreshBackupList();
});
};
$scope.uploadBackupFile = function (file, errFiles) {
RequestsErrorHandler.specificallyHandled(function () {
$scope.file = file;
$scope.errFile = errFiles && errFiles[0];
if (file) {
$scope.uploadActive = true;
file.upload = Upload.upload({
url: 'internalapi/backup/restorefile',
file: file
});
file.upload.then(function (response) {
if (response.data.successful) {
$scope.uploadActive = false;
RestartService.startCountdown("Upload successful. Restarting for wrapper to restore data.");
} else {
file.progress = 0;
growl.error(response.data.message)
}
}, function (response) {
growl.error(response.data.message)
}, function (evt) {
file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
file.loaded = Math.floor(evt.loaded / 1024);
file.total = Math.floor(evt.total / 1024);
});
}
});
};
$scope.restoreFromFile = function (filename) {
BackupService.restoreFromFile(filename).then(function () {
RestartService.startCountdown("Extraction of backup successful. Restarting for wrapper to restore data.");
},
function (response) {
growl.error(response.data);
})
}
}
}