From a83d5132d9ff8d89a40f933d4acba432b2bddf91 Mon Sep 17 00:00:00 2001 From: Ben Phelps Date: Mon, 26 Sep 2022 10:58:14 +0300 Subject: [PATCH] refactor lidarr widget --- src/utils/api-helpers.js | 4 ---- .../lidarr/component.jsx} | 7 +++--- src/widgets/lidarr/widget.js | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) rename src/{components/services/widgets/service/lidarr.jsx => widgets/lidarr/component.jsx} (88%) create mode 100644 src/widgets/lidarr/widget.js diff --git a/src/utils/api-helpers.js b/src/utils/api-helpers.js index 17e966ec7..cea10e663 100644 --- a/src/utils/api-helpers.js +++ b/src/utils/api-helpers.js @@ -1,7 +1,3 @@ -// const formats = { -// lidarr: `{url}/api/v1/{endpoint}?apikey={key}`, -// }; - export function formatApiCall(url, args) { const find = /\{.*?\}/g; const replace = (match) => { diff --git a/src/components/services/widgets/service/lidarr.jsx b/src/widgets/lidarr/component.jsx similarity index 88% rename from src/components/services/widgets/service/lidarr.jsx rename to src/widgets/lidarr/component.jsx index 4b985aee3..fc0e7a952 100644 --- a/src/components/services/widgets/service/lidarr.jsx +++ b/src/widgets/lidarr/component.jsx @@ -1,12 +1,11 @@ import useSWR from "swr"; import { useTranslation } from "next-i18next"; -import Widget from "../widget"; -import Block from "../block"; - +import Widget from "components/services/widgets/widget"; +import Block from "components/services/widgets/block"; import { formatProxyUrl } from "utils/api-helpers"; -export default function Lidarr({ service }) { +export default function Component({ service }) { const { t } = useTranslation(); const config = service.widget; diff --git a/src/widgets/lidarr/widget.js b/src/widgets/lidarr/widget.js new file mode 100644 index 000000000..aac84b74b --- /dev/null +++ b/src/widgets/lidarr/widget.js @@ -0,0 +1,24 @@ +import genericProxyHandler from "utils/proxies/generic"; +import { jsonArrayFilter } from "utils/api-helpers"; + +const widget = { + api: "{url}/api/v1/{endpoint}?apikey={key}", + proxyHandler: genericProxyHandler, + + mappings: { + album: { + endpoint: "album", + map: (data) => ({ + have: jsonArrayFilter(data, (item) => item?.statistics?.percentOfTracks === 100).length, + }), + }, + "wanted/missing": { + endpoint: "wanted/missing", + }, + "queue/status": { + endpoint: "queue/status", + }, + }, +}; + +export default widget;