From 68b8e4b3762394cef75569532a37c33a709cf5a7 Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Mon, 31 Oct 2022 15:23:34 +0200 Subject: [PATCH] feat: add tubearchivist widget --- public/locales/en/common.json | 6 ++++ src/utils/proxy/handlers/credentialed.js | 2 ++ src/widgets/components.js | 1 + src/widgets/tubearchivist/component.jsx | 40 ++++++++++++++++++++++++ src/widgets/tubearchivist/widget.js | 23 ++++++++++++++ src/widgets/widgets.js | 2 ++ 6 files changed, 74 insertions(+) create mode 100644 src/widgets/tubearchivist/component.jsx create mode 100644 src/widgets/tubearchivist/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index dd00ff86eb3..a4b0628d2f6 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -303,5 +303,11 @@ "rejectedPushes": "Rejected", "filters": "Filters", "indexers": "Indexers" + }, + "tubearchivist": { + "downloads": "Queue", + "videos": "Videos", + "channels": "Channels", + "playlists": "Playlists" } } diff --git a/src/utils/proxy/handlers/credentialed.js b/src/utils/proxy/handlers/credentialed.js index c2c6e334c5a..54c393b172e 100644 --- a/src/utils/proxy/handlers/credentialed.js +++ b/src/utils/proxy/handlers/credentialed.js @@ -33,6 +33,8 @@ export default async function credentialedProxyHandler(req, res) { headers.Authorization = `PVEAPIToken=${widget.username}=${widget.password}`; } else if (widget.type === "autobrr") { headers["X-API-Token"] = `${widget.key}`; + } else if (widget.type === "tubearchivist") { + headers.Authorization = `Token ${widget.key}`; } else { headers["X-API-Key"] = `${widget.key}`; } diff --git a/src/widgets/components.js b/src/widgets/components.js index c2b50189010..47502403700 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -36,6 +36,7 @@ const components = { tautulli: dynamic(() => import("./tautulli/component")), traefik: dynamic(() => import("./traefik/component")), transmission: dynamic(() => import("./transmission/component")), + tubearchivist: dynamic(() => import("./tubearchivist/component")), unifi: dynamic(() => import("./unifi/component")), watchtower: dynamic(() => import("./watchtower/component")), }; diff --git a/src/widgets/tubearchivist/component.jsx b/src/widgets/tubearchivist/component.jsx new file mode 100644 index 00000000000..5b54844366d --- /dev/null +++ b/src/widgets/tubearchivist/component.jsx @@ -0,0 +1,40 @@ +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: downloadsData, error: downloadsError } = useWidgetAPI(widget, "downloads"); + const { data: videosData, error: videosError } = useWidgetAPI(widget, "videos"); + const { data: channelsData, error: channelsError } = useWidgetAPI(widget, "channels"); + const { data: playlistsData, error: playlistsError } = useWidgetAPI(widget, "playlists"); + + if (downloadsError || videosError || channelsError || playlistsError) { + return ; + } + + if (!downloadsData || !videosData || !channelsData || !playlistsData) { + return ( + + + + + + + ); + } + + return ( + + + + + + + ); +} diff --git a/src/widgets/tubearchivist/widget.js b/src/widgets/tubearchivist/widget.js new file mode 100644 index 00000000000..c73070f0092 --- /dev/null +++ b/src/widgets/tubearchivist/widget.js @@ -0,0 +1,23 @@ +import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; + +const widget = { + api: "{url}/api/{endpoint}", + proxyHandler: credentialedProxyHandler, + + mappings: { + downloads: { + endpoint: "download", + }, + videos: { + endpoint: "video", + }, + channels: { + endpoint: "channel", + }, + playlists: { + endpoint: "playlist", + }, + }, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 74f426b36a3..0352466d7c0 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -31,6 +31,7 @@ import strelaysrv from "./strelaysrv/widget"; import tautulli from "./tautulli/widget"; import traefik from "./traefik/widget"; import transmission from "./transmission/widget"; +import tubearchivist from "./tubearchivist/widget"; import unifi from "./unifi/widget"; import watchtower from './watchtower/widget' @@ -69,6 +70,7 @@ const widgets = { tautulli, traefik, transmission, + tubearchivist, unifi, unifi_console: unifi, watchtower,