Check webdav folder more often

This commit is contained in:
SebClem 2024-09-10 11:36:47 +02:00
parent f54bcdfc58
commit 43367602d9
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
2 changed files with 43 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import { WebdavDeleteValidation } from "../types/services/webdavValidation.js";
import { restoreToHA } from "../services/orchestrator.js";
import path from "path";
import logger from "../config/winston.js";
import { getStatus } from "../tools/status.js";
const webdavRouter = express.Router();
@ -22,6 +23,13 @@ webdavRouter.get("/backup/auto", (req, res) => {
.then(() => {
return webdavService.checkWebdavLogin(config);
})
.then(() => {
if (!getStatus().webdav.folder_created) {
return webdavService.createBackupFolder(config);
} else {
return Promise.resolve();
}
})
.then(async () => {
const value = await webdavService.getBackups(
pathTools.auto,
@ -43,6 +51,13 @@ webdavRouter.get("/backup/manual", (req, res) => {
.then(() => {
return webdavService.checkWebdavLogin(config);
})
.then(() => {
if (!getStatus().webdav.folder_created) {
return webdavService.createBackupFolder(config);
} else {
return Promise.resolve();
}
})
.then(async () => {
const value = await webdavService.getBackups(
pathTools.manual,
@ -68,6 +83,13 @@ webdavRouter.delete("/", (req, res) => {
.then(() => {
return webdavService.checkWebdavLogin(config);
})
.then(() => {
if (!getStatus().webdav.folder_created) {
return webdavService.createBackupFolder(config);
} else {
return Promise.resolve();
}
})
.then(() => {
webdavService
.deleteBackup(body.path, config)

View File

@ -42,6 +42,13 @@ export function doBackupWorkflow(type: WorkflowType) {
);
return webDavService.checkWebdavLogin(webdavConfig);
})
.then(() => {
if (!statusTools.getStatus().webdav.folder_created) {
return webDavService.createBackupFolder(webdavConfig);
} else {
return Promise.resolve();
}
})
.then(() => {
return homeAssistantService.stopAddons(addonsToStartStop);
})
@ -128,6 +135,13 @@ export function uploadToCloud(slug: string) {
return webDavService
.checkWebdavLogin(webdavConfig)
.then(() => {
if (!statusTools.getStatus().webdav.folder_created) {
return webDavService.createBackupFolder(webdavConfig);
} else {
return Promise.resolve();
}
})
.then(() => {
return homeAssistantService.getBackupInfo(slug);
})
@ -210,6 +224,13 @@ export function restoreToHA(webdavPath: string, filename: string) {
const webdavConfig = getWebdavConfig();
return webDavService
.checkWebdavLogin(webdavConfig)
.then(() => {
if (!statusTools.getStatus().webdav.folder_created) {
return webDavService.createBackupFolder(webdavConfig);
} else {
return Promise.resolve();
}
})
.then(() => {
return webDavService.downloadFile(webdavPath, filename, webdavConfig);
})