add instance delete path

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-02-21 22:35:09 +00:00
parent 14fa48bd86
commit 9f4320a697

View File

@ -9,6 +9,7 @@ var api = require("./package.json");
const {pveAPI, pveAPIToken, listenPort} = require("./vars.js"); const {pveAPI, pveAPIToken, listenPort} = require("./vars.js");
const { token } = require("morgan"); const { token } = require("morgan");
const { response } = require("express");
const app = express(); const app = express();
app.use(helmet()); app.use(helmet());
@ -123,6 +124,22 @@ app.post("/api/resources", async (req, res) => {
} }
}); });
//app.post("/api/instance", async (req, res) => {});
app.delete("/api/instance", async (req, res) => {
let vmpath = `/nodes/${req.body.node}/${req.body.type}/${req.body.vmid}`;
let auth = await checkAuth(req.cookies, vmpath);
if (auth) {
let result = await requestPVE(`${vmpath}`, "DELETE", req.cookies, null, pveAPIToken);
result = await handleResponse(req.body.node, result);
res.send({auth: auth, status: result.status, data: result.data.data});
}
else {
res.send({auth: auth});
}
});
async function checkAuth (cookies, vmpath = null) { async function checkAuth (cookies, vmpath = null) {
if (vmpath) { if (vmpath) {
let result = await requestPVE(`/${vmpath}/config`, "GET", cookies); let result = await requestPVE(`/${vmpath}/config`, "GET", cookies);