Compare commits

...

7 Commits

22 changed files with 453 additions and 119 deletions

View File

@ -8,4 +8,5 @@
"javascript.inlayHints.propertyDeclarationTypes.enabled": true,
"javascript.inlayHints.parameterNames.suppressWhenArgumentMatchesName": true,
"javascript.inlayHints.parameterNames.enabled": "literals",
"editor.formatOnSave": true
}

View File

@ -69,11 +69,6 @@ function postInit() {
settingsTools.check(settingsTools.getSettings(), true);
// cronTools.init();
messageManager.error("this is error");
messageManager.info("This is info");
messageManager.warn("re gerg rg ergrge r ");
messageManager.success("zefzegz gze gerg erg zegfze gerg erg aeferg erg erg er");
}
export default postInit;

View File

@ -3,6 +3,7 @@ import configRouter from "./config.js";
import homeAssistant from "./homeAssistant.js"
import messageRouter from "./messages.js";
import webdavRouter from "./webdav.js";
import statusRouter from "./status.js";
const router = express.Router();
@ -10,6 +11,7 @@ const router = express.Router();
router.use("/homeAssistant", homeAssistant)
router.use("/config", configRouter);
router.use("/webdav", webdavRouter);
router.use("/messages", messageRouter)
router.use("/messages", messageRouter);
router.use('/status', statusRouter);
export default router;

View File

@ -5,6 +5,7 @@ import {
validateBackupConfig,
} from "../services/backupConfigService.js";
import { getWebdavConfig, saveWebdavConfig, validateWebdavConfig } from "../services/webdavConfigService.js";
import { checkWebdavLogin } from "../services/webdavService.js";
const configRouter = express.Router();
@ -31,6 +32,9 @@ configRouter.get("/webdav", (req, res, next) => {
configRouter.put("/webdav", (req, res, next) => {
validateWebdavConfig(req.body)
.then(() => {
return checkWebdavLogin(req.body, true)
})
.then(() => {
saveWebdavConfig(req.body);
res.status(204);
@ -38,7 +42,7 @@ configRouter.put("/webdav", (req, res, next) => {
})
.catch((error) => {
res.status(400);
res.json(error.details);
res.json(error.details ? error.details : error);
});
});

View File

@ -0,0 +1,12 @@
import express from "express";
import { getStatus } from "../tools/status.js";
const statusRouter = express.Router();
statusRouter.get('/', (req, res) => {
res.json(getStatus());
})
export default statusRouter

View File

@ -16,6 +16,9 @@ webdavRouter.get("/backup/auto", (req, res, next) => {
const config = getWebdavConfig();
const backupConf = getBackupConfig();
validateWebdavConfig(config)
.then(() => {
return webdavService.checkWebdavLogin(config);
})
.then(async () => {
const value = await webdavService
.getBackups(pathTools.auto, config, backupConf.nameTemplate);
@ -31,6 +34,9 @@ webdavRouter.get("/backup/manual", (req, res, next) => {
const config = getWebdavConfig();
const backupConf = getBackupConfig();
validateWebdavConfig(config)
.then(() => {
return webdavService.checkWebdavLogin(config);
})
.then(async () => {
const value = await webdavService
.getBackups(pathTools.manual, config, backupConf.nameTemplate);
@ -49,6 +55,9 @@ webdavRouter.delete("/", (req, res, next) => {
validateWebdavConfig(config).then(() => {
validator
.validateAsync(body)
.then(() => {
return webdavService.checkWebdavLogin(config);
})
.then(() => {
webdavService.deleteBackup(body.path, config)
.then(()=>{

View File

@ -1,7 +1,12 @@
import fs from "fs";
import FormData from "form-data";
import got, { type OptionsOfJSONResponseBody, type Response } from "got";
import got, {
RequestError,
type OptionsOfJSONResponseBody,
type PlainResponse,
type Response,
} from "got";
import stream from "stream";
import { promisify } from "util";
import logger from "../config/winston.js";
@ -18,7 +23,8 @@ import type {
CoreInfoBody,
SupervisorResponse,
} from "../types/services/ha_os_response.js";
import type { Status } from "../types/status.js";
import { States, type Status } from "../types/status.js";
import { DateTime } from "luxon";
const pipeline = promisify(stream.pipeline);
@ -86,7 +92,6 @@ function getAddonToBackup(addons: AddonModel[]) {
return slugs;
}
function getFolderToBackup() {
const excluded_folder = settingsTools.getSettings().exclude_folder;
const all_folder = getFolderList();
@ -109,9 +114,17 @@ function getBackups(): Promise<Response<SupervisorResponse<BackupData>>> {
option
).then(
(result) => {
const status = statusTools.getStatus();
status.hass.ok = true;
status.hass.last_check = DateTime.now();
statusTools.setStatus(status);
return result;
},
(error) => {
const status = statusTools.getStatus();
status.hass.ok = false;
status.hass.last_check = DateTime.now();
statusTools.setStatus(status);
messageManager.error("Fail to fetch Hassio backups", error?.message);
return Promise.reject(error);
}
@ -126,7 +139,7 @@ function downloadSnapshot(id: string): Promise<string> {
const tmp_file = `./temp/${id}.tar`;
const stream = fs.createWriteStream(tmp_file);
const status = statusTools.getStatus();
status.status = "download";
status.status = States.BKUP_DOWNLOAD_HA;
status.progress = 0;
statusTools.setStatus(status);
const option = {
@ -147,7 +160,9 @@ function downloadSnapshot(id: string): Promise<string> {
).then(
() => {
logger.info("Download success !");
status.progress = 1;
const status = statusTools.getStatus();
status.status = States.IDLE;
status.progress = undefined;
statusTools.setStatus(status);
logger.debug(
"Snapshot dl size : " + fs.statSync(tmp_file).size / 1024 / 1024
@ -160,6 +175,10 @@ function downloadSnapshot(id: string): Promise<string> {
"Fail to download Home Assistant backup",
reason.message
);
const status = statusTools.getStatus();
status.status = States.IDLE;
status.progress = undefined;
statusTools.setStatus(status);
return Promise.reject(reason);
}
);
@ -217,7 +236,7 @@ function createNewBackup(
folders: string[]
) {
const status = statusTools.getStatus();
status.status = "creating";
status.status = States.BKUP_CREATION;
status.progress = -1;
statusTools.setStatus(status);
logger.info("Creating new snapshot...");
@ -248,12 +267,20 @@ function createNewBackup(
.then(
(result) => {
logger.info(`Snapshot created with id ${result.body.data.slug}`);
const status = statusTools.getStatus();
status.status = States.IDLE;
status.progress = undefined;
statusTools.setStatus(status);
return result;
},
(reason) => {
messageManager.error("Fail to create new backup.", reason.message);
logger.error("Fail to create new backup");
logger.error(reason);
const status = statusTools.getStatus();
status.status = States.IDLE;
status.progress = undefined;
statusTools.setStatus(status);
return Promise.reject(reason);
}
);
@ -297,6 +324,7 @@ function clean(backups: BackupModel[]) {
function uploadSnapshot(path: string) {
return new Promise((resolve, reject) => {
const status = statusTools.getStatus();
status.status = States.BKUP_UPLOAD_HA;
status.progress = 0;
statusTools.setStatus(status);
logger.info("Uploading backup...");
@ -320,22 +348,36 @@ function uploadSnapshot(path: string) {
logger.info("Upload done...");
}
})
.on("response", (res) => {
.on("response", (res: PlainResponse) => {
if (res.statusCode !== 200) {
logger.error(status.message);
messageManager.error(
"Fail to upload backup to Home Assistant",
`Code: ${res.statusCode} Body: ${res.body}`
);
logger.error("Fail to upload backup to Home Assistant");
logger.error(`Code: ${res.statusCode}`);
logger.error(`Body: ${res.body}`);
fs.unlinkSync(path);
reject(status.message);
reject(res.statusCode);
} else {
logger.info(`...Upload finish ! (status: ${res.statusCode})`);
const status = statusTools.getStatus();
status.status = States.IDLE;
status.progress = undefined;
statusTools.setStatus(status);
fs.unlinkSync(path);
resolve(res);
}
})
.on("error", (err) => {
.on("error", (err: RequestError) => {
const status = statusTools.getStatus();
status.status = States.IDLE;
status.progress = undefined;
statusTools.setStatus(status);
fs.unlinkSync(path);
messageManager.error(
"Fail to upload backup to Home Assistant",
err?.message
err.message
);
logger.error("Fail to upload backup to Home Assistant");
logger.error(err);
@ -346,6 +388,10 @@ function uploadSnapshot(path: string) {
function stopAddons(addonSlugs: string[]) {
logger.info("Stopping addons...");
const status = statusTools.getStatus();
status.status = States.STOP_ADDON;
status.progress = -1;
statusTools.setStatus(status);
const promises = [];
const option: OptionsOfJSONResponseBody = {
headers: { authorization: `Bearer ${token}` },
@ -359,11 +405,16 @@ function stopAddons(addonSlugs: string[]) {
}
return Promise.allSettled(promises).then((values) => {
let errors = false;
const status = statusTools.getStatus();
status.status = States.IDLE;
status.progress = undefined;
statusTools.setStatus(status);
for (const val of values) {
if (val.status == "rejected") {
messageManager.error("Fail to stop addon", val.reason);
logger.error("Fail to stop addon");
logger.error(val.reason);
logger.error;
errors = true;
}
}
@ -378,7 +429,7 @@ function stopAddons(addonSlugs: string[]) {
function startAddons(addonSlugs: string[]) {
logger.info("Starting addons...");
const status = statusTools.getStatus();
status.status = "starting";
status.status = States.START_ADDON;
status.progress = -1;
statusTools.setStatus(status);
const promises = [];
@ -393,6 +444,10 @@ function startAddons(addonSlugs: string[]) {
}
}
return Promise.allSettled(promises).then((values) => {
const status = statusTools.getStatus();
status.status = States.IDLE;
status.progress = undefined;
statusTools.setStatus(status);
let errors = false;
for (const val of values) {
if (val.status == "rejected") {
@ -435,7 +490,6 @@ export function getFolderList() {
];
}
function publish_state(state: Status) {
// let data_error_sensor = {
// state: state.status == "error" ? "on" : "off",
@ -511,5 +565,5 @@ export {
startAddons,
clean,
publish_state,
getBackupInfo
getBackupInfo,
};

View File

@ -1,6 +1,11 @@
import { XMLParser } from "fast-xml-parser";
import { createReadStream, statSync, unlinkSync } from "fs";
import got, { HTTPError, type Method } from "got";
import { createReadStream, stat, statSync, unlinkSync } from "fs";
import got, {
HTTPError,
RequestError,
type Method,
type PlainResponse,
} from "got";
import { DateTime } from "luxon";
import logger from "../config/winston.js";
import messageManager from "../tools/messageManager.js";
@ -10,7 +15,7 @@ import type { WebdavBackup } from "../types/services/webdav.js";
import type { WebdavConfig } from "../types/services/webdavConfig.js";
import { templateToRegexp } from "./backupConfigService.js";
import { getEndpoint } from "./webdavConfigService.js";
import { WebdabStatus } from "../types/status.js";
import { States } from "../types/status.js";
const PROPFIND_BODY =
'<?xml version="1.0" encoding="utf-8" ?>\
@ -24,7 +29,10 @@ const PROPFIND_BODY =
</d:prop>\
</d:propfind>';
export function checkWebdavLogin(config: WebdavConfig) {
export function checkWebdavLogin(
config: WebdavConfig,
silent: boolean = false
) {
const endpoint = getEndpoint(config);
return got(config.url + endpoint, {
method: "OPTIONS",
@ -35,16 +43,21 @@ export function checkWebdavLogin(config: WebdavConfig) {
},
}).then(
(response) => {
const status = statusTools.getStatus();
status.webdav.logged_in = true;
status.webdav.last_check = DateTime.now();
return response;
},
(reason) => {
messageManager.error("Fail to connect to Webdav", reason?.message);
if (!silent) {
messageManager.error("Fail to connect to Webdav", reason?.message);
}
const status = statusTools.getStatus();
status.webdav = {
state: WebdabStatus.LOGIN_FAIL,
blocked: true,
last_check: DateTime.now()
}
logged_in: false,
folder_created: status.webdav.folder_created,
last_check: DateTime.now(),
};
statusTools.setStatus(status);
logger.error(`Fail to connect to Webdav`);
logger.error(reason);
@ -70,11 +83,8 @@ export async function createBackupFolder(conf: WebdavConfig) {
logger.error("Fail to create webdav root folder");
logger.error(error);
const status = statusTools.getStatus();
status.webdav = {
state: WebdabStatus.MK_FOLDER_FAIL,
blocked: true,
last_check: DateTime.now()
}
status.webdav.folder_created = false;
status.webdav.last_check = DateTime.now();
statusTools.setStatus(status);
return Promise.reject(error);
}
@ -92,10 +102,18 @@ export async function createBackupFolder(conf: WebdavConfig) {
messageManager.error("Fail to create webdav root folder");
logger.error("Fail to create webdav root folder");
logger.error(error);
const status = statusTools.getStatus();
status.webdav.folder_created = false;
status.webdav.last_check = DateTime.now();
statusTools.setStatus(status);
return Promise.reject(error);
}
}
}
const status = statusTools.getStatus();
status.webdav.folder_created = true;
status.webdav.last_check = DateTime.now();
statusTools.setStatus(status);
}
function createDirectory(path: string, config: WebdavConfig) {
@ -115,6 +133,10 @@ export function getBackups(
config: WebdavConfig,
nameTemplate: string
) {
const status = statusTools.getStatus();
if (!status.webdav.logged_in && !status.webdav.folder_created) {
return Promise.reject("Not logged in");
}
const endpoint = getEndpoint(config);
return got(config.url + endpoint + config.backupDir + folder, {
method: "PROPFIND" as Method,
@ -160,8 +182,8 @@ function extractBackupInfo(backups: WebdavBackup[], template: string) {
elem.creationDate = DateTime.fromFormat(date, format);
}
if(match?.groups?.version){
elem.haVersion = match.groups.version
if (match?.groups?.version) {
elem.haVersion = match.groups.version;
}
}
return backups;
@ -224,13 +246,14 @@ function parseXmlBackupData(body: string, config: WebdavConfig) {
return backups;
}
export function webdabUploadFile(
export function webdavUploadFile(
localPath: string,
webdavPath: string,
config: WebdavConfig
) {
return new Promise((resolve, reject) => {
logger.info(`Uploading ${localPath} to webdav...`);
const stats = statSync(localPath);
const stream = createReadStream(localPath);
const options = {
@ -251,6 +274,9 @@ export function webdabUploadFile(
logger.debug(`...URI: ${encodeURI(url)}`);
logger.debug(`...rejectUnauthorized: ${options.https?.rejectUnauthorized}`);
const status = statusTools.getStatus();
status.status = States.BKUP_UPLOAD_CLOUD;
status.progress = 0;
statusTools.setStatus(status);
got.stream
.put(encodeURI(url), options)
.on("uploadProgress", (e) => {
@ -263,16 +289,19 @@ export function webdabUploadFile(
logger.info("Upload done...");
}
})
.on("response", (res) => {
.on("response", (res: PlainResponse) => {
const status = statusTools.getStatus();
status.status = States.IDLE;
status.progress = undefined;
statusTools.setStatus(status);
if (res.statusCode != 201 && res.statusCode != 204) {
messageManager.error(
"Fail to upload file to webdav.",
`Status code: ${res.statusCode}`
"Fail to upload file to Cloud.",
`Code: ${res.statusCode} Body: ${res.body}`
);
logger.error(
`Fail to upload file to webdav, Status code: ${res.statusCode}`
);
logger.error(status.message);
logger.error(`Fail to upload file to Cloud`);
logger.error(`Code: ${res.statusCode}`);
logger.error(`Body: ${res.body}`);
unlinkSync(localPath);
reject(res);
} else {
@ -281,10 +310,16 @@ export function webdabUploadFile(
resolve(undefined);
}
})
.on("error", (err) => {
logger.error(status.message);
logger.error(err.stack);
reject(status.message);
.on("error", (err: RequestError) => {
const status = statusTools.getStatus();
status.status = States.IDLE;
status.progress = undefined;
statusTools.setStatus(status);
messageManager.error("Fail to upload backup to Cloud", err.message);
logger.error("Fail to upload backup to Cloud");
logger.error(err);
unlinkSync(localPath);
reject(err);
});
});
}

View File

@ -1,25 +1,27 @@
import { publish_state } from "../services/homeAssistantService.js";
import logger from "../config/winston.js";
import { type Status, WebdabStatus } from "../types/status.js";
import { States, type Status } from "../types/status.js";
import { DateTime } from "luxon";
let status: Status = {
status: "idle",
last_backup: undefined,
status: States.IDLE,
last_backup: {},
next_backup: undefined,
progress: -1,
progress: undefined,
webdav: {
state: WebdabStatus.INIT,
logged_in: false,
folder_created: false,
last_check: DateTime.now(),
},
hass: {
ok: false,
last_check: DateTime.now(),
blocked: true,
},
};
export function init() {
if (status.status !== "idle") {
status.status = "idle";
status.message = undefined;
status.progress = -1;
if (status.status !== States.IDLE) {
status.status = States.IDLE;
status.progress = undefined;
}
}
@ -34,13 +36,3 @@ export function setStatus(new_state: Status) {
publish_state(status);
}
}
export function setError(message: string, error_code: number) {
// Check if we don't have another error stored
if (status.status != "error") {
status.status = "error";
status.message = message;
status.error_code = error_code;
}
logger.error(message);
}

View File

@ -1,24 +1,32 @@
import type { DateTime } from "luxon";
export enum WebdabStatus {
OK = "OK",
LOGIN_FAIL = "LOGIN_FAIL",
UPLOAD_FAIL = "UPLOAD_FAIL",
CON_ERROR = "CON_ERROR",
INIT = "INIT",
MK_FOLDER_FAIL = "MK_FOLDER_FAIL"
export enum States {
IDLE = "IDLE",
BKUP_CREATION = "BKUP_CREATION",
BKUP_DOWNLOAD_HA = "BKUP_DOWNLOAD_HA",
BKUP_DOWNLOAD_CLOUD = "BKUP_DOWNLOAD_CLOUD",
BKUP_UPLOAD_HA = "BKUP_UPLOAD_HA",
BKUP_UPLOAD_CLOUD = "BKUP_UPLOAD_CLOUD",
STOP_ADDON = "STOP_ADDON",
START_ADDON = "START_ADDON",
}
export interface Status {
status: string;
progress: number;
last_backup?: string;
status: States;
progress?: number;
last_backup: {
success?: boolean;
last_success?: DateTime;
message?: string;
};
next_backup?: string;
message?: string;
error_code?: number;
webdav: {
state: WebdabStatus;
logged_in: boolean;
folder_created: boolean;
last_check: DateTime;
};
hass: {
ok: boolean;
last_check: DateTime;
blocked: boolean;
};
}

View File

@ -1,3 +1,3 @@
{
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
"recommendations": ["Vue.volar"]
}

View File

@ -26,6 +26,7 @@ declare module 'vue' {
NavbarComponent: typeof import('./src/components/NavbarComponent.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
StatusComponent: typeof import('./src/components/StatusComponent.vue')['default']
WebdavConfigForm: typeof import('./src/components/settings/WebdavConfigForm.vue')['default']
WebdavConfigMenu: typeof import('./src/components/settings/WebdavConfigMenu.vue')['default']
}

View File

@ -21,6 +21,7 @@
},
"devDependencies": {
"@babel/types": "^7.23.0",
"@types/luxon": "^3.4.2",
"@types/node": "^20.10.0",
"@vitejs/plugin-vue": "^4.5.0",
"@vue/eslint-config-typescript": "^12.0.0",

View File

@ -37,6 +37,9 @@ devDependencies:
'@babel/types':
specifier: ^7.23.0
version: 7.23.9
'@types/luxon':
specifier: ^3.4.2
version: 3.4.2
'@types/node':
specifier: ^20.10.0
version: 20.11.19
@ -526,6 +529,10 @@ packages:
resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==}
dev: true
/@types/luxon@3.4.2:
resolution: {integrity: sha512-TifLZlFudklWlMBfhubvgqTXRzLDI5pCbGa4P8a3wPyUQSW+1xQ5eDsreP9DWHX3tjq1ke96uYG/nwundroWcA==}
dev: true
/@types/node@20.11.19:
resolution: {integrity: sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ==}
dependencies:

View File

@ -2,16 +2,21 @@
<v-app>
<navbar-component></navbar-component>
<message-bar></message-bar>
<webdav-settings-menu></webdav-settings-menu>
<webdav-config-menu @saved="cloudList?.refreshBackup"></webdav-config-menu>
<backup-config-menu></backup-config-menu>
<alert-manager></alert-manager>
<v-main class="mx-12">
<v-row>
<v-col cols="4" offset="1">
<status-component></status-component>
</v-col>
</v-row>
<v-row>
<v-col cols="6">
<ha-list></ha-list>
</v-col>
<v-col cols="6">
<cloud-list></cloud-list>
<cloud-list ref="cloudList"></cloud-list>
</v-col>
</v-row>
</v-main>
@ -19,13 +24,16 @@
</template>
<script setup lang="ts">
import { ref } from "vue";
import AlertManager from "./components/AlertManager.vue";
import CloudList from "./components/cloud/CloudList.vue";
import HaList from "./components/homeAssistant/HaList.vue";
import MessageBar from "./components/MessageBar.vue";
import NavbarComponent from "./components/NavbarComponent.vue";
import BackupConfigMenu from "./components/settings/BackupConfigMenu.vue";
import WebdavSettingsMenu from "./components/settings/WebdavConfigMenu.vue";
import WebdavConfigMenu from "./components/settings/WebdavConfigMenu.vue";
import StatusComponent from "./components/StatusComponent.vue";
const cloudList = ref<InstanceType<typeof CloudList> | null>(null);
</script>
<style scoped></style>

View File

@ -11,9 +11,7 @@
class="mb-2"
>
<v-row dense>
<v-col>
{{ alert.message }}
</v-col>
<v-col v-html="alert.message"></v-col>
<v-col cols="2">
<v-btn
class="d-inline"

View File

@ -0,0 +1,130 @@
<template>
<div>
<v-card class="mt-5" border elevation="10">
<v-card-title class="text-center">Status</v-card-title>
<v-divider></v-divider>
<v-card-text>
<v-row>
<v-col cols="6">
<v-card variant="elevated" border>
<v-card-text class="align-center d-flex justify-center">
<span class="me-auto">Home Assistant</span>
<v-tooltip content-class="bg-black">
<template v-slot:activator="{ props }">
<v-chip
v-bind="props"
variant="elevated"
:prepend-icon="hassProps.icon"
:color="hassProps.color"
:text="hassProps.text"
>
</v-chip>
</template>
Last check:
{{
status?.hass.last_check
? DateTime.fromISO(status.hass.last_check).toLocaleString(
DateTime.DATETIME_MED
)
: "UNKNOWN"
}}
</v-tooltip>
</v-card-text>
</v-card>
</v-col>
<v-col cols="6">
<v-card variant="elevated" border>
<v-card-text class="align-center d-flex justify-center">
<span class="me-auto">Cloud</span>
<v-tooltip content-class="bg-black">
<template v-slot:activator="{ props }">
<v-chip
v-bind="props"
variant="elevated"
:prepend-icon="webdavProps.icon"
:color="webdavProps.color"
:text="webdavProps.text"
>
</v-chip>
</template>
<span>Login: </span>
<span :class="'text-' + webdavLoggedProps.color">
{{ webdavLoggedProps.text }}
</span>
<br />
<span>Folder: </span>
<span :class="'text-' + webdavFolderProps.color">
{{ webdavFolderProps.text }}
</span>
<p>
Last check:
{{
status?.webdav.last_check
? DateTime.fromISO(
status.webdav.last_check
).toLocaleString(DateTime.DATETIME_MED)
: "UNKNOWN"
}}
</p>
</v-tooltip>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-card-text>
</v-card>
</div>
</template>
<script setup lang="ts">
import { getStatus } from "@/services/statusService";
import { Status } from "@/types/status";
import { computed, ref, onBeforeUnmount } from "vue";
import { DateTime } from "luxon";
const status = ref<Status | undefined>(undefined);
function refreshStatus() {
getStatus().then((data) => {
status.value = data;
});
}
const webdavProps = computed(() => {
if (status.value?.webdav.logged_in && status.value?.webdav.folder_created) {
return { icon: "mdi-check", text: "Ok", color: "green" };
} else {
return { icon: "mdi-alert", text: "Fail", color: "red" };
}
});
const webdavLoggedProps = computed(() => {
if (status.value?.webdav.logged_in) {
return { text: "Ok", color: "green" };
} else {
return { text: "Fail", color: "red" };
}
});
const webdavFolderProps = computed(() => {
if (status.value?.webdav.folder_created) {
return { text: "Ok", color: "green" };
} else {
return { text: "Fail", color: "red" };
}
});
const hassProps = computed(() => {
if (status.value?.hass.ok) {
return { icon: "mdi-check", text: "Ok", color: "green" };
} else {
return { icon: "mdi-alert", text: "Fail", color: "red" };
}
});
refreshStatus();
const interval = setInterval(refreshStatus, 2000);
onBeforeUnmount(() => {
clearInterval(interval);
});
</script>

View File

@ -1,7 +1,20 @@
<template>
<div>
<v-card elevation="10" class="mt-10" border>
<v-card-title class="text-center"> Cloud </v-card-title>
<v-card elevation="10" border>
<v-row align="center" justify="center">
<v-col offset="2">
<v-card-title class="text-center"> Cloud </v-card-title>
</v-col>
<v-col cols="2">
<v-btn
class="float-right mr-2"
icon="mdi-refresh"
variant="text"
@click="refreshBackup"
:loading="loading"
></v-btn>
</v-col>
</v-row>
<v-divider></v-divider>
<v-card-text>
<v-row>
@ -81,13 +94,23 @@ const deleteDialog = ref<InstanceType<typeof CloudDeleteDialog> | null>(null);
const deleteItem = ref<WebdavBackup | null>(null);
const autoBackups = ref<WebdavBackup[]>([]);
const manualBackups = ref<WebdavBackup[]>([]);
const loading = ref<boolean>(true);
function refreshBackup() {
getAutoBackupList().then((value) => {
autoBackups.value = value;
});
getManualBackupList().then((value) => {
manualBackups.value = value;
});
loading.value = true;
getAutoBackupList()
.then((value) => {
autoBackups.value = value;
return getManualBackupList();
})
.then((value) => {
manualBackups.value = value;
loading.value = false;
})
.catch(() => {
loading.value = false;
});
}
function deleteBackup(item: WebdavBackup) {
@ -95,10 +118,5 @@ function deleteBackup(item: WebdavBackup) {
deleteDialog.value?.open(item);
}
refreshBackup();
const interval = setInterval(refreshBackup, 2000);
onBeforeUnmount(() => {
clearInterval(interval);
});
defineExpose({ refreshBackup });
</script>

View File

@ -1,7 +1,20 @@
<template>
<div>
<v-card elevation="10" class="mt-10" border>
<v-card-title class="text-center"> Home Assistant </v-card-title>
<v-card elevation="10" border>
<v-row align="center" justify="center">
<v-col offset="2">
<v-card-title class="text-center"> Home Assistant </v-card-title>
</v-col>
<v-col cols="2">
<v-btn
class="float-right mr-2"
icon="mdi-refresh"
variant="text"
@click="refreshBackup"
:loading="loading"
></v-btn>
</v-col>
</v-row>
<v-divider></v-divider>
<v-card-text>
<v-row>
@ -43,19 +56,19 @@ import { getBackups } from "@/services/homeAssistantService";
import HaListItem from "./HaListItem.vue";
const backups = ref<BackupModel[]>([]);
const loading = ref<boolean>(true);
function refreshBackup() {
loading.value = true;
getBackups().then((value) => {
backups.value = value;
});
loading.value = false;
}).catch(()=> {
loading.value = false;
})
}
refreshBackup();
const interval = setInterval(refreshBackup, 2000);
onBeforeUnmount(() => {
clearInterval(interval);
});
// TODO Manage delete
</script>

View File

@ -53,6 +53,10 @@ let saveLoading = computed(() => {
return saving.value || loading.value;
});
const emit = defineEmits<{
(e: "saved"): void;
}>();
function save() {
saving.value = true;
form.value?.save();
@ -60,13 +64,16 @@ function save() {
function fail() {
saving.value = false;
alertStore.add("error", "Fail to save cloud settings !");
alertStore.add(
"error",
"Fail to connect to Cloud<br>Please check credentials !"
);
}
function saved() {
dialogStatusStore.webdav = false;
saving.value = false;
alertStore.add("success", "Cloud settings saved !");
emit("saved");
}
</script>
@/store/alert@/store/dialogStatus

View File

@ -0,0 +1,7 @@
import type { WebdavBackup } from "@/types/webdav";
import kyClient from "./kyClient";
import { Status } from "@/types/status";
export function getStatus() {
return kyClient.get("status").json<Status>();
}

View File

@ -0,0 +1,32 @@
import type { DateTime } from "luxon";
export enum States {
IDLE = "IDLE",
BKUP_CREATION = "BKUP_CREATION",
BKUP_DOWNLOAD_HA = "BKUP_DOWNLOAD_HA",
BKUP_DOWNLOAD_CLOUD = "BKUP_DOWNLOAD_CLOUD",
BKUP_UPLOAD_HA = "BKUP_UPLOAD_HA",
BKUP_UPLOAD_CLOUD = "BKUP_UPLOAD_CLOUD",
STOP_ADDON = "STOP_ADDON",
START_ADDON = "START_ADDON",
}
export interface Status {
status: States;
progress?: number;
last_backup: {
success?: boolean;
last_success?: string;
message?: string;
};
next_backup?: string;
webdav: {
logged_in: boolean;
folder_created: boolean;
last_check: string;
};
hass: {
ok: boolean;
last_check: string;
};
}