From bc1757c9c349c26b49e00f62e7a63b8c997487c9 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Thu, 29 Jun 2023 22:09:57 +0000 Subject: [PATCH] set brace style to Stroustrup --- .eslintrc.json | 15 ++++++++++++--- src/db.js | 6 ++++-- src/pve.js | 37 +++++++++++++++++++++++++------------ src/utils.js | 15 ++++++++++----- 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 3bee5ed..86a2b41 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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 + } ] } -} +} \ No newline at end of file diff --git a/src/db.js b/src/db.js index 25a2dae..02f06b9 100644 --- a/src/db.js +++ b/src/db.js @@ -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; } } diff --git a/src/pve.js b/src/pve.js index c912205..9ec6fee 100644 --- a/src/pve.js +++ b/src/pve.js @@ -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; } } diff --git a/src/utils.js b/src/utils.js index 247cc7a..85ea061 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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; } });