fix detach disk endpoint for lxc

This commit is contained in:
Arthur Lu 2023-01-26 07:53:56 +00:00
parent ee7fdad946
commit f46c1165fa

View File

@ -35,7 +35,8 @@ app.post("/api/disk/detach", (req, res) => {
let vmpath = `nodes/${req.body.node}/${req.body.type}/${req.body.vmid}`; let vmpath = `nodes/${req.body.node}/${req.body.type}/${req.body.vmid}`;
checkAuth(req.cookies, (result) => { checkAuth(req.cookies, (result) => {
if (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); res.send(result);
}, body = req.body.action, token = pveAPIToken); }, body = req.body.action, token = pveAPIToken);
} }
@ -75,12 +76,10 @@ function requestPVE (path, method, cookies, callback, body = null, token = null)
mode: "cors", mode: "cors",
credentials: "include", credentials: "include",
headers: { 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) { if (token) {
content.headers.Authorization = `PVEAPIToken=${token.user}@${token.realm}!${token.id}=${token.uuid}`; 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); request.write(body);
} }