From f36020eb5be501cd82f74b560378bd771b03a9b1 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 25 Dec 2022 20:48:03 -0800 Subject: [PATCH] xteve code cleanup --- src/widgets/xteve/component.jsx | 8 ++++---- src/widgets/xteve/proxy.js | 18 +++++++----------- src/widgets/xteve/widget.js | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/widgets/xteve/component.jsx b/src/widgets/xteve/component.jsx index 2568301a..9d22e8a1 100644 --- a/src/widgets/xteve/component.jsx +++ b/src/widgets/xteve/component.jsx @@ -9,7 +9,7 @@ export default function Component({ service }) { const { widget } = service; - const { data: xteveData, error: xteveError } = useWidgetAPI(widget, "xteve"); + const { data: xteveData, error: xteveError } = useWidgetAPI(widget, "api"); if (xteveError) { return ; @@ -27,9 +27,9 @@ export default function Component({ service }) { return ( - - - + + + ); } diff --git a/src/widgets/xteve/proxy.js b/src/widgets/xteve/proxy.js index dada6734..22795b76 100644 --- a/src/widgets/xteve/proxy.js +++ b/src/widgets/xteve/proxy.js @@ -21,18 +21,16 @@ export default async function xteveProxyHandler(req, res) { const url = formatApiCall(api, { endpoint, ...widget }); const method = "POST"; - const payload = { "cmd": "status" }; + const payload = { cmd: "status" }; if (widget.username && widget.password) { - const body = JSON.stringify({ - "cmd": "login", - "username": widget.username, - "password": widget.password, - }); - const [status, contentType, data] = await httpProxy(url, { method, - body, + body: JSON.stringify({ + cmd: "login", + username: widget.username, + password: widget.password, + }) }); if (status !== 200) { @@ -49,11 +47,9 @@ export default async function xteveProxyHandler(req, res) { payload.token = json.token; } - const body = JSON.stringify(payload); - const [status, contentType, data] = await httpProxy(url, { method, - body, + body: JSON.stringify(payload) }); if (status !== 200) { diff --git a/src/widgets/xteve/widget.js b/src/widgets/xteve/widget.js index 7e65b8b6..59b6e3fa 100644 --- a/src/widgets/xteve/widget.js +++ b/src/widgets/xteve/widget.js @@ -5,7 +5,7 @@ const widget = { proxyHandler: xteveProxyHandler, mappings: { - "xteve": { + "api": { endpoint: "api/", }, },