mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-24 10:12:59 +01:00
Compare commits
9 Commits
93ada90d08
...
e1b27f8925
Author | SHA1 | Date | |
---|---|---|---|
|
e1b27f8925 | ||
|
2c155b1060 | ||
|
2f883e83ca | ||
|
ce23c6ac08 | ||
|
2850e2c054 | ||
|
c2b0236764 | ||
|
fdd4e5287e | ||
aa99b360d3 | |||
15ed577682 |
File diff suppressed because it is too large
Load Diff
@ -9,18 +9,18 @@
|
|||||||
"@fortawesome/fontawesome-free": "^5.15.3",
|
"@fortawesome/fontawesome-free": "^5.15.3",
|
||||||
"app-root-path": "^3.0.0",
|
"app-root-path": "^3.0.0",
|
||||||
"bootstrap": "^5.0.1",
|
"bootstrap": "^5.0.1",
|
||||||
"cookie-parser": "^1.4.5",
|
"cookie-parser": "^1.4.6",
|
||||||
"cron": "^1.8.2",
|
"cron": "^1.8.2",
|
||||||
"debug": "~4.3.1",
|
"debug": "~4.3.3",
|
||||||
"ejs": "~3.1.6",
|
"ejs": "~3.1.6",
|
||||||
"express": "~4.17.1",
|
"express": "~4.17.2",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"got": "^11.8.2",
|
"got": "^12.0.1",
|
||||||
"http-errors": "~1.8.0",
|
"http-errors": "~2.0.0",
|
||||||
"jquery": "^3.6.0",
|
"jquery": "^3.6.0",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
"morgan": "~1.10.0",
|
"morgan": "~1.10.0",
|
||||||
"webdav": "^4.5.0",
|
"webdav": "^4.8.0",
|
||||||
"winston": "^3.3.3"
|
"winston": "^3.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ function getVersion() {
|
|||||||
let token = process.env.HASSIO_TOKEN;
|
let token = process.env.HASSIO_TOKEN;
|
||||||
let status = statusTools.getStatus();
|
let status = statusTools.getStatus();
|
||||||
let option = {
|
let option = {
|
||||||
headers: { "X-HASSIO-KEY": token },
|
headers: { "Authorization": `Bearer ${token}` },
|
||||||
responseType: "json",
|
responseType: "json",
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ function getAddonList() {
|
|||||||
let token = process.env.HASSIO_TOKEN;
|
let token = process.env.HASSIO_TOKEN;
|
||||||
let status = statusTools.getStatus();
|
let status = statusTools.getStatus();
|
||||||
let option = {
|
let option = {
|
||||||
headers: { "X-HASSIO-KEY": token },
|
headers: { "Authorization": `Bearer ${token}` },
|
||||||
responseType: "json",
|
responseType: "json",
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,6 +97,8 @@ function getAddonToBackup() {
|
|||||||
if (!excluded_addon.includes(addon.slug))
|
if (!excluded_addon.includes(addon.slug))
|
||||||
slugs.push(addon.slug)
|
slugs.push(addon.slug)
|
||||||
}
|
}
|
||||||
|
logger.debug("Addon to backup:")
|
||||||
|
logger.debug(slugs)
|
||||||
resolve(slugs)
|
resolve(slugs)
|
||||||
})
|
})
|
||||||
.catch(() => reject());
|
.catch(() => reject());
|
||||||
@ -136,6 +138,8 @@ function getFolderToBackup() {
|
|||||||
if (!excluded_folder.includes(folder.slug))
|
if (!excluded_folder.includes(folder.slug))
|
||||||
slugs.push(folder.slug)
|
slugs.push(folder.slug)
|
||||||
}
|
}
|
||||||
|
logger.debug("Folders to backup:");
|
||||||
|
logger.debug(slugs)
|
||||||
return slugs;
|
return slugs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,11 +148,11 @@ function getSnapshots() {
|
|||||||
let token = process.env.HASSIO_TOKEN;
|
let token = process.env.HASSIO_TOKEN;
|
||||||
let status = statusTools.getStatus();
|
let status = statusTools.getStatus();
|
||||||
let option = {
|
let option = {
|
||||||
headers: { "X-HASSIO-KEY": token },
|
headers: { "Authorization": `Bearer ${token}` },
|
||||||
responseType: "json",
|
responseType: "json",
|
||||||
};
|
};
|
||||||
|
|
||||||
got("http://hassio/snapshots", option)
|
got("http://hassio/backups", option)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (status.error_code === 1) {
|
if (status.error_code === 1) {
|
||||||
status.status = "idle";
|
status.status = "idle";
|
||||||
@ -156,7 +160,7 @@ function getSnapshots() {
|
|||||||
status.error_code = null;
|
status.error_code = null;
|
||||||
statusTools.setStatus(status);
|
statusTools.setStatus(status);
|
||||||
}
|
}
|
||||||
let snaps = result.body.data.snapshots;
|
let snaps = result.body.data.backups;
|
||||||
resolve(snaps);
|
resolve(snaps);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@ -184,11 +188,11 @@ function downloadSnapshot(id) {
|
|||||||
status.progress = 0;
|
status.progress = 0;
|
||||||
statusTools.setStatus(status);
|
statusTools.setStatus(status);
|
||||||
let option = {
|
let option = {
|
||||||
headers: { "X-HASSIO-KEY": token },
|
headers: { "Authorization": `Bearer ${token}` },
|
||||||
};
|
};
|
||||||
|
|
||||||
pipeline(
|
pipeline(
|
||||||
got.stream.get(`http://hassio/snapshots/${id}/download`, option)
|
got.stream.get(`http://hassio/backups/${id}/download`, option)
|
||||||
.on("downloadProgress", (e) => {
|
.on("downloadProgress", (e) => {
|
||||||
let percent = Math.round(e.percent * 100) / 100;
|
let percent = Math.round(e.percent * 100) / 100;
|
||||||
if (status.progress !== percent) {
|
if (status.progress !== percent) {
|
||||||
@ -233,11 +237,11 @@ function dellSnap(id) {
|
|||||||
let token = process.env.HASSIO_TOKEN;
|
let token = process.env.HASSIO_TOKEN;
|
||||||
|
|
||||||
let option = {
|
let option = {
|
||||||
headers: { "X-HASSIO-KEY": token },
|
headers: { "Authorization": `Bearer ${token}` },
|
||||||
responseType: "json",
|
responseType: "json",
|
||||||
};
|
};
|
||||||
|
|
||||||
got.post(`http://hassio/snapshots/${id}/remove`, option)
|
got.post(`http://hassio/backups/${id}/remove`, option)
|
||||||
.then(() => resolve())
|
.then(() => resolve())
|
||||||
.catch(() => reject());
|
.catch(() => reject());
|
||||||
})
|
})
|
||||||
@ -251,11 +255,11 @@ function checkSnap(id) {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let token = process.env.HASSIO_TOKEN;
|
let token = process.env.HASSIO_TOKEN;
|
||||||
let option = {
|
let option = {
|
||||||
headers: { "X-HASSIO-KEY": token },
|
headers: { "Authorization": `Bearer ${token}` },
|
||||||
responseType: "json",
|
responseType: "json",
|
||||||
};
|
};
|
||||||
|
|
||||||
got(`http://hassio/snapshots/${id}/info`, option)
|
got(`http://hassio/backups/${id}/info`, option)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
logger.debug(`Snapshot size: ${result.body.data.size}`);
|
logger.debug(`Snapshot size: ${result.body.data.size}`);
|
||||||
resolve();
|
resolve();
|
||||||
@ -275,7 +279,7 @@ function createNewBackup(name) {
|
|||||||
getAddonToBackup().then((addons) => {
|
getAddonToBackup().then((addons) => {
|
||||||
let folders = getFolderToBackup();
|
let folders = getFolderToBackup();
|
||||||
let option = {
|
let option = {
|
||||||
headers: { "X-HASSIO-KEY": token },
|
headers: { "Authorization": `Bearer ${token}` },
|
||||||
responseType: "json",
|
responseType: "json",
|
||||||
timeout: create_snap_timeout,
|
timeout: create_snap_timeout,
|
||||||
json: {
|
json: {
|
||||||
@ -288,7 +292,7 @@ function createNewBackup(name) {
|
|||||||
option.json.password = settingsTools.getSettings().password_protect_value
|
option.json.password = settingsTools.getSettings().password_protect_value
|
||||||
}
|
}
|
||||||
|
|
||||||
got.post(`http://hassio/snapshots/new/partial`, option)
|
got.post(`http://hassio/backups/new/partial`, option)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
logger.info(`Snapshot created with id ${result.body.data.slug}`);
|
logger.info(`Snapshot created with id ${result.body.data.slug}`);
|
||||||
resolve(result.body.data.slug);
|
resolve(result.body.data.slug);
|
||||||
@ -354,11 +358,11 @@ function uploadSnapshot(path) {
|
|||||||
body: form,
|
body: form,
|
||||||
username: this.username,
|
username: this.username,
|
||||||
password: this.password,
|
password: this.password,
|
||||||
headers: { "X-HASSIO-KEY": token },
|
headers: { "Authorization": `Bearer ${token}` },
|
||||||
};
|
};
|
||||||
|
|
||||||
got.stream
|
got.stream
|
||||||
.post(`http://hassio/snapshots/new/upload`, options)
|
.post(`http://hassio/backups/new/upload`, options)
|
||||||
.on("uploadProgress", (e) => {
|
.on("uploadProgress", (e) => {
|
||||||
let percent = e.percent;
|
let percent = e.percent;
|
||||||
if (status.progress !== percent) {
|
if (status.progress !== percent) {
|
||||||
@ -413,7 +417,7 @@ function stopAddons() {
|
|||||||
let promises = [];
|
let promises = [];
|
||||||
let token = process.env.HASSIO_TOKEN;
|
let token = process.env.HASSIO_TOKEN;
|
||||||
let option = {
|
let option = {
|
||||||
headers: { "X-HASSIO-KEY": token },
|
headers: { "Authorization": `Bearer ${token}` },
|
||||||
responseType: "json",
|
responseType: "json",
|
||||||
};
|
};
|
||||||
let addons_slug = settingsTools.getSettings().auto_stop_addon
|
let addons_slug = settingsTools.getSettings().auto_stop_addon
|
||||||
@ -496,72 +500,72 @@ function startAddons() {
|
|||||||
|
|
||||||
function publish_state(state){
|
function publish_state(state){
|
||||||
|
|
||||||
let data_error_sensor = {
|
// let data_error_sensor = {
|
||||||
state: state.status == "error" ? "on" : "off",
|
// state: state.status == "error" ? "on" : "off",
|
||||||
attributes: {
|
// attributes: {
|
||||||
friendly_name: "Nexcloud Backup Error",
|
// friendly_name: "Nexcloud Backup Error",
|
||||||
device_class: "problem",
|
// device_class: "problem",
|
||||||
error_code: state.error_code,
|
// error_code: state.error_code,
|
||||||
message: state.message,
|
// message: state.message,
|
||||||
icon: state.status == "error" ? "mdi:cloud-alert" : "mdi:cloud-check"
|
// icon: state.status == "error" ? "mdi:cloud-alert" : "mdi:cloud-check"
|
||||||
},
|
// },
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
let token = process.env.HASSIO_TOKEN;
|
// let token = process.env.HASSIO_TOKEN;
|
||||||
let option = {
|
// let option = {
|
||||||
headers: { "Authorization": `Bearer ${token}` },
|
// headers: { "Authorization": `Bearer ${token}` },
|
||||||
responseType: "json",
|
// responseType: "json",
|
||||||
json: data_error_sensor
|
// json: data_error_sensor
|
||||||
};
|
// };
|
||||||
got.post(`http://hassio/core/api/states/binary_sensor.nextcloud_backup_error`, option)
|
// got.post(`http://hassio/core/api/states/binary_sensor.nextcloud_backup_error`, option)
|
||||||
.then((result) => {
|
// .then((result) => {
|
||||||
logger.debug('Home assistant sensor updated (error status)');
|
// logger.debug('Home assistant sensor updated (error status)');
|
||||||
})
|
// })
|
||||||
.catch((error) => {
|
// .catch((error) => {
|
||||||
logger.error(error);
|
// logger.error(error);
|
||||||
});
|
// });
|
||||||
|
|
||||||
let icon = ""
|
// let icon = ""
|
||||||
switch(state.status){
|
// switch(state.status){
|
||||||
case "error":
|
// case "error":
|
||||||
icon = "mdi:cloud-alert";
|
// icon = "mdi:cloud-alert";
|
||||||
break;
|
// break;
|
||||||
case "download":
|
// case "download":
|
||||||
case "download-b":
|
// case "download-b":
|
||||||
icon = "mdi:cloud-download";
|
// icon = "mdi:cloud-download";
|
||||||
break;
|
// break;
|
||||||
case "upload":
|
// case "upload":
|
||||||
case "upload-b":
|
// case "upload-b":
|
||||||
icon = "mdi:cloud-upload";
|
// icon = "mdi:cloud-upload";
|
||||||
break;
|
// break;
|
||||||
case "idle":
|
// case "idle":
|
||||||
icon = "mdi:cloud-check";
|
// icon = "mdi:cloud-check";
|
||||||
break;
|
// break;
|
||||||
default:
|
// default:
|
||||||
icon = "mdi:cloud-sync";
|
// icon = "mdi:cloud-sync";
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
let data_state_sensor = {
|
// let data_state_sensor = {
|
||||||
state: state.status,
|
// state: state.status,
|
||||||
attributes: {
|
// attributes: {
|
||||||
friendly_name: "Nexcloud Backup Status",
|
// friendly_name: "Nexcloud Backup Status",
|
||||||
error_code: state.error_code,
|
// error_code: state.error_code,
|
||||||
message: state.message,
|
// message: state.message,
|
||||||
icon: icon,
|
// icon: icon,
|
||||||
last_backup: state.last_backup == null || state.last_backup == "" ? "" : new Date(state.last_backup).toISOString(),
|
// last_backup: state.last_backup == null || state.last_backup == "" ? "" : new Date(state.last_backup).toISOString(),
|
||||||
next_backup: state.next_backup == null || state.next_backup == "" ? "" : new Date(state.next_backup).toISOString()
|
// next_backup: state.next_backup == null || state.next_backup == "" ? "" : new Date(state.next_backup).toISOString()
|
||||||
},
|
// },
|
||||||
}
|
// }
|
||||||
option.json = data_state_sensor
|
// option.json = data_state_sensor
|
||||||
got.post(`http://hassio/core/api/states/sensor.nextcloud_backup_status`, option)
|
// got.post(`http://hassio/core/api/states/sensor.nextcloud_backup_status`, option)
|
||||||
.then((result) => {
|
// .then((result) => {
|
||||||
logger.debug('Home assistant sensor updated (status)');
|
// logger.debug('Home assistant sensor updated (status)');
|
||||||
})
|
// })
|
||||||
.catch((error) => {
|
// .catch((error) => {
|
||||||
logger.error(error);
|
// logger.error(error);
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getVersion = getVersion;
|
exports.getVersion = getVersion;
|
||||||
|
Loading…
Reference in New Issue
Block a user