set brace style to Stroustrup

This commit is contained in:
Arthur Lu 2023-06-29 22:09:57 +00:00
parent 79d2448a3d
commit 628067a061
4 changed files with 51 additions and 22 deletions

View File

@ -10,8 +10,10 @@
},
"rules": {
"no-tabs": [
"error",
{ "allowIndentationTabs": true }
"error",
{
"allowIndentationTabs": true
}
],
"indent": [
"error",
@ -28,6 +30,13 @@
"semi": [
"error",
"always"
],
"brace-style": [
"error",
"stroustrup",
{
"allowSingleLine": false
}
]
}
}
}

View File

@ -7,7 +7,8 @@ class LocalDB {
constructor () {
try {
this.load(this.#filename);
} catch {
}
catch {
console.log("Error: localdb.json was not found. Please follow the directions in the README to initialize localdb.json.");
exit(1);
}
@ -32,7 +33,8 @@ class LocalDB {
getUserConfig (username) {
if (this.#data.users[username]) {
return this.#data.users[username];
} else {
}
else {
return null;
}
}

View File

@ -14,7 +14,8 @@ export async function requestPVE (path, method, cookies, body = null, token = nu
if (token) {
content.headers.Authorization = `PVEAPIToken=${token.user}@${token.realm}!${token.id}=${token.uuid}`;
} else if (cookies) {
}
else if (cookies) {
content.headers.CSRFPreventionToken = cookies.CSRFPreventionToken;
content.headers.Cookie = `PVEAuthCookie=${cookies.PVEAuthCookie}; CSRFPreventionToken=${cookies.CSRFPreventionToken}`;
}
@ -26,7 +27,8 @@ export async function requestPVE (path, method, cookies, body = null, token = nu
try {
const response = await axios.request(url, content);
return response;
} catch (error) {
}
catch (error) {
return error.response;
}
}
@ -46,14 +48,16 @@ export async function handleResponse (node, result, res) {
result.log = taskLog.data.data;
res.status(200).send(result);
res.end();
} else {
}
else {
const result = taskStatus.data.data;
const taskLog = await requestPVE(`/nodes/${node}/tasks/${upid}/log`, "GET", null, null, pveAPIToken);
result.log = taskLog.data.data;
res.status(500).send(result);
res.end();
}
} else {
}
else {
res.status(result.status).send(result.data);
res.end();
}
@ -69,9 +73,11 @@ export async function getUsedResources (req, resourceMeta) {
for (const diskPrefix of resourceMeta[resourceName].disks) {
diskprefixes.push(diskPrefix);
}
} else if (resourceMeta[resourceName].type === "list") {
}
else if (resourceMeta[resourceName].type === "list") {
used[resourceName] = [];
} else {
}
else {
used[resourceName] = 0;
}
}
@ -82,14 +88,17 @@ export async function getUsedResources (req, resourceMeta) {
for (const key of Object.keys(config)) {
if (Object.keys(used).includes(key) && resourceMeta[key].type === "numeric") {
used[key] += Number(config[key]);
} else if (diskprefixes.some(prefix => key.startsWith(prefix))) {
}
else if (diskprefixes.some(prefix => key.startsWith(prefix))) {
const diskInfo = await getDiskInfo(instance.node, instance.type, instance.vmid, key);
if (diskInfo) { // only count if disk exists
used[diskInfo.storage] += Number(diskInfo.size);
}
} else if (key.startsWith("net") && config[key].includes("rate=")) { // only count net instances with a rate limit
}
else if (key.startsWith("net") && config[key].includes("rate=")) { // only count net instances with a rate limit
used.network += Number(config[key].split("rate=")[1].split(",")[0]);
} else if (key.startsWith("hostpci")) {
}
else if (key.startsWith("hostpci")) {
const deviceInfo = await getDeviceInfo(instance.node, instance.type, instance.vmid, config[key].split(",")[0]);
if (deviceInfo) { // only count if device exists
used.pci.push(deviceInfo.device_name);
@ -109,7 +118,8 @@ export async function getDiskInfo (node, type, vmid, disk) {
const volInfo = await requestPVE(`/nodes/${node}/storage/${storageID}/content/${volID}`, "GET", null, null, pveAPIToken);
volInfo.data.data.storage = storageID;
return volInfo.data.data;
} catch {
}
catch {
return null;
}
}
@ -123,11 +133,14 @@ export async function getDeviceInfo (node, type, vmid, qid) {
deviceData.push(element);
}
});
deviceData.sort((a, b) => { return a.id < b.id; });
deviceData.sort((a, b) => {
return a.id < b.id;
});
const device = deviceData[0];
device.subfn = structuredClone(deviceData.slice(1));
return device;
} catch {
}
catch {
return null;
}
}

View File

@ -14,7 +14,8 @@ export async function checkAuth (cookies, res, vmpath = null) {
if (vmpath) {
const result = await requestPVE(`/${vmpath}/config`, "GET", cookies);
auth = result.status === 200;
} else { // if no path is specified, then do a simple authentication
}
else { // if no path is specified, then do a simple authentication
const result = await requestPVE("/version", "GET", cookies);
auth = result.status === 200;
}
@ -38,7 +39,8 @@ export async function getUserResources (req, username) {
const index = avail[k].findIndex((maxElement) => usedDeviceName.includes(maxElement));
avail[k].splice(index, 1);
});
} else {
}
else {
avail[k] = max[k] - used[k];
}
});
@ -53,14 +55,17 @@ export async function approveResources (req, username, request) {
Object.keys(request).forEach((key) => {
if (!(key in avail)) { // if requested resource is not in avail, block
approved = false;
} else if (resources[key].type === "list") {
}
else if (resources[key].type === "list") {
const inAvail = avail[key].some(availElem => request[key].includes(availElem));
if (inAvail !== resources[key].whitelist) {
approved = false;
}
} else if (isNaN(avail[key]) || isNaN(request[key])) { // if either the requested or avail resource is NaN, block
}
else if (isNaN(avail[key]) || isNaN(request[key])) { // if either the requested or avail resource is NaN, block
approved = false;
} else if (avail[key] - request[key] < 0) { // if the avail resources is less than the requested resources, block
}
else if (avail[key] - request[key] < 0) { // if the avail resources is less than the requested resources, block
approved = false;
}
});