diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 50e796f58..6bb3377e6 100755 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -517,5 +517,9 @@ "active_workers": "Active Workers", "total_workers": "Total Workers", "records_total": "Queue Length" + }, + "pterodactyl": { + "servers": "Servers", + "nodes": "Nodes" } -} \ No newline at end of file +} diff --git a/src/utils/proxy/handlers/credentialed.js b/src/utils/proxy/handlers/credentialed.js index 4d5b4a25d..a84897f07 100644 --- a/src/utils/proxy/handlers/credentialed.js +++ b/src/utils/proxy/handlers/credentialed.js @@ -46,6 +46,8 @@ export default async function credentialedProxyHandler(req, res, map) { } else if (widget.type === "cloudflared") { headers["X-Auth-Email"] = `${widget.email}`; headers["X-Auth-Key"] = `${widget.key}`; + } else if (widget.type === "pterodactyl") { + headers.Authorization = `Bearer ${widget.key}`; } else { headers["X-API-Key"] = `${widget.key}`; } diff --git a/src/widgets/components.js b/src/widgets/components.js index cfd4d01a6..28a70755c 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -52,6 +52,7 @@ const components = { portainer: dynamic(() => import("./portainer/component")), prowlarr: dynamic(() => import("./prowlarr/component")), proxmox: dynamic(() => import("./proxmox/component")), + pterodactyl: dynamic(() => import("./pterodactyl/component")), pyload: dynamic(() => import("./pyload/component")), qbittorrent: dynamic(() => import("./qbittorrent/component")), radarr: dynamic(() => import("./radarr/component")), @@ -76,4 +77,4 @@ const components = { uptimekuma: dynamic(() => import("./uptimekuma/component")), }; -export default components; \ No newline at end of file +export default components; diff --git a/src/widgets/pterodactyl/component.jsx b/src/widgets/pterodactyl/component.jsx new file mode 100644 index 000000000..346ce2349 --- /dev/null +++ b/src/widgets/pterodactyl/component.jsx @@ -0,0 +1,34 @@ + +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 {widget} = service; + + const {data: nodesData, error: nodesError} = useWidgetAPI(widget, "nodes"); + + if (nodesError) { + return ; + } + + if (!nodesData) { + return ( + + + + + ); + } + + const totalServers = nodesData.data.reduce((total, node) => + node.attributes?.relationships?.servers?.data?.length ?? 0 + total, 0); + + return ( + + + + + ); +} diff --git a/src/widgets/pterodactyl/widget.js b/src/widgets/pterodactyl/widget.js new file mode 100644 index 000000000..39d0eef2f --- /dev/null +++ b/src/widgets/pterodactyl/widget.js @@ -0,0 +1,17 @@ +import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; + +const widget = { + api: "{url}/api/application/{endpoint}", + proxyHandler: credentialedProxyHandler, + + mappings: { + nodes: { + endpoint: "nodes?include=servers", + validate: [ + "data" + ] + }, + }, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 7df127764..5d4b74a23 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -46,6 +46,7 @@ import plex from "./plex/widget"; import portainer from "./portainer/widget"; import prowlarr from "./prowlarr/widget"; import proxmox from "./proxmox/widget"; +import pterodactyl from "./pterodactyl/widget"; import pyload from "./pyload/widget"; import qbittorrent from "./qbittorrent/widget"; import radarr from "./radarr/widget"; @@ -119,6 +120,7 @@ const widgets = { portainer, prowlarr, proxmox, + pterodactyl, pyload, qbittorrent, radarr, @@ -144,4 +146,4 @@ const widgets = { uptimekuma, }; -export default widgets; \ No newline at end of file +export default widgets;