xteve code cleanup

This commit is contained in:
Michael Shamoon 2022-12-25 20:48:03 -08:00
parent 19e09ace35
commit f36020eb5b
3 changed files with 12 additions and 16 deletions

View File

@ -9,7 +9,7 @@ export default function Component({ service }) {
const { widget } = service; const { widget } = service;
const { data: xteveData, error: xteveError } = useWidgetAPI(widget, "xteve"); const { data: xteveData, error: xteveError } = useWidgetAPI(widget, "api");
if (xteveError) { if (xteveError) {
return <Container error={xteveError} />; return <Container error={xteveError} />;
@ -27,9 +27,9 @@ export default function Component({ service }) {
return ( return (
<Container service={service}> <Container service={service}>
<Block label="xteve.streams_all" value={t("common.number", { value: xteveData["streams.all"] })} /> <Block label="xteve.streams_all" value={t("common.number", { value: xteveData["streams.all"] ?? 0 })} />
<Block label="xteve.streams_active" value={t("common.number", { value: xteveData["streams.active"] })} /> <Block label="xteve.streams_active" value={t("common.number", { value: xteveData["streams.active"] ?? 0 })} />
<Block label="xteve.streams_xepg" value={t("common.number", { value: xteveData["streams.xepg"] })} /> <Block label="xteve.streams_xepg" value={t("common.number", { value: xteveData["streams.xepg"] ?? 0 })} />
</Container> </Container>
); );
} }

View File

@ -21,18 +21,16 @@ export default async function xteveProxyHandler(req, res) {
const url = formatApiCall(api, { endpoint, ...widget }); const url = formatApiCall(api, { endpoint, ...widget });
const method = "POST"; const method = "POST";
const payload = { "cmd": "status" }; const payload = { cmd: "status" };
if (widget.username && widget.password) { if (widget.username && widget.password) {
const body = JSON.stringify({
"cmd": "login",
"username": widget.username,
"password": widget.password,
});
const [status, contentType, data] = await httpProxy(url, { const [status, contentType, data] = await httpProxy(url, {
method, method,
body, body: JSON.stringify({
cmd: "login",
username: widget.username,
password: widget.password,
})
}); });
if (status !== 200) { if (status !== 200) {
@ -49,11 +47,9 @@ export default async function xteveProxyHandler(req, res) {
payload.token = json.token; payload.token = json.token;
} }
const body = JSON.stringify(payload);
const [status, contentType, data] = await httpProxy(url, { const [status, contentType, data] = await httpProxy(url, {
method, method,
body, body: JSON.stringify(payload)
}); });
if (status !== 200) { if (status !== 200) {

View File

@ -5,7 +5,7 @@ const widget = {
proxyHandler: xteveProxyHandler, proxyHandler: xteveProxyHandler,
mappings: { mappings: {
"xteve": { "api": {
endpoint: "api/", endpoint: "api/",
}, },
}, },