improve return values
This commit is contained in:
parent
9d454183db
commit
934873396d
16
index.js
16
index.js
@ -38,7 +38,7 @@ app.post("/api/disk/detach", async (req, res) => {
|
|||||||
if (auth) {
|
if (auth) {
|
||||||
let method = req.body.type === "qemu" ? "POST" : "PUT";
|
let method = req.body.type === "qemu" ? "POST" : "PUT";
|
||||||
let result = await requestPVE(`${vmpath}/config`, method, req.cookies, req.body.action, pveAPIToken);
|
let result = await requestPVE(`${vmpath}/config`, method, req.cookies, req.body.action, pveAPIToken);
|
||||||
await handleResponse(req.body.node, result);
|
result = await handleResponse(req.body.node, result);
|
||||||
res.send({auth: auth, status: result.status, data: result.data.data});
|
res.send({auth: auth, status: result.status, data: result.data.data});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -53,7 +53,7 @@ app.post("/api/disk/attach", async (req, res) => {
|
|||||||
if (auth) {
|
if (auth) {
|
||||||
let method = req.body.type === "qemu" ? "POST" : "PUT";
|
let method = req.body.type === "qemu" ? "POST" : "PUT";
|
||||||
let result = await requestPVE(`${vmpath}/config`, method, req.cookies, req.body.action, pveAPIToken);
|
let result = await requestPVE(`${vmpath}/config`, method, req.cookies, req.body.action, pveAPIToken);
|
||||||
await handleResponse(req.body.node, result);
|
result = await handleResponse(req.body.node, result);
|
||||||
res.send({auth: auth, status: result.status, data: result.data.data});
|
res.send({auth: auth, status: result.status, data: result.data.data});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -68,7 +68,7 @@ app.post("/api/disk/resize", async (req, res) => {
|
|||||||
if (auth) {
|
if (auth) {
|
||||||
let method = "PUT";
|
let method = "PUT";
|
||||||
let result = await requestPVE(`${vmpath}/resize`, method, req.cookies, req.body.action, pveAPIToken);
|
let result = await requestPVE(`${vmpath}/resize`, method, req.cookies, req.body.action, pveAPIToken);
|
||||||
await handleResponse(req.body.node, result);
|
result = await handleResponse(req.body.node, result);
|
||||||
res.send({auth: auth, status: result.status, data: result.data.data});
|
res.send({auth: auth, status: result.status, data: result.data.data});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -84,7 +84,7 @@ app.post("/api/disk/move", async (req, res) => {
|
|||||||
if (auth) {
|
if (auth) {
|
||||||
let method = "POST";
|
let method = "POST";
|
||||||
let result = await requestPVE(`${vmpath}/${route}`, method, req.cookies, req.body.action, pveAPIToken);
|
let result = await requestPVE(`${vmpath}/${route}`, method, req.cookies, req.body.action, pveAPIToken);
|
||||||
await handleResponse(req.body.node, result);
|
result = await handleResponse(req.body.node, result);
|
||||||
res.send({auth: auth, status: result.status, data: result.data.data});
|
res.send({auth: auth, status: result.status, data: result.data.data});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -99,7 +99,7 @@ app.post("/api/disk/delete", async (req, res) => {
|
|||||||
if (auth) {
|
if (auth) {
|
||||||
let method = req.body.type === "qemu" ? "POST" : "PUT";
|
let method = req.body.type === "qemu" ? "POST" : "PUT";
|
||||||
let result = await requestPVE(`${vmpath}/config`, method, req.cookies, req.body.action, pveAPIToken);
|
let result = await requestPVE(`${vmpath}/config`, method, req.cookies, req.body.action, pveAPIToken);
|
||||||
await handleResponse(req.body.node, result);
|
result = await handleResponse(req.body.node, result);
|
||||||
res.send({auth: auth, status: result.status, data: result.data.data});
|
res.send({auth: auth, status: result.status, data: result.data.data});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -162,10 +162,10 @@ async function handleResponse (node, response) {
|
|||||||
while (true) {
|
while (true) {
|
||||||
let taskStatus = await requestPVE(`/nodes/${node}/tasks/${upid}/status`, "GET", null, null, pveAPIToken);
|
let taskStatus = await requestPVE(`/nodes/${node}/tasks/${upid}/status`, "GET", null, null, pveAPIToken);
|
||||||
if (taskStatus.data.data.status === "stopped" && taskStatus.data.data.exitStatus === "OK") {
|
if (taskStatus.data.data.status === "stopped" && taskStatus.data.data.exitStatus === "OK") {
|
||||||
return true;
|
return taskStatus;
|
||||||
}
|
}
|
||||||
else if (taskStatus.data.data.status === "stopped") {
|
else if (taskStatus.data.data.status === "stopped") {
|
||||||
return false;
|
return taskStatus;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await waitFor(1000);
|
await waitFor(1000);
|
||||||
@ -173,7 +173,7 @@ async function handleResponse (node, response) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return true;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user