[Back] Check webdav cred in more places

This commit is contained in:
SebClem 2024-04-18 10:42:22 +02:00
parent 35aaae183b
commit b0070b1917
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
2 changed files with 14 additions and 1 deletions

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

@ -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(()=>{