mirror of
https://github.com/karl0ss/homepage.git
synced 2025-07-02 22:19:08 +01:00
Update glances to use private widget options API
This commit is contained in:
parent
7c39cd8960
commit
c1a55ff6d3
@ -1,29 +1,17 @@
|
|||||||
import { httpProxy } from "utils/proxy/http";
|
import { httpProxy } from "utils/proxy/http";
|
||||||
import createLogger from "utils/logger";
|
import createLogger from "utils/logger";
|
||||||
import { getSettings } from "utils/config/config";
|
import { getPrivateWidgetOptions } from "utils/config/service-helpers";
|
||||||
|
|
||||||
const logger = createLogger("glances");
|
const logger = createLogger("glances");
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
const { id } = req.query;
|
const { index } = req.query;
|
||||||
|
|
||||||
let errorMessage;
|
const privateWidgetOptions = await getPrivateWidgetOptions("glances", index);
|
||||||
|
|
||||||
let instanceID = "glances";
|
const url = privateWidgetOptions?.url;
|
||||||
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 = instanceSettings?.url;
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
errorMessage = "Missing Glances URL";
|
const errorMessage = "Missing Glances URL";
|
||||||
logger.error(errorMessage);
|
logger.error(errorMessage);
|
||||||
return res.status(400).json({ error: errorMessage });
|
return res.status(400).json({ error: errorMessage });
|
||||||
}
|
}
|
||||||
@ -32,8 +20,8 @@ export default async function handler(req, res) {
|
|||||||
const headers = {
|
const headers = {
|
||||||
"Accept-Encoding": "application/json"
|
"Accept-Encoding": "application/json"
|
||||||
};
|
};
|
||||||
if (instanceSettings.username && instanceSettings.password) {
|
if (privateWidgetOptions.username && privateWidgetOptions.password) {
|
||||||
headers.Authorization = `Basic ${Buffer.from(`${instanceSettings.username}:${instanceSettings.password}`).toString("base64")}`
|
headers.Authorization = `Basic ${Buffer.from(`${privateWidgetOptions.username}:${privateWidgetOptions.password}`).toString("base64")}`
|
||||||
}
|
}
|
||||||
const params = { method: "GET", headers };
|
const params = { method: "GET", headers };
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user