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

51 lines
1.1 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";
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) => {
res.status(500);
res.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) => {
2022-09-27 23:38:40 +02:00
res.status(500);
res.json(reason);
2023-01-13 16:18:27 +01:00
});
});
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) => {
res.status(500);
res.json(reason);
});
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;