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

View File

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