import express from "express"; import { getBackupConfig, saveBackupConfig, validateBackupConfig, } from "../services/backupConfigService.js"; import { getWebdavConfig, saveWebdavConfig, validateWebdavConfig } from "../services/webdavConfigService.js"; import { checkWebdavLogin } from "../services/webdavService.js"; const configRouter = express.Router(); configRouter.get("/backup", (req, res, next) => { res.json(getBackupConfig()); }); configRouter.put("/backup", (req, res, next) => { validateBackupConfig(req.body) .then(() => { saveBackupConfig(req.body); res.status(204); res.send(); }) .catch((error) => { res.status(400); res.json(error.details); }); }); configRouter.get("/webdav", (req, res, next) => { res.json(getWebdavConfig()); }); configRouter.put("/webdav", (req, res, next) => { validateWebdavConfig(req.body) .then(() => { return checkWebdavLogin(req.body, true) }) .then(() => { saveWebdavConfig(req.body); res.status(204); res.send(); }) .catch((error) => { res.status(400); res.json(error.details ? error.details : error); }); }); export default configRouter;