fix formatting

This commit is contained in:
Arthur Lu 2023-05-17 21:38:11 +00:00
parent b12d84d4be
commit 2cd23324e5
3 changed files with 8 additions and 8 deletions

8
db.js
View File

@ -11,18 +11,18 @@ catch {
save(); save();
} }
function load () { function load() {
db = JSON.parse(readFileSync(filename)); db = JSON.parse(readFileSync(filename));
} }
function save () { function save() {
writeFileSync(filename, JSON.stringify(db)); writeFileSync(filename, JSON.stringify(db));
} }
export function getResourceConfig () { export function getResourceConfig() {
return db.resources; return db.resources;
} }
export function getUserConfig (username) { export function getUserConfig(username) {
return db.users[username]; return db.users[username];
} }

View File

@ -1,7 +1,7 @@
import { getUsedResources } from "./pve.js"; import { getUsedResources } from "./pve.js";
import { getUserConfig, getResourceConfig } from "./db.js"; import { getUserConfig, getResourceConfig } from "./db.js";
export async function getAllocatedResources (req, username) { export async function getAllocatedResources(req, username) {
let dbResources = getResourceConfig(); let dbResources = getResourceConfig();
let used = await getUsedResources(req, dbResources); let used = await getUsedResources(req, dbResources);
let max = getUserConfig(username).resources.max; let max = getUserConfig(username).resources.max;
@ -9,10 +9,10 @@ export async function getAllocatedResources (req, username) {
Object.keys(max).forEach((k) => { Object.keys(max).forEach((k) => {
avail[k] = max[k] - used[k]; avail[k] = max[k] - used[k];
}); });
return {used: used, max: max, avail: avail, units: dbResources}; return { used: used, max: max, avail: avail, units: dbResources };
} }
export async function approveResources (req, username, request) { export async function approveResources(req, username, request) {
let avail = (await getAllocatedResources(req, username)).avail; let avail = (await getAllocatedResources(req, username)).avail;