hassio-nextcloud-backup/nextcloud_backup/backend/src/routes/config.ts

50 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-09-29 00:05:53 +02:00
import express from "express";
2022-09-29 12:42:25 +02:00
import {
getBackupConfig,
saveBackupConfig,
validateBackupConfig,
} from "../services/backupConfigService.js";
import { getWebdavConfig, saveWebdavConfig, validateWebdavConfig } from "../services/webdavConfigService.js";
import { checkWebdavLogin } from "../services/webdavService.js";
2022-09-29 00:05:53 +02:00
const configRouter = express.Router();
2022-09-29 12:42:25 +02:00
configRouter.get("/backup", (req, res, next) => {
res.json(getBackupConfig());
});
2022-09-29 00:05:53 +02:00
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);
});
});
2022-09-29 12:42:25 +02:00
configRouter.get("/webdav", (req, res, next) => {
res.json(getWebdavConfig());
});
configRouter.put("/webdav", (req, res, next) => {
validateWebdavConfig(req.body)
.then(() => {
return checkWebdavLogin(req.body, true)
})
2022-09-29 12:42:25 +02:00
.then(() => {
saveWebdavConfig(req.body);
res.status(204);
res.send();
})
.catch((error) => {
res.status(400);
res.json(error.details ? error.details : error);
2022-09-29 12:42:25 +02:00
});
});
2022-09-29 00:05:53 +02:00
export default configRouter;