From 43367602d91986f7a8535a19d80b28660b6978ba Mon Sep 17 00:00:00 2001 From: SebClem Date: Tue, 10 Sep 2024 11:36:47 +0200 Subject: [PATCH] Check webdav folder more often --- nextcloud_backup/backend/src/routes/webdav.ts | 22 +++++++++++++++++++ .../backend/src/services/orchestrator.ts | 21 ++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/nextcloud_backup/backend/src/routes/webdav.ts b/nextcloud_backup/backend/src/routes/webdav.ts index e821dd1..1e988d1 100644 --- a/nextcloud_backup/backend/src/routes/webdav.ts +++ b/nextcloud_backup/backend/src/routes/webdav.ts @@ -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) diff --git a/nextcloud_backup/backend/src/services/orchestrator.ts b/nextcloud_backup/backend/src/services/orchestrator.ts index 074cdb7..5125b96 100644 --- a/nextcloud_backup/backend/src/services/orchestrator.ts +++ b/nextcloud_backup/backend/src/services/orchestrator.ts @@ -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); })