From f46c1165fa2cba7f816426eecde36ded41365170 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Thu, 26 Jan 2023 07:53:56 +0000 Subject: [PATCH] fix detach disk endpoint for lxc --- index.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index fbb3e37..d64170f 100644 --- a/index.js +++ b/index.js @@ -35,7 +35,8 @@ app.post("/api/disk/detach", (req, res) => { let vmpath = `nodes/${req.body.node}/${req.body.type}/${req.body.vmid}`; checkAuth(req.cookies, (result) => { if (result) { - requestPVE(`/${vmpath}/config`, "POST", req.cookies, (result) => { + let method = req.body.type === "qemu" ? "POST" : "PUT"; + requestPVE(`/${vmpath}/config`, method, req.cookies, (result) => { res.send(result); }, body = req.body.action, token = pveAPIToken); } @@ -75,12 +76,10 @@ function requestPVE (path, method, cookies, callback, body = null, token = null) mode: "cors", credentials: "include", headers: { - "Content-Type": "application/x-www-form-urlencoded" + "Content-Type": "application/x-www-form-urlencoded", + "CSRFPreventionToken": cookies.CSRFPreventionToken } } - if (method === "POST") { - content.headers.CSRFPreventionToken = cookies.CSRFPreventionToken; - } if (token) { content.headers.Authorization = `PVEAPIToken=${token.user}@${token.realm}!${token.id}=${token.uuid}`; @@ -111,7 +110,7 @@ function requestPVE (path, method, cookies, callback, body = null, token = null) }); }); - if (method === "POST") { + if (body) { request.write(body); }