fix linting errors,

group more routes,
use mergeParams in router init
This commit is contained in:
Arthur Lu 2023-07-31 19:23:22 +00:00
parent aae3bb14c0
commit 8acaba3911
9 changed files with 29 additions and 37 deletions

View File

@ -24,8 +24,6 @@ app.use(morgan("combined"));
// legacy defs
const requestPVE = global.pve.requestPVE;
const handleResponse = global.pve.handleResponse;
const getDiskInfo = global.pve.getDiskInfo;
const getDeviceInfo = global.pve.getDeviceInfo;
const getNodeAvailDevices = global.pve.getNodeAvailDevices;
const checkAuth = global.utils.checkAuth;
const approveResources = global.utils.approveResources;

View File

@ -1,5 +1,5 @@
import { Router } from "express";
export const router = Router();
export const router = Router({ mergeParams: true }); ;
const domain = global.db.domain;
const checkAuth = global.utils.checkAuth;

View File

@ -1,5 +1,5 @@
import { Router } from "express";
export const router = Router();
export const router = Router({ mergeParams: true });
const nodeRegexP = "[\\w-]+";
const typeRegexP = "qemu|lxc";
@ -8,22 +8,13 @@ const vmidRegexP = "\\d+";
const basePath = `/:node(${nodeRegexP})/:type(${typeRegexP})/:vmid(${vmidRegexP})`;
import("./cluster/disk.js").then((module) => {
router.use(`${basePath}/disk`, (req, res, next) => {
req.routeparams = Object.assign({}, req.routeparams, req.params);
next();
}, module.router);
router.use(`${basePath}/disk`, module.router);
});
import("./cluster/net.js").then((module) => {
router.use(`${basePath}/net`, (req, res, next) => {
req.routeparams = Object.assign({}, req.routeparams, req.params);
next();
}, module.router);
router.use(`${basePath}/net`, module.router);
});
import("./cluster/pci.js").then((module) => {
router.use(`${basePath}/pci`,(req, res, next) => {
req.routeparams = Object.assign({}, req.routeparams, req.params);
next();
}, module.router);
router.use(`${basePath}/pci`, module.router);
});

View File

@ -1,6 +1,7 @@
import { Router } from "express";
export const router = Router();
export const router = Router({ mergeParams: true });
const db = global.db;
const requestPVE = global.pve.requestPVE;
const handleResponse = global.pve.handleResponse;
const getDiskInfo = global.pve.getDiskInfo;
@ -21,7 +22,7 @@ const pveAPIToken = global.db.pveAPIToken;
* - 500: {error: string}
* - 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);
const params = {
node: req.params.node,
@ -69,7 +70,7 @@ router.post(`/:disk/detach`, async (req, res) => {
* - 500: {error: string}
* - 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);
const params = {
node: req.params.node,
@ -125,7 +126,7 @@ router.post(`/:disk/attach`, async (req, res) => {
* - 500: {request: Object, error: string}
* - 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);
const params = {
node: req.params.node,
@ -179,7 +180,7 @@ router.post(`/:disk/resize`, async (req, res) => {
* - 500: {request: Object, error: string}
* - 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);
const params = {
node: req.params.node,
@ -243,7 +244,7 @@ router.post(`/:disk/move`, async (req, res) => {
* - 500: {error: string}
* - 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);
const params = {
node: req.params.node,
@ -295,7 +296,7 @@ router.delete(`/:disk/delete`, async (req, res) => {
* - 500: {request: Object, error: string}
* - 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);
const params = {
node: req.params.node,

View File

@ -1,6 +1,7 @@
import { Router } from "express";
export const router = Router();
export const router = Router({ mergeParams: true }); ;
const db = global.db;
const requestPVE = global.pve.requestPVE;
const handleResponse = global.pve.handleResponse;
const checkAuth = global.utils.checkAuth;
@ -23,7 +24,7 @@ const pveAPIToken = global.db.pveAPIToken;
* - 500: {request: Object, error: string}
* - 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);
const params = {
node: req.params.node,
@ -92,7 +93,7 @@ router.post(`/:netid/create`, async (req, res) => {
* - 500: {request: Object, error: string}
* - 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);
const params = {
node: req.params.node,
@ -149,7 +150,7 @@ router.post(`/:netid/modify`, async (req, res) => {
* - 500: {error: string}
* - 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);
const params = {
node: req.params.node,

View File

@ -1,13 +1,13 @@
import { Router } from "express";
export const router = Router();
export const router = Router({ mergeParams: true }); ;
const db = global.db;
const requestPVE = global.pve.requestPVE;
const handleResponse = global.pve.handleResponse;
const getDeviceInfo = global.pve.getDeviceInfo;
const getNodeAvailDevices = global.pve.getNodeAvailDevices;
const checkAuth = global.utils.checkAuth;
const approveResources = global.utils.approveResources;
const getUserResources = global.utils.getUserResources;
const pveAPIToken = global.db.pveAPIToken;
/**
@ -22,7 +22,7 @@ const pveAPIToken = global.db.pveAPIToken;
* - 401: {auth: false, path: string}
* - 500: {error: string}
*/
router.get(`/:hostpci`, async (req, res) => {
router.get("/:hostpci", async (req, res) => {
req.params = Object.assign({}, req.routeparams, req.params);
const params = {
node: req.params.node,
@ -70,7 +70,7 @@ router.get(`/:hostpci`, async (req, res) => {
* - 500: {request: Object, error: string}
* - 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);
const params = {
node: req.params.node,
@ -154,7 +154,7 @@ router.post(`/:hostpci/modify`, async (req, res) => {
* - 500: {request: Object, error: string}
* - 500: PVE Task Object
*/
router.post(`/create`, async (req, res) => {
router.post("/create", async (req, res) => {
req.params = Object.assign({}, req.routeparams, req.params);
const params = {
node: req.params.node,
@ -233,7 +233,7 @@ router.post(`/create`, async (req, res) => {
* - 500: {request: Object, error: string}
* - 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);
const params = {
node: req.params.node,

View File

@ -1,5 +1,5 @@
import { Router } from "express";
export const router = Router();
export const router = Router({ mergeParams: true }); ;
const requestPVE = global.pve.requestPVE;

View File

@ -2,7 +2,7 @@ import { WebSocketServer } from "ws";
import * as cookie from "cookie";
import { Router } from "express";
export const router = Router();
export const router = Router({ mergeParams: true }); ;
const requestPVE = global.pve.requestPVE;
const checkAuth = global.utils.checkAuth;

View File

@ -1,6 +1,7 @@
import { Router } from "express";
export const router = Router();
export const router = Router({ mergeParams: true }); ;
const db = global.db;
const requestPVE = global.pve.requestPVE;
const checkAuth = global.utils.checkAuth;
const getUserResources = global.utils.getUserResources;