diff --git a/public/locales/en/common.json b/public/locales/en/common.json index de972f78..3b96d09b 100755 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -663,6 +663,11 @@ "upcoming": "Upcoming", "ready": "Recent" }, + "jdrssdownloader": { + "totalShows": "Tracked Shows", + "retryCache": "Retry Cache", + "feedCache": "Feed Cache" + }, "wgeasy": { "clients": "Total Clients" } diff --git a/src/widgets/components.js b/src/widgets/components.js index 5d2dc7e6..3bbab8bb 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -32,6 +32,7 @@ const components = { immich: dynamic(() => import("./immich/component")), jackett: dynamic(() => import("./jackett/component")), jdownloader: dynamic(() => import("./jdownloader/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..c301b447 --- /dev/null +++ b/src/widgets/jdrssdownloader/proxy.js @@ -0,0 +1,77 @@ +/* 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"); + // Get data from JDRss stats API + const [status, apiData] = await fetchDataFromJDRss('stats', widget); + + if (status !== 200) { + return res.status(status).json({ error: { message: "HTTP error communicating with JDRss API", data: Buffer.from(apiData).toString() } }); + } + const data = { + showCount:apiData.ShowList , + retryCache:apiData.RetryCache, + feedCache: apiData.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 ab8beb56..947be341 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -86,6 +86,7 @@ import watchtower from "./watchtower/widget"; import whatsupdocker from "./whatsupdocker/widget"; import wgeasy from "./wgeasy/widget"; import xteve from "./xteve/widget"; +import jdrssdownloader from "./jdrssdownloader/widget"; const widgets = { adguard, @@ -118,6 +119,7 @@ const widgets = { jackett, jdownloader, jellyfin: emby, + jdrssdownloader, jellyseerr, komga, kopia,