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

61 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-09-27 23:38:40 +02:00
import express from "express";
2023-01-13 16:18:27 +01:00
import * as haOsService from "../services/homeAssistantService.js";
2024-07-22 11:20:43 +02:00
import { uploadToCloud } from "../services/orchestrator.js";
import logger from "../config/winston.js";
2022-09-27 23:38:40 +02:00
2022-09-29 00:05:53 +02:00
const homeAssistantRouter = express.Router();
2022-09-27 23:38:40 +02:00
2024-07-11 15:47:27 +02:00
homeAssistantRouter.get("/backups/", (req, res) => {
2023-01-13 16:18:27 +01:00
haOsService
.getBackups()
.then((value) => {
2024-07-11 15:47:27 +02:00
res.json(
value.body.data.backups.sort(
(a, b) => Date.parse(b.date) - Date.parse(a.date)
)
);
})
.catch((reason) => {
2024-07-22 11:20:10 +02:00
res.status(500).json(reason);
});
});
2024-07-11 15:47:27 +02:00
homeAssistantRouter.get("/backup/:slug", (req, res) => {
haOsService
.getBackupInfo(req.params.slug)
.then((value) => {
res.json(value.body.data);
2023-01-13 16:18:27 +01:00
})
.catch((reason) => {
2024-07-22 11:20:10 +02:00
res.status(500).json(reason);
2023-01-13 16:18:27 +01:00
});
});
2024-07-22 11:20:43 +02:00
homeAssistantRouter.post("/backup/:slug/upload", (req, res) => {
uploadToCloud(req.params.slug)
.then(() => {
logger.info("All good !");
})
.catch(() => {
logger.error("Something wrong !");
});
res.sendStatus(202);
});
2024-07-11 15:47:27 +02:00
homeAssistantRouter.get("/addons", (req, res) => {
2023-01-13 16:18:27 +01:00
haOsService
.getAddonList()
.then((value) => {
res.json(value.body.data);
2022-09-27 23:38:40 +02:00
})
2023-01-13 16:18:27 +01:00
.catch((reason) => {
2024-07-22 11:20:10 +02:00
res.status(500).json(reason);
2023-01-13 16:18:27 +01:00
});
2022-09-27 23:38:40 +02:00
});
2024-07-11 15:47:27 +02:00
homeAssistantRouter.get("/folders", (req, res) => {
2023-01-13 16:18:27 +01:00
res.json(haOsService.getFolderList());
});
2022-09-27 23:38:40 +02:00
2023-01-13 16:18:27 +01:00
export default homeAssistantRouter;