mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-10-31 06:24:02 +00:00 
			
		
		
		
	Add Pyload widget
This commit is contained in:
		
							parent
							
								
									49a764e864
								
							
						
					
					
						commit
						5b21444c2e
					
				| @ -292,5 +292,11 @@ | |||||||
|         "containers_scanned": "Scanned", |         "containers_scanned": "Scanned", | ||||||
|         "containers_updated": "Updated", |         "containers_updated": "Updated", | ||||||
|         "containers_failed": "Failed" |         "containers_failed": "Failed" | ||||||
|  |     }, | ||||||
|  |     "pyload": { | ||||||
|  |         "speed": "Geschwindigkeit", | ||||||
|  |         "active": "Aktiv", | ||||||
|  |         "queue": "Warteschlange", | ||||||
|  |         "total": "Gesamt" | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -303,5 +303,11 @@ | |||||||
|         "rejectedPushes": "Rejected", |         "rejectedPushes": "Rejected", | ||||||
|         "filters": "Filters", |         "filters": "Filters", | ||||||
|         "indexers": "Indexers" |         "indexers": "Indexers" | ||||||
|  |     }, | ||||||
|  |     "pyload": { | ||||||
|  |         "speed": "Speed", | ||||||
|  |         "active": "Active", | ||||||
|  |         "queue": "Queue", | ||||||
|  |         "total": "Total" | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -25,6 +25,7 @@ const components = { | |||||||
|   portainer: dynamic(() => import("./portainer/component")), |   portainer: dynamic(() => import("./portainer/component")), | ||||||
|   prowlarr: dynamic(() => import("./prowlarr/component")), |   prowlarr: dynamic(() => import("./prowlarr/component")), | ||||||
|   proxmox: dynamic(() => import("./proxmox/component")), |   proxmox: dynamic(() => import("./proxmox/component")), | ||||||
|  |   pyload: dynamic(() => import("./pyload/component")), | ||||||
|   qbittorrent: dynamic(() => import("./qbittorrent/component")), |   qbittorrent: dynamic(() => import("./qbittorrent/component")), | ||||||
|   radarr: dynamic(() => import("./radarr/component")), |   radarr: dynamic(() => import("./radarr/component")), | ||||||
|   readarr: dynamic(() => import("./readarr/component")), |   readarr: dynamic(() => import("./readarr/component")), | ||||||
|  | |||||||
							
								
								
									
										27
									
								
								src/widgets/pyload/component.jsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/widgets/pyload/component.jsx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | |||||||
|  | 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: pyloadData, error: pyloadError } = useWidgetAPI( | ||||||
|  |     widget, | ||||||
|  |     'statusServer', | ||||||
|  |   ) | ||||||
|  | 
 | ||||||
|  |   if (pyloadError || !pyloadData) { | ||||||
|  |     return <Container error={t('widget.api_error')} /> | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return ( | ||||||
|  |     <Container service={service}> | ||||||
|  |       <Block label="pyload.speed" value={t("common.bitrate", { value: pyloadData.speed })} /> | ||||||
|  |       <Block label="pyload.active" value={t("common.number", { value: pyloadData.active })} /> | ||||||
|  |       <Block label="pyload.queue" value={t("common.number", { value: pyloadData.queue })} /> | ||||||
|  |       <Block label="pyload.total" value={t("common.number", { value: pyloadData.total })} /> | ||||||
|  |     </Container> | ||||||
|  |   ) | ||||||
|  | } | ||||||
							
								
								
									
										38
									
								
								src/widgets/pyload/proxy.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/widgets/pyload/proxy.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,38 @@ | |||||||
|  | import getServiceWidget from "utils/config/service-helpers"; | ||||||
|  | import { formatApiCall } from "utils/proxy/api-helpers"; | ||||||
|  | import widgets from "widgets/widgets"; | ||||||
|  | 
 | ||||||
|  | export default async function pyloadProxyHandler(req, res) { | ||||||
|  |   const { group, service, endpoint } = req.query; | ||||||
|  | 
 | ||||||
|  |   if (group && service) { | ||||||
|  |     const widget = await getServiceWidget(group, service); | ||||||
|  | 
 | ||||||
|  |     if (widget) { | ||||||
|  |       const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...widget })); | ||||||
|  |       const loginUrl = `${widget.url}/api/login`; | ||||||
|  | 
 | ||||||
|  |       // Pyload api does not support argument passing as JSON.
 | ||||||
|  |       const sessionId = await fetch(loginUrl, { | ||||||
|  |         method: "POST", | ||||||
|  |         // Empty passwords are supported.
 | ||||||
|  |         body: `username=${widget.username}&password=${widget.password ?? ''}`, | ||||||
|  |         headers: { | ||||||
|  |           "Content-Type": "application/x-www-form-urlencoded", | ||||||
|  |         }, | ||||||
|  |       }).then((response) => response.json()); | ||||||
|  | 
 | ||||||
|  |       const apiResponse = await fetch(url, { | ||||||
|  |         method: "POST", | ||||||
|  |         body: `session=${sessionId}`, | ||||||
|  |         headers: { | ||||||
|  |           "Content-Type": "application/x-www-form-urlencoded", | ||||||
|  |         }, | ||||||
|  |       }).then((response) => response.json()); | ||||||
|  | 
 | ||||||
|  |       return res.send(apiResponse); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return res.status(400).json({ error: "Invalid proxy service type" }); | ||||||
|  | } | ||||||
							
								
								
									
										8
									
								
								src/widgets/pyload/widget.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/widgets/pyload/widget.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | import pyloadProxyHandler from "./proxy"; | ||||||
|  | 
 | ||||||
|  | const widget = { | ||||||
|  |   api: "{url}/api/{endpoint}", | ||||||
|  |   proxyHandler: pyloadProxyHandler, | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export default widget; | ||||||
| @ -20,6 +20,7 @@ import plex from "./plex/widget"; | |||||||
| import portainer from "./portainer/widget"; | import portainer from "./portainer/widget"; | ||||||
| import prowlarr from "./prowlarr/widget"; | import prowlarr from "./prowlarr/widget"; | ||||||
| import proxmox from "./proxmox/widget"; | import proxmox from "./proxmox/widget"; | ||||||
|  | import pyload from "./pyload/widget"; | ||||||
| import qbittorrent from "./qbittorrent/widget"; | import qbittorrent from "./qbittorrent/widget"; | ||||||
| import radarr from "./radarr/widget"; | import radarr from "./radarr/widget"; | ||||||
| import readarr from "./readarr/widget"; | import readarr from "./readarr/widget"; | ||||||
| @ -58,6 +59,7 @@ const widgets = { | |||||||
|   portainer, |   portainer, | ||||||
|   prowlarr, |   prowlarr, | ||||||
|   proxmox, |   proxmox, | ||||||
|  |   pyload, | ||||||
|   qbittorrent, |   qbittorrent, | ||||||
|   radarr, |   radarr, | ||||||
|   readarr, |   readarr, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 stuffinator
						stuffinator