Compare commits

...

5 Commits

Author SHA1 Message Date
d1e31d2472
🔨 Catch some errors 2022-04-30 16:16:02 +02:00
02d2fd9ae3
🔨 Add logs for protected 2022-04-30 16:16:02 +02:00
27bda4d1c6
🚑 Fix multiple upload 2022-04-30 16:16:02 +02:00
084af91620
🚑 Fix crash on backup upload to ha 2022-04-30 15:19:16 +02:00
fdaa188831
🔨 Move token to static in hassioApiTools 2022-04-30 15:18:42 +02:00
3 changed files with 23 additions and 27 deletions

View File

@ -29,13 +29,15 @@ function updateDynamicListeners() {
console.log(id); console.log(id);
}); });
let manual_back_list = $(".manual-back-list"); let manual_back_list = $(".manual-back-list");
manual_back_list.off(); manual_back_list.unbind();
manual_back_list.on("click", function () { manual_back_list.on("click", function () {
let id = this.getAttribute("data-id"); let id = this.getAttribute("data-id");
let name = this.getAttribute("data-name"); let name = this.getAttribute("data-name");
manualBackup(id, name); manualBackup(id, name);
}); });
$(".restore").click(function () { let restore_btn = $(".restore");
restore_btn.unbind();
restore_btn.click(function () {
let to_restore = this.getAttribute("data-id"); let to_restore = this.getAttribute("data-id");
console.log(to_restore); console.log(to_restore);
restore(to_restore); restore(to_restore);

View File

@ -128,9 +128,15 @@ router.post("/manual-backup", function (req, res, next) {
hassioApiTools hassioApiTools
.downloadSnapshot(id) .downloadSnapshot(id)
.then(() => { .then(() => {
webdav.uploadFile(id, webdav.getConf().back_dir + pathTools.manual + name + ".tar").catch(); webdav.uploadFile(id, webdav.getConf().back_dir + pathTools.manual + name + ".tar").then(()=>{
res.status(201); res.status(201);
res.send(); res.send();
}).catch(()=>{
res.status(500);
res.send();
}
);
}) })
.catch(() => { .catch(() => {
res.status(500); res.status(500);
@ -159,10 +165,10 @@ router.post("/new-backup", function (req, res, next) {
.then(() => { .then(() => {
hassioApiTools.startAddons().catch(() => { hassioApiTools.startAddons().catch(() => {
}) })
});
}).catch(()=>{}); }).catch(()=>{});
}).catch(()=>{}); }).catch(()=>{});
}).catch(()=>{});; }).catch(()=>{});
}).catch(()=>{});
}) })
.catch(() => { .catch(() => {
hassioApiTools.startAddons().catch(() => { hassioApiTools.startAddons().catch(() => {

View File

@ -11,14 +11,14 @@ import logger from "../config/winston.js"
const pipeline = promisify(stream.pipeline); const pipeline = promisify(stream.pipeline);
const token = process.env.SUPERVISOR_TOKEN;
// Default timout to 90min // Default timeout to 90min
const create_snap_timeout = parseInt(process.env.CREATE_BACKUP_TIMEOUT) || (90 * 60 * 1000); const create_snap_timeout = parseInt(process.env.CREATE_BACKUP_TIMEOUT) || (90 * 60 * 1000);
function getVersion() { function getVersion() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let token = process.env.HASSIO_TOKEN;
let status = statusTools.getStatus(); let status = statusTools.getStatus();
let option = { let option = {
headers: { "Authorization": `Bearer ${token}` }, headers: { "Authorization": `Bearer ${token}` },
@ -45,7 +45,6 @@ function getVersion() {
function getAddonList() { function getAddonList() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let token = process.env.HASSIO_TOKEN;
let status = statusTools.getStatus(); let status = statusTools.getStatus();
let option = { let option = {
headers: { "Authorization": `Bearer ${token}` }, headers: { "Authorization": `Bearer ${token}` },
@ -139,7 +138,6 @@ function getFolderToBackup() {
function getSnapshots() { function getSnapshots() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let token = process.env.HASSIO_TOKEN;
let status = statusTools.getStatus(); let status = statusTools.getStatus();
let option = { let option = {
headers: { "Authorization": `Bearer ${token}` }, headers: { "Authorization": `Bearer ${token}` },
@ -170,7 +168,6 @@ function downloadSnapshot(id) {
if (!fs.existsSync("./temp/")) fs.mkdirSync("./temp/"); if (!fs.existsSync("./temp/")) fs.mkdirSync("./temp/");
let tmp_file = `./temp/${id}.tar`; let tmp_file = `./temp/${id}.tar`;
let stream = fs.createWriteStream(tmp_file); let stream = fs.createWriteStream(tmp_file);
let token = process.env.HASSIO_TOKEN;
let status = statusTools.getStatus(); let status = statusTools.getStatus();
checkSnap(id) checkSnap(id)
.then(() => { .then(() => {
@ -192,20 +189,20 @@ function downloadSnapshot(id) {
}), }),
stream stream
) )
.then((res) => { .then(() => {
logger.info("Download success !"); logger.info("Download success !");
status.progress = 1; status.progress = 1;
statusTools.setStatus(status); statusTools.setStatus(status);
logger.debug("Snapshot dl size : " + fs.statSync(tmp_file).size / 1024 / 1024); logger.debug("Snapshot dl size : " + fs.statSync(tmp_file).size / 1024 / 1024);
resolve(); resolve();
}) })
.catch((err) => { .catch((error) => {
fs.unlinkSync(tmp_file); fs.unlinkSync(tmp_file);
statusTools.setError(`Fail to download Hassio backup (${error.message})`, 7); statusTools.setError(`Fail to download Hassio backup (${error.message})`, 7);
reject(`Fail to download Hassio backup (${error.message})`); reject(`Fail to download Hassio backup (${error.message})`);
}); });
}) })
.catch((err) => { .catch(() => {
statusTools.setError("Fail to download Hassio backup. Not found ?", 7); statusTools.setError("Fail to download Hassio backup. Not found ?", 7);
reject(); reject();
}); });
@ -216,8 +213,6 @@ function dellSnap(id) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
checkSnap(id) checkSnap(id)
.then(() => { .then(() => {
let token = process.env.HASSIO_TOKEN;
let option = { let option = {
headers: { "Authorization": `Bearer ${token}` }, headers: { "Authorization": `Bearer ${token}` },
responseType: "json", responseType: "json",
@ -238,7 +233,6 @@ function dellSnap(id) {
function checkSnap(id) { function checkSnap(id) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let token = process.env.HASSIO_TOKEN;
let option = { let option = {
headers: { "Authorization": `Bearer ${token}` }, headers: { "Authorization": `Bearer ${token}` },
responseType: "json", responseType: "json",
@ -260,7 +254,6 @@ function createNewBackup(name) {
status.progress = -1; status.progress = -1;
statusTools.setStatus(status); statusTools.setStatus(status);
logger.info("Creating new snapshot..."); logger.info("Creating new snapshot...");
let token = process.env.HASSIO_TOKEN;
getAddonToBackup().then((addons) => { getAddonToBackup().then((addons) => {
let folders = getFolderToBackup(); let folders = getFolderToBackup();
let option = { let option = {
@ -275,7 +268,9 @@ function createNewBackup(name) {
folders: folders folders: folders
}, },
}; };
if (settingsTools.getSettings().password_protected === "true") { let password_protected = settingsTools.getSettings().password_protected;
logger.debug(`Is password protected ? ${password_protected}`)
if ( password_protected === "true") {
option.json.password = settingsTools.getSettings().password_protect_value option.json.password = settingsTools.getSettings().password_protect_value
} }
@ -333,15 +328,11 @@ function uploadSnapshot(path) {
statusTools.setStatus(status); statusTools.setStatus(status);
logger.info("Uploading backup..."); logger.info("Uploading backup...");
let stream = fs.createReadStream(path); let stream = fs.createReadStream(path);
let token = process.env.HASSIO_TOKEN;
let form = new FormData(); let form = new FormData();
form.append("file", stream); form.append("file", stream);
let options = { let options = {
body: form, body: form,
username: this.username,
password: this.password,
headers: { "Authorization": `Bearer ${token}` }, headers: { "Authorization": `Bearer ${token}` },
}; };
@ -395,7 +386,6 @@ function stopAddons() {
status.error_code = null; status.error_code = null;
statusTools.setStatus(status); statusTools.setStatus(status);
let promises = []; let promises = [];
let token = process.env.HASSIO_TOKEN;
let option = { let option = {
headers: { "Authorization": `Bearer ${token}` }, headers: { "Authorization": `Bearer ${token}` },
responseType: "json", responseType: "json",
@ -436,7 +426,6 @@ function startAddons() {
status.error_code = null; status.error_code = null;
statusTools.setStatus(status); statusTools.setStatus(status);
let promises = []; let promises = [];
let token = process.env.HASSIO_TOKEN;
let option = { let option = {
headers: { "Authorization": `Bearer ${token}` }, headers: { "Authorization": `Bearer ${token}` },
responseType: "json", responseType: "json",
@ -484,7 +473,6 @@ function publish_state(state) {
// } // }
// let token = process.env.HASSIO_TOKEN;
// let option = { // let option = {
// headers: { "Authorization": `Bearer ${token}` }, // headers: { "Authorization": `Bearer ${token}` },
// responseType: "json", // responseType: "json",