commit
a1f2003a77
@ -0,0 +1,50 @@
|
|||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { IoAlertCircle } from "react-icons/io5";
|
||||||
|
|
||||||
|
function displayError(error) {
|
||||||
|
return JSON.stringify(error[1] ? error[1] : error, null, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayData(data) {
|
||||||
|
return (data.type === 'Buffer') ? Buffer.from(data).toString() : JSON.stringify(data, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Error({ error }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
if (error?.data?.error) {
|
||||||
|
error = error.data.error; // eslint-disable-line no-param-reassign
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<details className="px-1 pb-1">
|
||||||
|
<summary className="block text-center mt-1 mb-0 mx-auto p-3 rounded bg-rose-900/80 hover:bg-rose-900/95 text-theme-900 cursor-pointer">
|
||||||
|
<div className="flex items-center justify-center text-xs font-bold">
|
||||||
|
<IoAlertCircle className="mr-1 w-5 h-5"/>{t("widget.api_error")} {error.message && t("widget.information")}
|
||||||
|
</div>
|
||||||
|
</summary>
|
||||||
|
<div className="bg-white dark:bg-theme-200/50 mt-2 rounded text-rose-900 text-xs font-mono whitespace-pre-wrap break-all">
|
||||||
|
<ul className="p-4">
|
||||||
|
{error.message && <li>
|
||||||
|
<span className="text-black">{t("widget.api_error")}:</span> {error.message}
|
||||||
|
</li>}
|
||||||
|
{error.url && <li className="mt-2">
|
||||||
|
<span className="text-black">{t("widget.url")}:</span> {error.url}
|
||||||
|
</li>}
|
||||||
|
{error.rawError && <li className="mt-2">
|
||||||
|
<span className="text-black">{t("widget.raw_error")}:</span>
|
||||||
|
<div className="ml-2">
|
||||||
|
{displayError(error.rawError)}
|
||||||
|
</div>
|
||||||
|
</li>}
|
||||||
|
{error.data && <li className="mt-2">
|
||||||
|
<span className="text-black">{t("widget.response_data")}:</span>
|
||||||
|
<div className="ml-2">
|
||||||
|
{displayData(error.data)}
|
||||||
|
</div>
|
||||||
|
</li>}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
import widgets from "widgets/widgets";
|
||||||
|
|
||||||
|
export default function validateWidgetData(widget, endpoint, data) {
|
||||||
|
let valid = true;
|
||||||
|
let dataParsed;
|
||||||
|
try {
|
||||||
|
dataParsed = JSON.parse(data);
|
||||||
|
} catch (e) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dataParsed && Object.entries(dataParsed).length) {
|
||||||
|
const validate = widgets[widget.type]?.mappings?.[endpoint]?.validate;
|
||||||
|
validate?.forEach(key => {
|
||||||
|
if (dataParsed[key] === undefined) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return valid;
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
import Container from "components/services/widget/container";
|
||||||
|
import Block from "components/services/widget/block";
|
||||||
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
|
|
||||||
|
export default function Component({ service }) {
|
||||||
|
const { widget } = service;
|
||||||
|
|
||||||
|
const { data: channelsData, error: channelsError } = useWidgetAPI(widget, "lineup");
|
||||||
|
|
||||||
|
if (channelsError) {
|
||||||
|
return <Container error={channelsError} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!channelsData) {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="hdhomerun.channels" />
|
||||||
|
<Block label="hdhomerun.hd" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const hdChannels = channelsData?.filter((channel) => channel.HD === 1);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="hdhomerun.channels" value={channelsData.length } />
|
||||||
|
<Block label="hdhomerun.hd" value={hdChannels.length} />
|
||||||
|
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
api: "{url}/{endpoint}",
|
||||||
|
proxyHandler: genericProxyHandler,
|
||||||
|
|
||||||
|
mappings: {
|
||||||
|
"lineup": {
|
||||||
|
endpoint: "lineup.json",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default widget;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue