fix bugs from refactor

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-04-24 21:45:32 +00:00
parent 81c290f795
commit 096dfb10e0

14
main.js
View File

@ -91,7 +91,7 @@ app.post("/api/instance/disk/resize", async (req, res) => {
let request = {}; let request = {};
request[storage] = Number(req.body.size * 1024 ** 3); // setup request object request[storage] = Number(req.body.size * 1024 ** 3); // setup request object
// check request approval // check request approval
if (!await approveResources(req, req.body.username, request)) { if (!await approveResources(req, req.cookies.username, request)) {
res.status(500).send({request: request, error: `Storage ${storage} could not fulfill request of size ${req.body.size}G.`}); res.status(500).send({request: request, error: `Storage ${storage} could not fulfill request of size ${req.body.size}G.`});
res.end(); res.end();
return; return;
@ -123,7 +123,7 @@ app.post("/api/instance/disk/move", async (req, res) => {
} }
request[dstStorage] = Number(size); // always decrease destination storage by size request[dstStorage] = Number(size); // always decrease destination storage by size
// check request approval // check request approval
if (!await approveResources(req, req.body.username, request)) { if (!await approveResources(req, req.cookies.username, request)) {
res.status(500).send({request: request, error: `Storage ${req.body.storage} could not fulfill request of size ${req.body.size}G.`}); res.status(500).send({request: request, error: `Storage ${req.body.storage} could not fulfill request of size ${req.body.size}G.`});
res.end(); res.end();
return; return;
@ -166,7 +166,7 @@ app.post("/api/instance/disk/create", async (req, res) => {
if (!req.body.disk.includes("ide")) { if (!req.body.disk.includes("ide")) {
request[req.body.storage] = Number(req.body.size * 1024 ** 3); // setup request object request[req.body.storage] = Number(req.body.size * 1024 ** 3); // setup request object
// check request approval // check request approval
if (!await approveResources(req, req.body.username, request)) { if (!await approveResources(req, req.cookies.username, request)) {
res.status(500).send({request: request, error: `Storage ${req.body.storage} could not fulfill request of size ${req.body.size}G.`}); res.status(500).send({request: request, error: `Storage ${req.body.storage} could not fulfill request of size ${req.body.size}G.`});
res.end(); res.end();
return; return;
@ -180,7 +180,7 @@ app.post("/api/instance/disk/create", async (req, res) => {
action[req.body.disk] = `${req.body.storage}:${req.body.size}`; action[req.body.disk] = `${req.body.storage}:${req.body.size}`;
} }
else { // type is lxc, use mp and add mp and backup values else { // type is lxc, use mp and add mp and backup values
action[req.body.disk] = `${req.body.storage}:${req.body.size},mp=/mp${req.body.device}/,backup=1`; action[req.body.disk] = `${req.body.storage}:${req.body.size},mp=/${req.body.disk}/,backup=1`;
} }
action = JSON.stringify(action); action = JSON.stringify(action);
let method = req.body.type === "qemu" ? "POST" : "PUT"; let method = req.body.type === "qemu" ? "POST" : "PUT";
@ -199,7 +199,7 @@ app.post("/api/resources", async (req, res) => {
memory: Number(req.body.memory) - Number(currentConfig.data.data.memory) memory: Number(req.body.memory) - Number(currentConfig.data.data.memory)
}; };
// check resource approval // check resource approval
if (!await approveResources(req, req.body.username, request)) { if (!await approveResources(req, req.cookies.username, request)) {
res.status(500).send({request: request, error: `Could not fulfil request`}); res.status(500).send({request: request, error: `Could not fulfil request`});
res.end(); res.end();
return; return;
@ -220,7 +220,7 @@ app.post("/api/instance", async (req, res) => {
memory: Number(req.body.memory) memory: Number(req.body.memory)
}; };
// setup action // setup action
let user = getUser(req.cookies.username); let user = await getUserData(req, req.cookies.username);
let vmid = Number.parseInt(req.body.vmid); let vmid = Number.parseInt(req.body.vmid);
let vmid_min = user.instances.vmid.min; let vmid_min = user.instances.vmid.min;
let vmid_max = user.instances.vmid.max; let vmid_max = user.instances.vmid.max;
@ -252,7 +252,7 @@ app.post("/api/instance", async (req, res) => {
action.name = req.body.name; action.name = req.body.name;
} }
// check resource approval // check resource approval
if (!await approveResources(req, req.body.username, request)) { // check resource approval if (!await approveResources(req, req.cookies.username, request)) { // check resource approval
res.status(500).send({request: request, error: `Not enough resources to satisfy request.`}); res.status(500).send({request: request, error: `Not enough resources to satisfy request.`});
res.end(); res.end();
return; return;