Add Pyload widget

pull/496/head
stuffinator 2 years ago
parent 49a764e864
commit 5b21444c2e

@ -292,5 +292,11 @@
"containers_scanned": "Scanned",
"containers_updated": "Updated",
"containers_failed": "Failed"
},
"pyload": {
"speed": "Geschwindigkeit",
"active": "Aktiv",
"queue": "Warteschlange",
"total": "Gesamt"
}
}

@ -303,5 +303,11 @@
"rejectedPushes": "Rejected",
"filters": "Filters",
"indexers": "Indexers"
},
"pyload": {
"speed": "Speed",
"active": "Active",
"queue": "Queue",
"total": "Total"
}
}

@ -25,6 +25,7 @@ const components = {
portainer: dynamic(() => import("./portainer/component")),
prowlarr: dynamic(() => import("./prowlarr/component")),
proxmox: dynamic(() => import("./proxmox/component")),
pyload: dynamic(() => import("./pyload/component")),
qbittorrent: dynamic(() => import("./qbittorrent/component")),
radarr: dynamic(() => import("./radarr/component")),
readarr: dynamic(() => import("./readarr/component")),

@ -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>
)
}

@ -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" });
}

@ -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 prowlarr from "./prowlarr/widget";
import proxmox from "./proxmox/widget";
import pyload from "./pyload/widget";
import qbittorrent from "./qbittorrent/widget";
import radarr from "./radarr/widget";
import readarr from "./readarr/widget";
@ -58,6 +59,7 @@ const widgets = {
portainer,
prowlarr,
proxmox,
pyload,
qbittorrent,
radarr,
readarr,

Loading…
Cancel
Save