mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-24 18:22:57 +01:00
Compare commits
5 Commits
f3c0b6787a
...
d1e31d2472
Author | SHA1 | Date | |
---|---|---|---|
d1e31d2472 | |||
02d2fd9ae3 | |||
27bda4d1c6 | |||
084af91620 | |||
fdaa188831 |
@ -29,13 +29,15 @@ function updateDynamicListeners() {
|
||||
console.log(id);
|
||||
});
|
||||
let manual_back_list = $(".manual-back-list");
|
||||
manual_back_list.off();
|
||||
manual_back_list.unbind();
|
||||
manual_back_list.on("click", function () {
|
||||
let id = this.getAttribute("data-id");
|
||||
let name = this.getAttribute("data-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");
|
||||
console.log(to_restore);
|
||||
restore(to_restore);
|
||||
|
@ -128,9 +128,15 @@ router.post("/manual-backup", function (req, res, next) {
|
||||
hassioApiTools
|
||||
.downloadSnapshot(id)
|
||||
.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.send();
|
||||
}).catch(()=>{
|
||||
res.status(500);
|
||||
res.send();
|
||||
}
|
||||
);
|
||||
|
||||
})
|
||||
.catch(() => {
|
||||
res.status(500);
|
||||
@ -159,10 +165,10 @@ router.post("/new-backup", function (req, res, next) {
|
||||
.then(() => {
|
||||
hassioApiTools.startAddons().catch(() => {
|
||||
})
|
||||
});
|
||||
}).catch(()=>{});
|
||||
}).catch(()=>{});
|
||||
}).catch(()=>{});;
|
||||
}).catch(()=>{});
|
||||
}).catch(()=>{});
|
||||
})
|
||||
.catch(() => {
|
||||
hassioApiTools.startAddons().catch(() => {
|
||||
|
@ -11,14 +11,14 @@ import logger from "../config/winston.js"
|
||||
|
||||
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);
|
||||
|
||||
|
||||
function getVersion() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let token = process.env.HASSIO_TOKEN;
|
||||
let status = statusTools.getStatus();
|
||||
let option = {
|
||||
headers: { "Authorization": `Bearer ${token}` },
|
||||
@ -45,7 +45,6 @@ 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}` },
|
||||
@ -139,7 +138,6 @@ 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}` },
|
||||
@ -170,7 +168,6 @@ 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(() => {
|
||||
@ -192,20 +189,20 @@ function downloadSnapshot(id) {
|
||||
}),
|
||||
stream
|
||||
)
|
||||
.then((res) => {
|
||||
.then(() => {
|
||||
logger.info("Download success !");
|
||||
status.progress = 1;
|
||||
statusTools.setStatus(status);
|
||||
logger.debug("Snapshot dl size : " + fs.statSync(tmp_file).size / 1024 / 1024);
|
||||
resolve();
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch((error) => {
|
||||
fs.unlinkSync(tmp_file);
|
||||
statusTools.setError(`Fail to download Hassio backup (${error.message})`, 7);
|
||||
reject(`Fail to download Hassio backup (${error.message})`);
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(() => {
|
||||
statusTools.setError("Fail to download Hassio backup. Not found ?", 7);
|
||||
reject();
|
||||
});
|
||||
@ -216,8 +213,6 @@ 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",
|
||||
@ -238,7 +233,6 @@ 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",
|
||||
@ -260,7 +254,6 @@ 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 = {
|
||||
@ -275,7 +268,9 @@ function createNewBackup(name) {
|
||||
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
|
||||
}
|
||||
|
||||
@ -333,15 +328,11 @@ 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}` },
|
||||
};
|
||||
|
||||
@ -395,7 +386,6 @@ 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",
|
||||
@ -436,7 +426,6 @@ 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",
|
||||
@ -484,7 +473,6 @@ function publish_state(state) {
|
||||
// }
|
||||
|
||||
|
||||
// let token = process.env.HASSIO_TOKEN;
|
||||
// let option = {
|
||||
// headers: { "Authorization": `Bearer ${token}` },
|
||||
// responseType: "json",
|
||||
|
Loading…
Reference in New Issue
Block a user