🚑 Fix ssl setting not working #16

This commit is contained in:
Sebastien 2020-06-14 19:51:28 +02:00
parent 7fa1df0fcc
commit 488e04c8b3
3 changed files with 80 additions and 80 deletions

View File

@ -1,6 +1,6 @@
{
"name": "Nextcloud Backup",
"version": "0.7.5",
"version": "0.7.6",
"slug": "nextcloud_backup",
"description": "Hass.io snapshot backup to Nextcloud",
"url": "https://github.com/Sebclem/hassio-nextcloud-backup",

View File

@ -25,7 +25,7 @@ class WebdavTools {
return new Promise((resolve, reject) => {
let status = statusTools.getStatus();
logger.info("Initilizing and checking webdav client...");
this.baseUrl = (ssl ? "https" : "http") + "://" + host + endpoint;
this.baseUrl = (ssl == true ? "https" : "http") + "://" + host + endpoint;
this.username = username;
this.password = password;
try {
@ -124,7 +124,7 @@ class WebdavTools {
return content;
}
else
return null;
return null;
}
setConf(conf) {
@ -142,7 +142,7 @@ class WebdavTools {
})
}
else
this._startUpload(id, path);
this._startUpload(id, path);
});
}
@ -167,54 +167,54 @@ class WebdavTools {
}
let lastPercent = 0;
let req = request.put(option)
.on('drain', () => {
let percent = Math.floor((req.req.connection.bytesWritten / fileSize) * 100);
if (lastPercent != percent) {
lastPercent = percent;
status.progress = percent / 100;
statusTools.setStatus(status);
}
.on('drain', () => {
let percent = Math.floor((req.req.connection.bytesWritten / fileSize) * 100);
if (lastPercent != percent) {
lastPercent = percent;
status.progress = percent / 100;
statusTools.setStatus(status);
}
}).on('error', function(err) {
fs.unlinkSync('./temp/' + id + '.tar');
}).on('error', function(err) {
fs.unlinkSync('./temp/' + id + '.tar');
status.status = "error";
status.error_code = 4;
status.message = "Fail to upload snapshot to nextcloud (" + err + ") !"
statusTools.setStatus(status);
logger.error(status.message);
reject(status.message);
}).on('response', (res) => {
if (res.statusCode != 201 && res.statusCode != 204) {
status.status = "error";
status.error_code = 4;
status.message = "Fail to upload snapshot to nextcloud (" + err + ") !"
status.message = "Fail to upload snapshot to nextcloud (Status code: " + res.statusCode + ") !"
statusTools.setStatus(status);
logger.error(status.message);
fs.unlinkSync('./temp/' + id + '.tar')
reject(status.message);
}
else {
logger.info("...Upload finish ! (status: " + res.statusCode + ")");
status.status = "idle";
status.progress = -1;
status.message = null;
status.error_code = null;
status.last_backup = moment().format('MMM D, YYYY HH:mm')
}).on('response', (res) => {
if (res.statusCode != 201 && res.statusCode != 204) {
status.status = "error";
status.error_code = 4;
status.message = "Fail to upload snapshot to nextcloud (Status code: " + res.statusCode + ") !"
statusTools.setStatus(status);
logger.error(status.message);
fs.unlinkSync('./temp/' + id + '.tar')
reject(status.message);
statusTools.setStatus(status);
cleanTempFolder();
let autoCleanCloud = settingsTools.getSettings().auto_clean_backup;
if (autoCleanCloud != null && autoCleanCloud == "true") {
this.clean().catch();
}
else {
logger.info("...Upload finish ! (status: " + res.statusCode + ")");
status.status = "idle";
status.progress = -1;
status.message = null;
status.error_code = null;
status.last_backup = moment().format('MMM D, YYYY HH:mm')
statusTools.setStatus(status);
cleanTempFolder();
let autoCleanCloud = settingsTools.getSettings().auto_clean_backup;
if (autoCleanCloud != null && autoCleanCloud == "true") {
this.clean().catch();
}
let autoCleanlocal = settingsTools.getSettings().auto_clean_local;
if (autoCleanlocal != null && autoCleanlocal == "true") {
hassioApiTools.clean();
}
resolve();
let autoCleanlocal = settingsTools.getSettings().auto_clean_local;
if (autoCleanlocal != null && autoCleanlocal == "true") {
hassioApiTools.clean();
}
})
resolve();
}
})
});
}
@ -225,18 +225,18 @@ class WebdavTools {
return;
}
this.client.getDirectoryContents(path)
.then((contents) => {
resolve(contents);
}).catch((error) => {
reject(error);
})
.then((contents) => {
resolve(contents);
}).catch((error) => {
reject(error);
})
});
}
clean() {
let limit = settingsTools.getSettings().auto_clean_local_keep;
if (limit == null)
limit = 5;
limit = 5;
return new Promise((resolve, reject) => {
this.getFolderContent(pathTools.auto).then(async (contents) => {
if (contents.length < limit) {
@ -245,9 +245,9 @@ class WebdavTools {
}
contents.sort((a, b) => {
if (moment(a.lastmod).isBefore(moment(b.lastmod)))
return 1;
return 1;
else
return -1;
return -1;
});
let toDel = contents.slice(limit);

View File

@ -666,7 +666,7 @@
function getNextcloudSettings() {
loadingModal.open();
$.get('./api/nextcloud-settings', (data) => {
$('#ssl').prop('checked', ssl);
$('#ssl').prop("checked", data.ssl == "true");
$('#hostname').val(data.host);
$('#hostname + label').removeClass("active");
$('#hostname + label').addClass("active");