From 5eb56421661b77e953fbdd6fe8a8c925889f8f6a Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Thu, 1 Jun 2023 17:12:52 +0000 Subject: [PATCH] fix nodes pci endpoint Signed-off-by: Arthur Lu --- main.js | 21 +++++++++++++++------ pve.js | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/main.js b/main.js index 88aaff7..bfb8d32 100644 --- a/main.js +++ b/main.js @@ -618,20 +618,29 @@ app.delete("/api/instance", async (req, res) => { */ app.get("/api/nodes/pci", async (req, res) => { // check auth for specific instance - let vmpath = `/nodes/${req.body.node}/${req.body.type}/${req.body.vmid}`; + let vmpath = `/nodes/${req.query.node}/${req.query.type}/${req.query.vmid}`; let auth = await checkAuth(req.cookies, res, vmpath); if (!auth) { return; } // check device is in instance config let config = (await requestPVE(`${vmpath}/config`, "GET", req.cookies)).data.data; - if (!config[`hostpci${req.body.hostpci}`]) { - res.status(500).send({ error: `Could not find hostpci${req.body.hostpci} in ${req.body.vmid}.` }); + if (!config[`hostpci${req.query.hostpci}`]) { + res.status(500).send({ error: `Could not find hostpci${req.query.hostpci} in ${req.query.vmid}.` }); res.end(); return; } - let device = config[`hostpci${req.body.hostpci}`]; + let device = config[`hostpci${req.query.hostpci}`].split(",")[0]; + console.log(device) // get node's pci devices - let result = (await requestPVE(`/nodes/${req.body.node}/hardware/pci/${device}`, "GET", req.cookies)).data.data; - return result; + let result = (await requestPVE(`/nodes/${req.query.node}/hardware/pci`, "GET", req.cookies, null, pveAPIToken)).data.data; + let deviceData = []; + result.forEach((element) => { + if (element.id.startsWith(device)) { + deviceData.push(element); + } + }); + res.status(200).send(deviceData); + res.end(); + return; }); app.listen(listenPort, () => { diff --git a/pve.js b/pve.js index 39f72c6..8138b1a 100644 --- a/pve.js +++ b/pve.js @@ -35,7 +35,7 @@ export async function requestPVE(path, method, cookies, body = null, token = nul export async function handleResponse(node, result, res) { const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay)); - if (result.data.data) { + if (result.data.data && typeof(result.data.data) === String && result.data.data.startsWith("UPID:")) { let upid = result.data.data; while (true) { let taskStatus = await requestPVE(`/nodes/${node}/tasks/${upid}/status`, "GET", null, null, pveAPIToken);