pre-commit fixes

This commit is contained in:
Karl Hudgell 2025-04-14 20:17:42 +01:00
parent 6e10127683
commit 926d3d5103
3 changed files with 91 additions and 95 deletions

View File

@ -1,8 +1,8 @@
/* eslint-disable no-underscore-dangle */
import { formatApiCall } from "utils/proxy/api-helpers";
import { httpProxy } from "utils/proxy/http";
import getServiceWidget from "utils/config/service-helpers";
import createLogger from "utils/logger";
import { formatApiCall } from "utils/proxy/api-helpers";
import { httpProxy } from "utils/proxy/http";
import widgets from "widgets/widgets";
const proxyName = "portainerProxyHandler";
@ -23,20 +23,19 @@ async function getWidget(req) {
return widget;
}
async function getAllEnvIds(widget) {
const api = widgets?.[widget.type]?.api;
if (!api) {
return [403, null];
}
const endpoint = 'endpoints'
const endpoint = "endpoints";
let url = new URL(formatApiCall(api, { endpoint, ...widget }));
let [status, contentType, data] = await httpProxy(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
'x-api-key': widget.key,
}
"x-api-key": widget.key,
},
});
if (status !== 200) {
@ -51,27 +50,26 @@ async function getAllEnvIds(widget) {
logger.error("Error decoding NextPVR API data. Data: %s", data.toString());
return [status, null];
}
const ids = await dataAsJson.map(item => item.Id);
const ids = await dataAsJson.map((item) => item.Id);
return ids;
}
async function getAllContainers(ids, widget) {
let items = []
let items = [];
const api = widgets?.[widget.type]?.api;
if (!api) {
return [403, null];
}
for (let i = 0; i < ids.length; i++) {
const endpoint = "endpoints/" + ids[i] + "/docker/containers/json?all=1"
const endpoint = "endpoints/" + ids[i] + "/docker/containers/json?all=1";
let url = new URL(formatApiCall(api, { endpoint, ...widget }));
let [status, contentType, data] = await httpProxy(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
'x-api-key': widget.key,
}
"x-api-key": widget.key,
},
});
if (status !== 200) {
@ -82,7 +80,7 @@ async function getAllContainers(ids, widget) {
try {
const dataDecoded = data.toString();
dataAsJson = JSON.parse(dataDecoded);
items.push(dataAsJson)
items.push(dataAsJson);
} catch (e) {
logger.error("Error decoding NextPVR API data. Data: %s", data.toString());
return [status, null];
@ -94,9 +92,9 @@ async function getAllContainers(ids, widget) {
export default async function portainerProxyHandler(req, res) {
try {
const widget = await getWidget(req);
let ids
let ids;
if (('env' in widget)) {
if ("env" in widget) {
ids = [widget.env];
} else {
ids = await getAllEnvIds(widget);
@ -110,10 +108,8 @@ export default async function portainerProxyHandler(req, res) {
const total = containerList.length;
return res.status(200).send({ running, stopped, total });
} catch (error) {
console.error("portainerProxyHandler error:", error);
return res.status(500).send({ error: "Internal Server Error" });
}
}

View File

@ -6,8 +6,8 @@ const widget = {
mappings: {
"docker/containers/json": {
endpoint: "endpoints/{env}/docker/containers/json"
}
endpoint: "endpoints/{env}/docker/containers/json",
},
},
};