fix linting errors,
group more routes, use mergeParams in router init
This commit is contained in:
parent
76ccfabf59
commit
7fe1d2af5c
@ -24,8 +24,6 @@ app.use(morgan("combined"));
|
|||||||
// legacy defs
|
// legacy defs
|
||||||
const requestPVE = global.pve.requestPVE;
|
const requestPVE = global.pve.requestPVE;
|
||||||
const handleResponse = global.pve.handleResponse;
|
const handleResponse = global.pve.handleResponse;
|
||||||
const getDiskInfo = global.pve.getDiskInfo;
|
|
||||||
const getDeviceInfo = global.pve.getDeviceInfo;
|
|
||||||
const getNodeAvailDevices = global.pve.getNodeAvailDevices;
|
const getNodeAvailDevices = global.pve.getNodeAvailDevices;
|
||||||
const checkAuth = global.utils.checkAuth;
|
const checkAuth = global.utils.checkAuth;
|
||||||
const approveResources = global.utils.approveResources;
|
const approveResources = global.utils.approveResources;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
export const router = Router();
|
export const router = Router({ mergeParams: true }); ;
|
||||||
|
|
||||||
const domain = global.db.domain;
|
const domain = global.db.domain;
|
||||||
const checkAuth = global.utils.checkAuth;
|
const checkAuth = global.utils.checkAuth;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
export const router = Router();
|
export const router = Router({ mergeParams: true });
|
||||||
|
|
||||||
const nodeRegexP = "[\\w-]+";
|
const nodeRegexP = "[\\w-]+";
|
||||||
const typeRegexP = "qemu|lxc";
|
const typeRegexP = "qemu|lxc";
|
||||||
@ -8,22 +8,13 @@ const vmidRegexP = "\\d+";
|
|||||||
const basePath = `/:node(${nodeRegexP})/:type(${typeRegexP})/:vmid(${vmidRegexP})`;
|
const basePath = `/:node(${nodeRegexP})/:type(${typeRegexP})/:vmid(${vmidRegexP})`;
|
||||||
|
|
||||||
import("./cluster/disk.js").then((module) => {
|
import("./cluster/disk.js").then((module) => {
|
||||||
router.use(`${basePath}/disk`, (req, res, next) => {
|
router.use(`${basePath}/disk`, module.router);
|
||||||
req.routeparams = Object.assign({}, req.routeparams, req.params);
|
|
||||||
next();
|
|
||||||
}, module.router);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
import("./cluster/net.js").then((module) => {
|
import("./cluster/net.js").then((module) => {
|
||||||
router.use(`${basePath}/net`, (req, res, next) => {
|
router.use(`${basePath}/net`, module.router);
|
||||||
req.routeparams = Object.assign({}, req.routeparams, req.params);
|
|
||||||
next();
|
|
||||||
}, module.router);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
import("./cluster/pci.js").then((module) => {
|
import("./cluster/pci.js").then((module) => {
|
||||||
router.use(`${basePath}/pci`,(req, res, next) => {
|
router.use(`${basePath}/pci`, module.router);
|
||||||
req.routeparams = Object.assign({}, req.routeparams, req.params);
|
|
||||||
next();
|
|
||||||
}, module.router);
|
|
||||||
});
|
});
|
@ -1,6 +1,7 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
export const router = Router();
|
export const router = Router({ mergeParams: true });
|
||||||
|
|
||||||
|
const db = global.db;
|
||||||
const requestPVE = global.pve.requestPVE;
|
const requestPVE = global.pve.requestPVE;
|
||||||
const handleResponse = global.pve.handleResponse;
|
const handleResponse = global.pve.handleResponse;
|
||||||
const getDiskInfo = global.pve.getDiskInfo;
|
const getDiskInfo = global.pve.getDiskInfo;
|
||||||
@ -21,7 +22,7 @@ const pveAPIToken = global.db.pveAPIToken;
|
|||||||
* - 500: {error: string}
|
* - 500: {error: string}
|
||||||
* - 500: PVE Task Object
|
* - 500: PVE Task Object
|
||||||
*/
|
*/
|
||||||
router.post(`/:disk/detach`, async (req, res) => {
|
router.post("/:disk/detach", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
@ -69,7 +70,7 @@ router.post(`/:disk/detach`, async (req, res) => {
|
|||||||
* - 500: {error: string}
|
* - 500: {error: string}
|
||||||
* - 500: PVE Task Object
|
* - 500: PVE Task Object
|
||||||
*/
|
*/
|
||||||
router.post(`/:disk/attach`, async (req, res) => {
|
router.post("/:disk/attach", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
@ -125,7 +126,7 @@ router.post(`/:disk/attach`, async (req, res) => {
|
|||||||
* - 500: {request: Object, error: string}
|
* - 500: {request: Object, error: string}
|
||||||
* - 500: PVE Task Object
|
* - 500: PVE Task Object
|
||||||
*/
|
*/
|
||||||
router.post(`/:disk/resize`, async (req, res) => {
|
router.post("/:disk/resize", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
@ -179,7 +180,7 @@ router.post(`/:disk/resize`, async (req, res) => {
|
|||||||
* - 500: {request: Object, error: string}
|
* - 500: {request: Object, error: string}
|
||||||
* - 500: PVE Task Object
|
* - 500: PVE Task Object
|
||||||
*/
|
*/
|
||||||
router.post(`/:disk/move`, async (req, res) => {
|
router.post("/:disk/move", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
@ -243,7 +244,7 @@ router.post(`/:disk/move`, async (req, res) => {
|
|||||||
* - 500: {error: string}
|
* - 500: {error: string}
|
||||||
* - 500: PVE Task Object
|
* - 500: PVE Task Object
|
||||||
*/
|
*/
|
||||||
router.delete(`/:disk/delete`, async (req, res) => {
|
router.delete("/:disk/delete", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
@ -295,7 +296,7 @@ router.delete(`/:disk/delete`, async (req, res) => {
|
|||||||
* - 500: {request: Object, error: string}
|
* - 500: {request: Object, error: string}
|
||||||
* - 500: PVE Task Object
|
* - 500: PVE Task Object
|
||||||
*/
|
*/
|
||||||
router.post(`/:disk/create`, async (req, res) => {
|
router.post("/:disk/create", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
export const router = Router();
|
export const router = Router({ mergeParams: true }); ;
|
||||||
|
|
||||||
|
const db = global.db;
|
||||||
const requestPVE = global.pve.requestPVE;
|
const requestPVE = global.pve.requestPVE;
|
||||||
const handleResponse = global.pve.handleResponse;
|
const handleResponse = global.pve.handleResponse;
|
||||||
const checkAuth = global.utils.checkAuth;
|
const checkAuth = global.utils.checkAuth;
|
||||||
@ -23,7 +24,7 @@ const pveAPIToken = global.db.pveAPIToken;
|
|||||||
* - 500: {request: Object, error: string}
|
* - 500: {request: Object, error: string}
|
||||||
* - 500: PVE Task Object
|
* - 500: PVE Task Object
|
||||||
*/
|
*/
|
||||||
router.post(`/:netid/create`, async (req, res) => {
|
router.post("/:netid/create", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
@ -92,7 +93,7 @@ router.post(`/:netid/create`, async (req, res) => {
|
|||||||
* - 500: {request: Object, error: string}
|
* - 500: {request: Object, error: string}
|
||||||
* - 500: PVE Task Object
|
* - 500: PVE Task Object
|
||||||
*/
|
*/
|
||||||
router.post(`/:netid/modify`, async (req, res) => {
|
router.post("/:netid/modify", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
@ -149,7 +150,7 @@ router.post(`/:netid/modify`, async (req, res) => {
|
|||||||
* - 500: {error: string}
|
* - 500: {error: string}
|
||||||
* - 500: PVE Task Object
|
* - 500: PVE Task Object
|
||||||
*/
|
*/
|
||||||
router.delete(`/:netid/delete`, async (req, res) => {
|
router.delete("/:netid/delete", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
export const router = Router();
|
export const router = Router({ mergeParams: true }); ;
|
||||||
|
|
||||||
|
const db = global.db;
|
||||||
const requestPVE = global.pve.requestPVE;
|
const requestPVE = global.pve.requestPVE;
|
||||||
const handleResponse = global.pve.handleResponse;
|
const handleResponse = global.pve.handleResponse;
|
||||||
const getDeviceInfo = global.pve.getDeviceInfo;
|
const getDeviceInfo = global.pve.getDeviceInfo;
|
||||||
const getNodeAvailDevices = global.pve.getNodeAvailDevices;
|
const getNodeAvailDevices = global.pve.getNodeAvailDevices;
|
||||||
const checkAuth = global.utils.checkAuth;
|
const checkAuth = global.utils.checkAuth;
|
||||||
const approveResources = global.utils.approveResources;
|
const approveResources = global.utils.approveResources;
|
||||||
const getUserResources = global.utils.getUserResources;
|
|
||||||
const pveAPIToken = global.db.pveAPIToken;
|
const pveAPIToken = global.db.pveAPIToken;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,7 +22,7 @@ const pveAPIToken = global.db.pveAPIToken;
|
|||||||
* - 401: {auth: false, path: string}
|
* - 401: {auth: false, path: string}
|
||||||
* - 500: {error: string}
|
* - 500: {error: string}
|
||||||
*/
|
*/
|
||||||
router.get(`/:hostpci`, async (req, res) => {
|
router.get("/:hostpci", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
@ -70,7 +70,7 @@ router.get(`/:hostpci`, async (req, res) => {
|
|||||||
* - 500: {request: Object, error: string}
|
* - 500: {request: Object, error: string}
|
||||||
* - 500: PVE Task Object
|
* - 500: PVE Task Object
|
||||||
*/
|
*/
|
||||||
router.post(`/:hostpci/modify`, async (req, res) => {
|
router.post("/:hostpci/modify", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
@ -154,7 +154,7 @@ router.post(`/:hostpci/modify`, async (req, res) => {
|
|||||||
* - 500: {request: Object, error: string}
|
* - 500: {request: Object, error: string}
|
||||||
* - 500: PVE Task Object
|
* - 500: PVE Task Object
|
||||||
*/
|
*/
|
||||||
router.post(`/create`, async (req, res) => {
|
router.post("/create", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
@ -233,7 +233,7 @@ router.post(`/create`, async (req, res) => {
|
|||||||
* - 500: {request: Object, error: string}
|
* - 500: {request: Object, error: string}
|
||||||
* - 500: PVE Task Object
|
* - 500: PVE Task Object
|
||||||
*/
|
*/
|
||||||
router.delete(`/:hostpci/delete`, async (req, res) => {
|
router.delete("/:hostpci/delete", async (req, res) => {
|
||||||
req.params = Object.assign({}, req.routeparams, req.params);
|
req.params = Object.assign({}, req.routeparams, req.params);
|
||||||
const params = {
|
const params = {
|
||||||
node: req.params.node,
|
node: req.params.node,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
export const router = Router();
|
export const router = Router({ mergeParams: true }); ;
|
||||||
|
|
||||||
const requestPVE = global.pve.requestPVE;
|
const requestPVE = global.pve.requestPVE;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { WebSocketServer } from "ws";
|
|||||||
import * as cookie from "cookie";
|
import * as cookie from "cookie";
|
||||||
|
|
||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
export const router = Router();
|
export const router = Router({ mergeParams: true }); ;
|
||||||
|
|
||||||
const requestPVE = global.pve.requestPVE;
|
const requestPVE = global.pve.requestPVE;
|
||||||
const checkAuth = global.utils.checkAuth;
|
const checkAuth = global.utils.checkAuth;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
export const router = Router();
|
export const router = Router({ mergeParams: true }); ;
|
||||||
|
|
||||||
|
const db = global.db;
|
||||||
const requestPVE = global.pve.requestPVE;
|
const requestPVE = global.pve.requestPVE;
|
||||||
const checkAuth = global.utils.checkAuth;
|
const checkAuth = global.utils.checkAuth;
|
||||||
const getUserResources = global.utils.getUserResources;
|
const getUserResources = global.utils.getUserResources;
|
||||||
|
Loading…
Reference in New Issue
Block a user