Skip to content

Commit

Permalink
Check webdav folder more often
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebclem committed Sep 10, 2024
1 parent f54bcdf commit 4336760
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
22 changes: 22 additions & 0 deletions nextcloud_backup/backend/src/routes/webdav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions nextcloud_backup/backend/src/services/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down Expand Up @@ -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);
})
Expand Down Expand Up @@ -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);
})
Expand Down

0 comments on commit 4336760

Please sign in to comment.