mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-10-31 14:34:00 +00:00 
			
		
		
		
	JDRssDownloader
This commit is contained in:
		
							parent
							
								
									062e99da6f
								
							
						
					
					
						commit
						df0625550b
					
				| @ -653,5 +653,10 @@ | |||||||
|     "nextpvr": { |     "nextpvr": { | ||||||
|         "upcoming": "Upcoming", |         "upcoming": "Upcoming", | ||||||
|         "ready": "Recent" |         "ready": "Recent" | ||||||
|  |     }, | ||||||
|  |     "jdrssdownloader": { | ||||||
|  |         "totalShows": "Tracked Shows", | ||||||
|  |         "retryCache": "Retry Cache", | ||||||
|  |         "feedCache": "Feed Cache" | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -31,6 +31,7 @@ const components = { | |||||||
|   healthchecks: dynamic(() => import("./healthchecks/component")), |   healthchecks: dynamic(() => import("./healthchecks/component")), | ||||||
|   immich: dynamic(() => import("./immich/component")), |   immich: dynamic(() => import("./immich/component")), | ||||||
|   jackett: dynamic(() => import("./jackett/component")), |   jackett: dynamic(() => import("./jackett/component")), | ||||||
|  |   jdrssdownloader: dynamic(() => import("./jdrssdownloader/component")), | ||||||
|   jellyfin: dynamic(() => import("./emby/component")), |   jellyfin: dynamic(() => import("./emby/component")), | ||||||
|   jellyseerr: dynamic(() => import("./jellyseerr/component")), |   jellyseerr: dynamic(() => import("./jellyseerr/component")), | ||||||
|   komga: dynamic(() => import("./komga/component")), |   komga: dynamic(() => import("./komga/component")), | ||||||
|  | |||||||
							
								
								
									
										37
									
								
								src/widgets/jdrssdownloader/component.jsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/widgets/jdrssdownloader/component.jsx
									
									
									
									
									
										Normal file
									
								
							| @ -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 <Container service={service} error={wgeasyAPIError} />; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (!wgeasyData) { | ||||||
|  |         return ( | ||||||
|  |             <Container service={service}> | ||||||
|  |                 <Block label="jdrssdownloader.totalShows" /> | ||||||
|  |                 <Block label="jdrssdownloader.retryCache" /> | ||||||
|  |                 <Block label="jdrssdownloader.feedCache" /> | ||||||
|  |             </Container> | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return ( | ||||||
|  |         <Container service={service}> | ||||||
|  |             <Block label="jdrssdownloader.totalShows" value={t("common.number", { value: wgeasyData.showCount })} /> | ||||||
|  |             <Block label="jdrssdownloader.retryCache" value={t("common.number", { value: wgeasyData.retryCache })} /> | ||||||
|  |             <Block label="jdrssdownloader.feedCache" value={t("common.number", { value: wgeasyData.feedCache })} /> | ||||||
|  |         </Container> | ||||||
|  |     ); | ||||||
|  | } | ||||||
							
								
								
									
										97
									
								
								src/widgets/jdrssdownloader/proxy.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								src/widgets/jdrssdownloader/proxy.js
									
									
									
									
									
										Normal file
									
								
							| @ -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); | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
							
								
								
									
										14
									
								
								src/widgets/jdrssdownloader/widget.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/widgets/jdrssdownloader/widget.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | |||||||
|  | import JDRssProxyHandler from "./proxy"; | ||||||
|  | 
 | ||||||
|  | const widget = { | ||||||
|  |     api: "{url}/api/{endpoint}", | ||||||
|  |     proxyHandler: JDRssProxyHandler, | ||||||
|  | 
 | ||||||
|  |     mappings: { | ||||||
|  |         unified: { | ||||||
|  |             endpoint: "/", | ||||||
|  |         }, | ||||||
|  |     }, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export default widget; | ||||||
| @ -84,6 +84,7 @@ import uptimekuma from "./uptimekuma/widget"; | |||||||
| import watchtower from "./watchtower/widget"; | import watchtower from "./watchtower/widget"; | ||||||
| import whatsupdocker from "./whatsupdocker/widget"; | import whatsupdocker from "./whatsupdocker/widget"; | ||||||
| import xteve from "./xteve/widget"; | import xteve from "./xteve/widget"; | ||||||
|  | import jdrssdownloader from "./jdrssdownloader/widget"; | ||||||
| 
 | 
 | ||||||
| const widgets = { | const widgets = { | ||||||
|   adguard, |   adguard, | ||||||
| @ -115,6 +116,7 @@ const widgets = { | |||||||
|   immich, |   immich, | ||||||
|   jackett, |   jackett, | ||||||
|   jellyfin: emby, |   jellyfin: emby, | ||||||
|  |   jdrssdownloader, | ||||||
|   jellyseerr, |   jellyseerr, | ||||||
|   komga, |   komga, | ||||||
|   kopia, |   kopia, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Karl Hudgell
						Karl Hudgell