mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-07-07 05:21:40 -07:00
feat: es6+mods and replace node-cron with croner
This commit is contained in:
parent
19c92ed244
commit
ea828c326f
9 changed files with 10437 additions and 374 deletions
|
@ -1,13 +1,8 @@
|
|||
import express from "express";
|
||||
const router = express.Router();
|
||||
|
||||
import { isAuthorized } from "../services/auth.js";
|
||||
import {
|
||||
getNetworksData,
|
||||
createNetworkAdditionalData,
|
||||
updateNetworkAdditionalData,
|
||||
deleteNetworkAdditionalData,
|
||||
} from "../services/network.js";
|
||||
import * as auth from "../services/auth.js";
|
||||
import * as network from "../services/network.js";
|
||||
|
||||
import { api } from "../utils/controller-api.js";
|
||||
import { defaultRules } from "../utils/constants.js";
|
||||
|
@ -19,18 +14,18 @@ getZTAddress().then(function (address) {
|
|||
});
|
||||
|
||||
// get all networks
|
||||
router.get("/", isAuthorized, async function (req, res) {
|
||||
router.get("/", auth.isAuthorized, async function (req, res) {
|
||||
api.get("controller/network").then(async function (controllerRes) {
|
||||
const nwids = controllerRes.data;
|
||||
const data = await getNetworksData(nwids);
|
||||
const data = await network.getNetworksData(nwids);
|
||||
res.send(data);
|
||||
});
|
||||
});
|
||||
|
||||
// get network
|
||||
router.get("/:nwid", isAuthorized, async function (req, res) {
|
||||
router.get("/:nwid", auth.isAuthorized, async function (req, res) {
|
||||
const nwid = req.params.nwid;
|
||||
const data = await getNetworksData([nwid]);
|
||||
const data = await network.getNetworksData([nwid]);
|
||||
if (data[0]) {
|
||||
res.send(data[0]);
|
||||
} else {
|
||||
|
@ -39,7 +34,7 @@ router.get("/:nwid", isAuthorized, async function (req, res) {
|
|||
});
|
||||
|
||||
// create new network
|
||||
router.post("/", isAuthorized, async function (req, res) {
|
||||
router.post("/", auth.isAuthorized, async function (req, res) {
|
||||
let reqData = req.body;
|
||||
if (reqData.config) {
|
||||
const config = reqData.config;
|
||||
|
@ -52,36 +47,36 @@ router.post("/", isAuthorized, async function (req, res) {
|
|||
api
|
||||
.post("controller/network/" + ZT_ADDRESS + "______", reqData)
|
||||
.then(async function (controllerRes) {
|
||||
await createNetworkAdditionalData(controllerRes.data.id);
|
||||
const data = await getNetworksData([controllerRes.data.id]);
|
||||
await network.createNetworkAdditionalData(controllerRes.data.id);
|
||||
const data = await network.getNetworksData([controllerRes.data.id]);
|
||||
res.send(data[0]);
|
||||
});
|
||||
});
|
||||
|
||||
// update network
|
||||
router.post("/:nwid", isAuthorized, async function (req, res) {
|
||||
router.post("/:nwid", auth.isAuthorized, async function (req, res) {
|
||||
const nwid = req.params.nwid;
|
||||
updateNetworkAdditionalData(nwid, req.body);
|
||||
network.updateNetworkAdditionalData(nwid, req.body);
|
||||
if (req.body.config) {
|
||||
api
|
||||
.post("controller/network/" + nwid, req.body.config)
|
||||
.then(async function () {
|
||||
const data = await getNetworksData([nwid]);
|
||||
const data = await network.getNetworksData([nwid]);
|
||||
res.send(data[0]);
|
||||
})
|
||||
.catch(function (err) {
|
||||
res.status(500).send({ error: err.message });
|
||||
});
|
||||
} else {
|
||||
const data = await getNetworksData([nwid]);
|
||||
const data = await network.getNetworksData([nwid]);
|
||||
res.send(data[0]);
|
||||
}
|
||||
});
|
||||
|
||||
// delete network
|
||||
router.delete("/:nwid", isAuthorized, async function (req, res) {
|
||||
router.delete("/:nwid", auth.isAuthorized, async function (req, res) {
|
||||
const nwid = req.params.nwid;
|
||||
deleteNetworkAdditionalData(nwid);
|
||||
network.deleteNetworkAdditionalData(nwid);
|
||||
api
|
||||
.delete("controller/network/" + nwid)
|
||||
.then(function (controllerRes) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue