mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-16 11:20:10 +01:00
9a237db3d1
* Implement total permission overhaul Add explicit permissions on each flex and strict route Patch issues with role escalation and CRUD of users Patch permissions on all routes for coverage Improve middleware to accept role array for clarity * update comments * remove permissions to API-keys for manager. Manager could generate API-key and using high-privelege api-key give themselves admin * update sidebar permissions for multi-user and single user * update options for mobile sidebar
61 lines
1.3 KiB
JavaScript
61 lines
1.3 KiB
JavaScript
const { SystemSettings } = require("../models/systemSettings");
|
|
|
|
function utilEndpoints(app) {
|
|
if (!app) return;
|
|
|
|
app.get("/utils/metrics", async (_, response) => {
|
|
try {
|
|
const metrics = {
|
|
online: true,
|
|
version: getGitVersion(),
|
|
mode: (await SystemSettings.isMultiUserMode())
|
|
? "multi-user"
|
|
: "single-user",
|
|
vectorDB: process.env.VECTOR_DB || "lancedb",
|
|
storage: await getDiskStorage(),
|
|
};
|
|
response.status(200).json(metrics);
|
|
} catch (e) {
|
|
console.error(e);
|
|
response.sendStatus(500).end();
|
|
}
|
|
});
|
|
}
|
|
|
|
function getGitVersion() {
|
|
try {
|
|
return require("child_process")
|
|
.execSync("git rev-parse HEAD")
|
|
.toString()
|
|
.trim();
|
|
} catch (e) {
|
|
console.error("getGitVersion", e.message);
|
|
return "--";
|
|
}
|
|
}
|
|
|
|
function byteToGigaByte(n) {
|
|
return n / Math.pow(10, 9);
|
|
}
|
|
|
|
async function getDiskStorage() {
|
|
try {
|
|
const checkDiskSpace = require("check-disk-space").default;
|
|
const { free, size } = await checkDiskSpace("/");
|
|
return {
|
|
current: Math.floor(byteToGigaByte(free)),
|
|
capacity: Math.floor(byteToGigaByte(size)),
|
|
};
|
|
} catch {
|
|
return {
|
|
current: null,
|
|
capacity: null,
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
utilEndpoints,
|
|
getGitVersion,
|
|
};
|