From a2a5382ddbbdb476b5423117940ddcdbeeabd13f Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Wed, 26 Oct 2022 12:56:43 +0200 Subject: [PATCH] feat: add autobrr widget --- public/locales/en/common.json | 6 ++++ src/utils/proxy/handlers/credentialed.js | 2 ++ src/widgets/autobrr/component.jsx | 39 ++++++++++++++++++++++++ src/widgets/autobrr/widget.js | 20 ++++++++++++ src/widgets/components.js | 1 + src/widgets/widgets.js | 2 ++ 6 files changed, 70 insertions(+) create mode 100644 src/widgets/autobrr/component.jsx create mode 100644 src/widgets/autobrr/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index aa1d6601a..62ef2102b 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -292,5 +292,11 @@ "up_to_date": "Up to Date", "child_bridges": "Child Bridges", "child_bridges_status": "{{ok}}/{{total}}" + }, + "autobrr": { + "approvedPushes": "Approved", + "rejectedPushes": "Rejected", + "filters": "Filters", + "indexers": "Indexers" } } diff --git a/src/utils/proxy/handlers/credentialed.js b/src/utils/proxy/handlers/credentialed.js index 7418b68c3..c2c6e334c 100644 --- a/src/utils/proxy/handlers/credentialed.js +++ b/src/utils/proxy/handlers/credentialed.js @@ -31,6 +31,8 @@ export default async function credentialedProxyHandler(req, res) { headers.Authorization = `Bearer ${widget.key}`; } else if (widget.type === "proxmox") { headers.Authorization = `PVEAPIToken=${widget.username}=${widget.password}`; + } else if (widget.type === "autobrr") { + headers["X-API-Token"] = `${widget.key}`; } else { headers["X-API-Key"] = `${widget.key}`; } diff --git a/src/widgets/autobrr/component.jsx b/src/widgets/autobrr/component.jsx new file mode 100644 index 000000000..b78f48f61 --- /dev/null +++ b/src/widgets/autobrr/component.jsx @@ -0,0 +1,39 @@ +import { useTranslation } from "next-i18next"; + +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 { t } = useTranslation(); + + const { widget } = service; + + const { data: statsData, error: statsError } = useWidgetAPI(widget, "stats"); + const { data: filtersData, error: filtersError } = useWidgetAPI(widget, "filters"); + const { data: indexersData, error: indexersError } = useWidgetAPI(widget, "indexers"); + + if (statsError || filtersError || indexersError) { + return ; + } + + if (!statsData || !filtersData || !indexersData) { + return ( + + + + + + + ); + } + + return ( + + + + + + + ); +} diff --git a/src/widgets/autobrr/widget.js b/src/widgets/autobrr/widget.js new file mode 100644 index 000000000..0254029ee --- /dev/null +++ b/src/widgets/autobrr/widget.js @@ -0,0 +1,20 @@ +import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; + +const widget = { + api: "{url}/api/{endpoint}", + proxyHandler: credentialedProxyHandler, + + mappings: { + stats: { + endpoint: "release/stats", + }, + filters: { + endpoint: "filters", + }, + indexers: { + endpoint: "release/indexers", + }, + }, +}; + +export default widget; diff --git a/src/widgets/components.js b/src/widgets/components.js index 8f7bfeb93..f46808a50 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -3,6 +3,7 @@ import dynamic from "next/dynamic"; const components = { adguard: dynamic(() => import("./adguard/component")), authentik: dynamic(() => import("./authentik/component")), + autobrr: dynamic(() => import("./autobrr/component")), bazarr: dynamic(() => import("./bazarr/component")), changedetectionio: dynamic(() => import("./changedetectionio/component")), coinmarketcap: dynamic(() => import("./coinmarketcap/component")), diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 55379e986..577243a7a 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -1,5 +1,6 @@ import adguard from "./adguard/widget"; import authentik from "./authentik/widget"; +import autobrr from "./autobrr/widget"; import bazarr from "./bazarr/widget"; import changedetectionio from "./changedetectionio/widget"; import coinmarketcap from "./coinmarketcap/widget"; @@ -35,6 +36,7 @@ import unifi from "./unifi/widget"; const widgets = { adguard, authentik, + autobrr, bazarr, changedetectionio, coinmarketcap,