mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-09 06:48:47 +00:00
add ruTorrent widget
This commit is contained in:
parent
1f3cd43bef
commit
66e7637ea6
5 changed files with 223 additions and 0 deletions
|
@ -6,6 +6,7 @@ import Emby from "./widgets/service/emby";
|
|||
import Nzbget from "./widgets/service/nzbget";
|
||||
import Docker from "./widgets/service/docker";
|
||||
import Pihole from "./widgets/service/pihole";
|
||||
import Rutorrent from "./widgets/service/rutorrent";
|
||||
|
||||
const widgetMappings = {
|
||||
docker: Docker,
|
||||
|
@ -16,6 +17,7 @@ const widgetMappings = {
|
|||
emby: Emby,
|
||||
nzbget: Nzbget,
|
||||
pihole: Pihole,
|
||||
rutorrent: Rutorrent,
|
||||
};
|
||||
|
||||
export default function Widget({ service }) {
|
||||
|
|
62
src/components/services/widgets/service/rutorrent.jsx
Normal file
62
src/components/services/widgets/service/rutorrent.jsx
Normal file
|
@ -0,0 +1,62 @@
|
|||
import useSWR from "swr";
|
||||
import RuTorrent from "rutorrent-promise";
|
||||
|
||||
import { formatBytes } from "utils/stats-helpers";
|
||||
|
||||
import Widget from "../widget";
|
||||
import Block from "../block";
|
||||
|
||||
export default function Rutorrent({ service }) {
|
||||
const config = service.widget;
|
||||
|
||||
function buildApiUrl() {
|
||||
const { url, username, password } = config;
|
||||
|
||||
const options = {
|
||||
url: `${url}/plugins/httprpc/action.php`,
|
||||
};
|
||||
|
||||
if (username && password) {
|
||||
options.username = username;
|
||||
options.password = password;
|
||||
}
|
||||
|
||||
const params = new URLSearchParams(options);
|
||||
|
||||
return `/api/widgets/rutorrent?${params.toString()}`;
|
||||
}
|
||||
|
||||
const { data: statusData, error: statusError } = useSWR(buildApiUrl());
|
||||
|
||||
if (statusError) {
|
||||
return <Widget error="Nzbget API Error" />;
|
||||
}
|
||||
|
||||
if (!statusData) {
|
||||
return (
|
||||
<Widget>
|
||||
<Block label="Active" />
|
||||
<Block label="Upload" />
|
||||
<Block label="Download" />
|
||||
</Widget>
|
||||
);
|
||||
}
|
||||
|
||||
const upload = statusData.reduce((acc, torrent) => {
|
||||
return acc + parseInt(torrent["d.get_up_rate"]);
|
||||
}, 0);
|
||||
|
||||
const download = statusData.reduce((acc, torrent) => {
|
||||
return acc + parseInt(torrent["d.get_down_rate"]);
|
||||
}, 0);
|
||||
|
||||
const active = statusData.filter((torrent) => torrent["d.get_state"] === "1");
|
||||
|
||||
return (
|
||||
<Widget>
|
||||
<Block label="Active" value={active.length} />
|
||||
<Block label="Upload" value={`${formatBytes(upload)}/s`} />
|
||||
<Block label="Download" value={`${formatBytes(download)}/s`} />
|
||||
</Widget>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue