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);
});
let manual_back_list = $(".manual-back-list");
manual_back_list.unbind();
manual_back_list.off();
manual_back_list.on("click", function () {
let id = this.getAttribute("data-id");
let name = this.getAttribute("data-name");
manualBackup(id, name);
});
let restore_btn = $(".restore");
restore_btn.unbind();
restore_btn.click(function () {
$(".restore").click(function () {
let to_restore = this.getAttribute("data-id");
console.log(to_restore);
restore(to_restore);

View File

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

View File

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