Fix unifi with no type passing and lint

pull/3574/head
shamoon 6 months ago
parent ec79f3042a
commit 67a9f4983c

@ -14,8 +14,8 @@ import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Widget({ options }) {
const { t } = useTranslation();
// eslint-disable-next-line no-param-reassign
options.type = "unifi_console";
// eslint-disable-next-line no-param-reassign, no-multi-assign
options.service_group = options.service_name = "unifi_console";
const { data: statsData, error: statsError } = useWidgetAPI(options, "stat/sites", { index: options.index });
if (statsError) {

@ -12,8 +12,11 @@ export default async function handler(req, res) {
const { service, group } = req.query;
const serviceWidget = await getServiceWidget(group, service);
let type = serviceWidget?.type;
// calendar is an alias for ical
// exceptions
if (type === "calendar") type = "ical";
else if (service === "unifi_console" && group === "unifi_console") type = "unifi_console";
const widget = widgets[type];
if (!widget) {
@ -49,15 +52,17 @@ export default async function handler(req, res) {
if (req.query.segments) {
const segments = JSON.parse(req.query.segments);
for (const key in segments) {
let validSegments = true;
Object.keys(segments).forEach((key) => {
if (!mapping.segments.includes(key)) {
logger.debug("Unsupported segment: %s", key);
return res.status(403).json({ error: "Unsupported segment" });
validSegments = false;
} else if (segments[key].includes("/") || segments[key].includes("\\") || segments[key].includes("..")) {
logger.debug("Unsupported segment value: %s", segments[key]);
return res.status(403).json({ error: "Unsupported segment value" });
validSegments = false;
}
}
});
if (!validSegments) return res.status(403).json({ error: "Unsupported segment" });
req.query.endpoint = formatApiCall(endpoint, segments);
}

@ -14,13 +14,13 @@ const prefixCacheKey = `${proxyName}__prefix`;
const logger = createLogger(proxyName);
async function getWidget(req) {
const { group, service, type } = req.query;
const { group, service } = req.query;
let widget = null;
if (type === "unifi_console") {
if (group === "unifi_console" && service === "unifi_console") {
// info widget
const index = req.query?.query ? JSON.parse(req.query.query).index : undefined;
widget = await getPrivateWidgetOptions(type, index);
widget = await getPrivateWidgetOptions("unifi_console", index);
if (!widget) {
logger.debug("Error retrieving settings for this Unifi widget");
return null;

Loading…
Cancel
Save