diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 37f7e233..873586e5 100755 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -653,5 +653,10 @@ "nextpvr": { "upcoming": "Upcoming", "ready": "Recent" + }, + "jdrssdownloader": { + "totalShows": "Tracked Shows", + "retryCache": "Retry Cache", + "feedCache": "Feed Cache" } } \ No newline at end of file diff --git a/src/widgets/components.js b/src/widgets/components.js index 9916d601..b6a7ca82 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -31,6 +31,7 @@ const components = { healthchecks: dynamic(() => import("./healthchecks/component")), immich: dynamic(() => import("./immich/component")), jackett: dynamic(() => import("./jackett/component")), + jdrssdownloader: dynamic(() => import("./jdrssdownloader/component")), jellyfin: dynamic(() => import("./emby/component")), jellyseerr: dynamic(() => import("./jellyseerr/component")), komga: dynamic(() => import("./komga/component")), diff --git a/src/widgets/jdrssdownloader/component.jsx b/src/widgets/jdrssdownloader/component.jsx new file mode 100644 index 00000000..1790e9a5 --- /dev/null +++ b/src/widgets/jdrssdownloader/component.jsx @@ -0,0 +1,37 @@ +import { useTranslation } from "next-i18next"; + +import Block from "components/services/widget/block"; +import Container from "components/services/widget/container"; +import useWidgetAPI from "utils/proxy/use-widget-api"; + +export default function Component({ service }) { + const { t } = useTranslation(); + + const { widget } = service; + + const { data: wgeasyData, error: wgeasyAPIError } = useWidgetAPI(widget, "unified", { + refreshInterval: 60000, + }); + + if (wgeasyAPIError) { + return ; + } + + if (!wgeasyData) { + return ( + + + + + + ); + } + + return ( + + + + + + ); +} \ No newline at end of file diff --git a/src/widgets/jdrssdownloader/proxy.js b/src/widgets/jdrssdownloader/proxy.js new file mode 100644 index 00000000..99452692 --- /dev/null +++ b/src/widgets/jdrssdownloader/proxy.js @@ -0,0 +1,97 @@ +/* eslint-disable no-underscore-dangle */ +import { formatApiCall } from "utils/proxy/api-helpers"; +import { httpProxy } from "utils/proxy/http"; +import getServiceWidget from "utils/config/service-helpers"; +import createLogger from "utils/logger"; +import widgets from "widgets/widgets"; + + +const proxyName = "JDRssProxyHandler"; + +const logger = createLogger(proxyName); + +async function getWidget(req) { + const { group, service } = req.query; + if (!group || !service) { + logger.debug("Invalid or missing service '%s' or group '%s'", service, group); + return null; + } + const widget = await getServiceWidget(group, service); + if (!widget) { + logger.debug("Invalid or missing widget for service '%s' in group '%s'", service, group); + return null; + } + + return widget; +} + +async function fetchDataFromJDRss(endpoint, widget) { + const api = widgets?.[widget.type]?.api; + if (!api) { + return [403, null]; + } + const url = `${new URL(formatApiCall(api, { endpoint, ...widget }))}` + const [status, contentType, data] = await httpProxy(url, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }); + + if (status !== 200) { + logger.error("HTTP %d communicating with JDRss. Data: %s", status, data.toString()); + return [status, data]; + } + + try { + return [status, JSON.parse(data), contentType]; + } catch (e) { + logger.error("Error decoding JDRss API data. Data: %s", data.toString()); + return [status, null]; + } +} + +export default async function JDRssProxyHandler(req, res) { + const widget = await getWidget(req); + + if (!widget) { + return res.status(400).json({ error: "Invalid proxy service type" }); + } + + logger.debug("Getting data from JDRss API"); + // Calculate the number of Tracked Shows + let [status, apiData] = await fetchDataFromJDRss('shows', widget); + + if (status !== 200) { + return res.status(status).json({ error: { message: "HTTP error communicating with WGeasy API", data: Buffer.from(apiData).toString() } }); + } + let showCount; + showCount = apiData.length; + + // Calculate the number of items in the retry cache + [status, apiData] = await fetchDataFromJDRss('retryCache', widget); + if (status !== 200) { + return res.status(status).json({ error: { message: "HTTP error communicating with WGeasy API", data: Buffer.from(apiData).toString() } }); + } + let retryCache; + retryCache = apiData.length; + + // Calculate the number of items in the feed cache + [status, apiData] = await fetchDataFromJDRss('feedCache', widget); + if (status !== 200) { + return res.status(status).json({ error: { message: "HTTP error communicating with WGeasy API", data: Buffer.from(apiData).toString() } }); + } + let feedCache; + feedCache = apiData.length; + + const data = { + showCount:showCount, + retryCache:retryCache, + feedCache:feedCache + + }; + + return res.status(status).send(data); + +} + diff --git a/src/widgets/jdrssdownloader/widget.js b/src/widgets/jdrssdownloader/widget.js new file mode 100644 index 00000000..d372d0cf --- /dev/null +++ b/src/widgets/jdrssdownloader/widget.js @@ -0,0 +1,14 @@ +import JDRssProxyHandler from "./proxy"; + +const widget = { + api: "{url}/api/{endpoint}", + proxyHandler: JDRssProxyHandler, + + mappings: { + unified: { + endpoint: "/", + }, + }, +}; + +export default widget; \ No newline at end of file diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index ff770939..a2a00ff7 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -84,6 +84,7 @@ import uptimekuma from "./uptimekuma/widget"; import watchtower from "./watchtower/widget"; import whatsupdocker from "./whatsupdocker/widget"; import xteve from "./xteve/widget"; +import jdrssdownloader from "./jdrssdownloader/widget"; const widgets = { adguard, @@ -115,6 +116,7 @@ const widgets = { immich, jackett, jellyfin: emby, + jdrssdownloader, jellyseerr, komga, kopia,