mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-24 02:02:59 +01:00
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
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";
|
|
import type { BackupConfig } from "../types/services/backupConfig.js";
|
|
import type { ValidationError } from "joi";
|
|
import type { WebdavConfig } from "../types/services/webdavConfig.js";
|
|
|
|
const configRouter = express.Router();
|
|
|
|
configRouter.get("/backup", (req, res) => {
|
|
res.json(getBackupConfig());
|
|
});
|
|
|
|
configRouter.put("/backup", (req, res) => {
|
|
validateBackupConfig(req.body as BackupConfig)
|
|
.then(() => {
|
|
saveBackupConfig(req.body as BackupConfig);
|
|
res.status(204).send();
|
|
})
|
|
.catch((error: ValidationError) => {
|
|
res.status(400).json(error.details);
|
|
});
|
|
});
|
|
|
|
configRouter.get("/webdav", (req, res) => {
|
|
res.json(getWebdavConfig());
|
|
});
|
|
|
|
configRouter.put("/webdav", (req, res) => {
|
|
validateWebdavConfig(req.body as WebdavConfig)
|
|
.then(() => {
|
|
return checkWebdavLogin(req.body as WebdavConfig, true);
|
|
})
|
|
.then(() => {
|
|
saveWebdavConfig(req.body as WebdavConfig);
|
|
res.status(204).send();
|
|
})
|
|
.catch((error: ValidationError) => {
|
|
res.status(400);
|
|
if (error.details) {
|
|
res.json(error.details);
|
|
} else {
|
|
res.json(error);
|
|
}
|
|
});
|
|
});
|
|
|
|
export default configRouter;
|