Compare commits

..

No commits in common. "d1e31d2472cf54f162d9e07f523dc741d2d5f1c8" and "f3c0b6787ab310160e463b0cea1212117bfde3bb" have entirely different histories.

3 changed files with 27 additions and 23 deletions

View File

@ -29,15 +29,13 @@ 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.unbind(); manual_back_list.off();
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);
}); });
let restore_btn = $(".restore"); $(".restore").click(function () {
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,15 +128,9 @@ 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").then(()=>{ webdav.uploadFile(id, webdav.getConf().back_dir + pathTools.manual + name + ".tar").catch();
res.status(201); res.status(201);
res.send(); res.send();
}).catch(()=>{
res.status(500);
res.send();
}
);
}) })
.catch(() => { .catch(() => {
res.status(500); res.status(500);
@ -165,10 +159,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 timeout to 90min // Default timout 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,6 +45,7 @@ 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}` },
@ -138,6 +139,7 @@ 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}` },
@ -168,6 +170,7 @@ 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(() => {
@ -189,20 +192,20 @@ function downloadSnapshot(id) {
}), }),
stream stream
) )
.then(() => { .then((res) => {
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((error) => { .catch((err) => {
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(() => { .catch((err) => {
statusTools.setError("Fail to download Hassio backup. Not found ?", 7); statusTools.setError("Fail to download Hassio backup. Not found ?", 7);
reject(); reject();
}); });
@ -213,6 +216,8 @@ 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",
@ -233,6 +238,7 @@ 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",
@ -254,6 +260,7 @@ 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 = {
@ -268,9 +275,7 @@ function createNewBackup(name) {
folders: folders folders: folders
}, },
}; };
let password_protected = settingsTools.getSettings().password_protected; if (settingsTools.getSettings().password_protected === "true") {
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
} }
@ -328,11 +333,15 @@ 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}` },
}; };
@ -386,6 +395,7 @@ 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",
@ -426,6 +436,7 @@ 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",
@ -473,6 +484,7 @@ 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",