add path to get remaining resources
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
6bda62ae15
commit
4b37ababda
15
db.js
15
db.js
@ -91,4 +91,17 @@ function releaseResources (user, resources) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {init, requestResources, allocateResources, releaseResources};
|
/**
|
||||||
|
* return a read only copy of the user resources
|
||||||
|
* @param {string} user user's proxmox username in the form username@authrealm
|
||||||
|
* @returns {Object} user's remaining resources as k-v pairs with resource name as keys and resource ammount as values
|
||||||
|
*/
|
||||||
|
function getResources (user) {
|
||||||
|
let returnVal = {};
|
||||||
|
if(user in db) {
|
||||||
|
Object.assign(returnVal, db[user]);
|
||||||
|
}
|
||||||
|
return returnVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {init, requestResources, allocateResources, releaseResources, getResources};
|
12
main.js
12
main.js
@ -8,7 +8,7 @@ var api = require("./package.json");
|
|||||||
|
|
||||||
const {pveAPIToken, listenPort, domain} = require("./vars.js");
|
const {pveAPIToken, listenPort, domain} = require("./vars.js");
|
||||||
const {checkAuth, requestPVE, handleResponse, getUnusedDiskData, getDiskConfig} = require("./pveutils.js");
|
const {checkAuth, requestPVE, handleResponse, getUnusedDiskData, getDiskConfig} = require("./pveutils.js");
|
||||||
const {init, requestResources, allocateResources, releaseResources} = require("./db.js");
|
const {init, requestResources, allocateResources, releaseResources, getResources} = require("./db.js");
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
@ -43,6 +43,16 @@ app.post("/api/proxmox/*", async (req, res) => { // proxy endpoint for POST prox
|
|||||||
res.send(result.data, result.status);
|
res.send(result.data, result.status);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get("/api/user/resources", async(req, res) => {
|
||||||
|
let auth = await checkAuth(req.cookies, vmpath);
|
||||||
|
if (!auth) {
|
||||||
|
res.status(401).send({auth: auth});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return getResources(req.cookies.username);
|
||||||
|
});
|
||||||
|
|
||||||
app.post("/api/disk/detach", async (req, res) => {
|
app.post("/api/disk/detach", async (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}`;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user