[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, validateBackupConfig,
} from "../services/backupConfigService.js"; } from "../services/backupConfigService.js";
import { getWebdavConfig, saveWebdavConfig, validateWebdavConfig } from "../services/webdavConfigService.js"; import { getWebdavConfig, saveWebdavConfig, validateWebdavConfig } from "../services/webdavConfigService.js";
import { checkWebdavLogin } from "../services/webdavService.js";
const configRouter = express.Router(); const configRouter = express.Router();
@ -31,6 +32,9 @@ configRouter.get("/webdav", (req, res, next) => {
configRouter.put("/webdav", (req, res, next) => { configRouter.put("/webdav", (req, res, next) => {
validateWebdavConfig(req.body) validateWebdavConfig(req.body)
.then(() => {
return checkWebdavLogin(req.body, true)
})
.then(() => { .then(() => {
saveWebdavConfig(req.body); saveWebdavConfig(req.body);
res.status(204); res.status(204);
@ -38,7 +42,7 @@ configRouter.put("/webdav", (req, res, next) => {
}) })
.catch((error) => { .catch((error) => {
res.status(400); 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 config = getWebdavConfig();
const backupConf = getBackupConfig(); const backupConf = getBackupConfig();
validateWebdavConfig(config) validateWebdavConfig(config)
.then(() => {
return webdavService.checkWebdavLogin(config);
})
.then(async () => { .then(async () => {
const value = await webdavService const value = await webdavService
.getBackups(pathTools.auto, config, backupConf.nameTemplate); .getBackups(pathTools.auto, config, backupConf.nameTemplate);
@ -31,6 +34,9 @@ webdavRouter.get("/backup/manual", (req, res, next) => {
const config = getWebdavConfig(); const config = getWebdavConfig();
const backupConf = getBackupConfig(); const backupConf = getBackupConfig();
validateWebdavConfig(config) validateWebdavConfig(config)
.then(() => {
return webdavService.checkWebdavLogin(config);
})
.then(async () => { .then(async () => {
const value = await webdavService const value = await webdavService
.getBackups(pathTools.manual, config, backupConf.nameTemplate); .getBackups(pathTools.manual, config, backupConf.nameTemplate);
@ -49,6 +55,9 @@ webdavRouter.delete("/", (req, res, next) => {
validateWebdavConfig(config).then(() => { validateWebdavConfig(config).then(() => {
validator validator
.validateAsync(body) .validateAsync(body)
.then(() => {
return webdavService.checkWebdavLogin(config);
})
.then(() => { .then(() => {
webdavService.deleteBackup(body.path, config) webdavService.deleteBackup(body.path, config)
.then(()=>{ .then(()=>{