Properly pass threshold

This commit is contained in:
shamoon 2024-05-16 22:22:45 -07:00
parent 30d0492c55
commit 2283b4391c
3 changed files with 10 additions and 9 deletions

View File

@ -462,6 +462,9 @@ export function cleanServiceGroups(groups) {
// unifi // unifi
site, site,
// wgeasy
threshold,
} = cleanedService.widget; } = cleanedService.widget;
let fieldsList = fields; let fieldsList = fields;
@ -596,6 +599,9 @@ export function cleanServiceGroups(groups) {
cleanedService.widget.bitratePrecision = parseInt(bitratePrecision, 10); cleanedService.widget.bitratePrecision = parseInt(bitratePrecision, 10);
} }
} }
if (type === "wgeasy") {
if (threshold !== undefined) cleanedService.widget.threshold = parseInt(threshold, 10);
}
} }
return cleanedService; return cleanedService;

View File

@ -26,10 +26,9 @@ export default function Component({ service }) {
); );
} }
const total = infoData.length - 1;
const enabled = infoData.filter((item) => item.enabled).length; const enabled = infoData.filter((item) => item.enabled).length;
const disabled = total - enabled; const disabled = infoData.length - enabled;
const connectionThreshold = infoData[infoData.length - 1].threshold * 60 * 1000; const connectionThreshold = widget.threshold ?? 2 * 60 * 1000;
const currentTime = new Date(); const currentTime = new Date();
const connected = infoData.filter( const connected = infoData.filter(
(item) => currentTime - new Date(item.latestHandshakeAt) < connectionThreshold, (item) => currentTime - new Date(item.latestHandshakeAt) < connectionThreshold,
@ -40,7 +39,7 @@ export default function Component({ service }) {
<Block label="wgeasy.connected" value={connected} /> <Block label="wgeasy.connected" value={connected} />
<Block label="wgeasy.enabled" value={enabled} /> <Block label="wgeasy.enabled" value={enabled} />
<Block label="wgeasy.diabled" value={disabled} /> <Block label="wgeasy.diabled" value={disabled} />
<Block label="wgeasy.total" value={total} /> <Block label="wgeasy.total" value={infoData.length} />
</Container> </Container>
); );
} }

View File

@ -21,7 +21,6 @@ async function login(widget, service) {
}); });
try { try {
console.log(responseHeaders);
const connectSidCookie = responseHeaders["set-cookie"] const connectSidCookie = responseHeaders["set-cookie"]
.find((cookie) => cookie.startsWith("connect.sid=")) .find((cookie) => cookie.startsWith("connect.sid="))
.split(";")[0] .split(";")[0]
@ -63,10 +62,7 @@ export default async function wgeasyProxyHandler(req, res) {
}, },
); );
const dataParsed = JSON.parse(data); return res.json(JSON.parse(data));
dataParsed.push({ threshold: widget.threshold ?? 2 });
return res.send(dataParsed);
} }
} }