|
|
@ -62,22 +62,6 @@ async function apiCall(widget, endpoint) {
|
|
|
|
return { status, contentType, data: JSON.parse(data.toString()), responseHeaders };
|
|
|
|
return { status, contentType, data: JSON.parse(data.toString()), responseHeaders };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatPluginsResponse(plugins) {
|
|
|
|
|
|
|
|
const quantity = plugins?.data.filter(p => p.updateAvailable).length;
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
updatesAvailable: quantity > 0,
|
|
|
|
|
|
|
|
quantity,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function formatChildBridgesResponse(childBridges) {
|
|
|
|
|
|
|
|
const quantity = childBridges?.data?.length
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
quantity,
|
|
|
|
|
|
|
|
quantityWithOkStatus: childBridges?.data?.filter(cb => cb.status === "ok").length,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default async function homebridgeProxyHandler(req, res) {
|
|
|
|
export default async function homebridgeProxyHandler(req, res) {
|
|
|
|
const { group, service } = req.query;
|
|
|
|
const { group, service } = req.query;
|
|
|
|
|
|
|
|
|
|
|
@ -97,17 +81,20 @@ export default async function homebridgeProxyHandler(req, res) {
|
|
|
|
await login(widget);
|
|
|
|
await login(widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const statusRs = await apiCall(widget, "status/homebridge");
|
|
|
|
const { data: statusData } = await apiCall(widget, "status/homebridge");
|
|
|
|
const versionRs = await apiCall(widget, "status/homebridge-version");
|
|
|
|
const { data: versionData } = await apiCall(widget, "status/homebridge-version");
|
|
|
|
const childBrigdeRs = await apiCall(widget, "status/homebridge/child-bridges");
|
|
|
|
const { data: childBridgeData } = await apiCall(widget, "status/homebridge/child-bridges");
|
|
|
|
const pluginsRs = await apiCall(widget, "plugins");
|
|
|
|
const { data: pluginsData } = await apiCall(widget, "plugins");
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).send({
|
|
|
|
return res.status(200).send({
|
|
|
|
data: {
|
|
|
|
status: statusData?.status,
|
|
|
|
status: statusRs?.data?.status,
|
|
|
|
updateAvailable: versionData?.updateAvailable,
|
|
|
|
updateAvailable: versionRs?.data?.updateAvailable,
|
|
|
|
plugins: {
|
|
|
|
plugins: formatPluginsResponse(pluginsRs),
|
|
|
|
updatesAvailable: pluginsData?.filter(p => p.updateAvailable).length,
|
|
|
|
childBridges: formatChildBridgesResponse(childBrigdeRs),
|
|
|
|
},
|
|
|
|
|
|
|
|
childBridges: {
|
|
|
|
|
|
|
|
running: childBridgeData?.filter(cb => cb.status === "ok").length,
|
|
|
|
|
|
|
|
total: childBridgeData?.length
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|