From b32d51847e67a7a415a38d7521f7cbc6448f3d76 Mon Sep 17 00:00:00 2001 From: Sebastien Clement Date: Sat, 28 Dec 2019 16:25:54 +0100 Subject: [PATCH] Update last backup when upload is finish --- .../rootfs/opt/nextcloud_backup/routes/api.js | 17 +++++++------ .../opt/nextcloud_backup/tools/webdavTools.js | 3 +++ .../opt/nextcloud_backup/views/index.ejs | 24 +++++++++++-------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/nextcloud_backup/rootfs/opt/nextcloud_backup/routes/api.js b/nextcloud_backup/rootfs/opt/nextcloud_backup/routes/api.js index 3a66c26..21c803c 100644 --- a/nextcloud_backup/rootfs/opt/nextcloud_backup/routes/api.js +++ b/nextcloud_backup/rootfs/opt/nextcloud_backup/routes/api.js @@ -80,14 +80,17 @@ router.get('/nextcloud-settings', function(req, res, next) { router.post('/manual-backup', function(req, res, next) { let id = req.query.id; let name = req.query.name; - // hassioApiTools.downloadSnapshot(id) - // .then(() => { - webdav.uploadFile('8afb4728', '/Hassio Backup/Manual/' + '8afb4728' + '.tar'); + hassioApiTools.downloadSnapshot(id) + .then(() => { + webdav.uploadFile(id, '/Hassio Backup/Manual/' + name + '.tar'); res.send(200); - // }) - // .catch(() => { - // res.send(500); - // }) + }) + .catch(() => { + res.send(500); + }) + +}); + }); diff --git a/nextcloud_backup/rootfs/opt/nextcloud_backup/tools/webdavTools.js b/nextcloud_backup/rootfs/opt/nextcloud_backup/tools/webdavTools.js index 3c9a182..85e8e12 100644 --- a/nextcloud_backup/rootfs/opt/nextcloud_backup/tools/webdavTools.js +++ b/nextcloud_backup/rootfs/opt/nextcloud_backup/tools/webdavTools.js @@ -1,5 +1,6 @@ const { createClient } = require("webdav"); const fs = require("fs"); +const moment = require('moment'); const statusTools = require('./status'); const endpoint = "/remote.php/webdav" @@ -148,6 +149,8 @@ class WebdavTools { status.status = "idle"; status.message = null; status.error_code = null; + status.last_backup = moment().format("lll") + statusTools.setStatus(status); resolve(); }).catch((err) => { diff --git a/nextcloud_backup/rootfs/opt/nextcloud_backup/views/index.ejs b/nextcloud_backup/rootfs/opt/nextcloud_backup/views/index.ejs index 13dc5de..fda0c1d 100644 --- a/nextcloud_backup/rootfs/opt/nextcloud_backup/views/index.ejs +++ b/nextcloud_backup/rootfs/opt/nextcloud_backup/views/index.ejs @@ -112,7 +112,7 @@
Last Backup
-
+
@@ -308,7 +308,7 @@ console.log(id); }); - $('.manual-back-list').click(function(){ + $('.manual-back-list').click(function() { let id = this.getAttribute('data-id'); let name = this.getAttribute('data-name'); manualBackup(id, name); @@ -333,6 +333,10 @@ case "upload": printStatusWithBar('Uploading Snapshot', data.progress); } + if (data.last_backup != null) { + if ($('#last_back_status').html() != data.last_backup) + $('#last_back_status').html(data.last_backup); + } } @@ -350,27 +354,27 @@ $('#progress').addClass("hide"); } - function printStatusWithBar(status, progress){ + function printStatusWithBar(status, progress) { $('#status').empty(); $('#status').html(status); let secondLine = $('#status-second-line') secondLine.empty(); - secondLine.html(progress == -1 ? "Waiting..." : (Math.round(progress*100) + "%")); + secondLine.html(progress == -1 ? "Waiting..." : (Math.round(progress * 100) + "%")); secondLine.addClass("center"); - secondLine.attr('data-tooltip', Math.round(progress*100) + "%"); + secondLine.attr('data-tooltip', Math.round(progress * 100) + "%"); let progressDiv = $('#progress'); progressDiv.removeClass("hide"); - if(progress == -1){ + if (progress == -1) { progressDiv.children().removeClass('determinate'); progressDiv.children().addClass('indeterminate'); } - else{ + else { progressDiv.children().removeClass('indeterminate'); progressDiv.children().addClass('determinate'); - progressDiv.children().css('width', (progress*100) + "%"); + progressDiv.children().css('width', (progress * 100) + "%"); } - + } function listeners() { @@ -411,7 +415,7 @@ }) } - function manualBackup(id, name){ + function manualBackup(id, name) { $.post('./api/manual-backup?id=' + id + '&name=' + name); }