mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-01 21:13:39 +01:00
Allow multiple glances widgets with optional id
property
This commit is contained in:
parent
99b70f96e4
commit
8e2ff61f1c
@ -5,24 +5,35 @@ import { getSettings } from "utils/config/config";
|
|||||||
const logger = createLogger("glances");
|
const logger = createLogger("glances");
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
const settings = getSettings()?.glances;
|
const { id } = req.query;
|
||||||
if (!settings) {
|
|
||||||
logger.error("There is no glances section in settings.yaml");
|
let errorMessage;
|
||||||
return res.status(400).json({ error: "There is no glances section in settings.yaml" });
|
|
||||||
|
let instanceID = "glances";
|
||||||
|
if (id) { // multiple instances
|
||||||
|
instanceID = id;
|
||||||
|
}
|
||||||
|
const settings = getSettings();
|
||||||
|
const instanceSettings = settings[instanceID];
|
||||||
|
if (!instanceSettings) {
|
||||||
|
errorMessage = id ? `There is no glances section with id '${id}' in settings.yaml` : "There is no glances section in settings.yaml";
|
||||||
|
logger.error(errorMessage);
|
||||||
|
return res.status(400).json({ error: errorMessage });
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = settings?.url;
|
const url = instanceSettings?.url;
|
||||||
if (!url) {
|
if (!url) {
|
||||||
logger.error("Missing Glances URL");
|
errorMessage = "Missing Glances URL";
|
||||||
return res.status(400).json({ error: "Missing Glances URL" });
|
logger.error(errorMessage);
|
||||||
|
return res.status(400).json({ error: errorMessage });
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiUrl = `${url}/api/3/quicklook`;
|
const apiUrl = `${url}/api/3/quicklook`;
|
||||||
const headers = {
|
const headers = {
|
||||||
"Accept-Encoding": "application/json"
|
"Accept-Encoding": "application/json"
|
||||||
};
|
};
|
||||||
if (settings.username && settings.password) {
|
if (instanceSettings.username && instanceSettings.password) {
|
||||||
headers.Authorization = `Basic ${Buffer.from(`${settings.username}:${settings.password}`).toString("base64")}`
|
headers.Authorization = `Basic ${Buffer.from(`${instanceSettings.username}:${instanceSettings.password}`).toString("base64")}`
|
||||||
}
|
}
|
||||||
const params = { method: "GET", headers };
|
const params = { method: "GET", headers };
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user