mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00
add speedtest-tracker integration
This commit is contained in:
parent
0076701091
commit
ac718c852a
@ -9,7 +9,8 @@
|
|||||||
- Docker Integration
|
- Docker Integration
|
||||||
- Status light + CPU, Memory & Network Reporting *(click on the status light)*
|
- Status light + CPU, Memory & Network Reporting *(click on the status light)*
|
||||||
- Service Integration
|
- Service Integration
|
||||||
- Currently supports Sonarr, Radarr, Ombi, Emby, Jellyfin, NZBGet, ruTorrent, Portainer & PiHole
|
- Currently supports Sonarr, Radarr, Ombi, Emby, Jellyfin, NZBGet, ruTorrent
|
||||||
|
- Portainer, Speedtest Tracker, PiHole
|
||||||
* Homepage Widgets
|
* Homepage Widgets
|
||||||
- System Stats (Disk, CPU, Memory)
|
- System Stats (Disk, CPU, Memory)
|
||||||
- Weather (via weatherapi.com)
|
- Weather (via weatherapi.com)
|
||||||
|
@ -8,6 +8,7 @@ import Docker from "./widgets/service/docker";
|
|||||||
import Pihole from "./widgets/service/pihole";
|
import Pihole from "./widgets/service/pihole";
|
||||||
import Rutorrent from "./widgets/service/rutorrent";
|
import Rutorrent from "./widgets/service/rutorrent";
|
||||||
import Jellyfin from "./widgets/service/jellyfin";
|
import Jellyfin from "./widgets/service/jellyfin";
|
||||||
|
import Speedtest from "./widgets/service/speedtest";
|
||||||
|
|
||||||
const widgetMappings = {
|
const widgetMappings = {
|
||||||
docker: Docker,
|
docker: Docker,
|
||||||
@ -20,6 +21,7 @@ const widgetMappings = {
|
|||||||
nzbget: Nzbget,
|
nzbget: Nzbget,
|
||||||
pihole: Pihole,
|
pihole: Pihole,
|
||||||
rutorrent: Rutorrent,
|
rutorrent: Rutorrent,
|
||||||
|
speedtest: Speedtest,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Widget({ service }) {
|
export default function Widget({ service }) {
|
||||||
|
39
src/components/services/widgets/service/speedtest.jsx
Normal file
39
src/components/services/widgets/service/speedtest.jsx
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import useSWR from "swr";
|
||||||
|
|
||||||
|
import Widget from "../widget";
|
||||||
|
import Block from "../block";
|
||||||
|
|
||||||
|
import { formatBits } from "utils/stats-helpers";
|
||||||
|
|
||||||
|
export default function Speedtest({ service }) {
|
||||||
|
const config = service.widget;
|
||||||
|
|
||||||
|
function buildApiUrl(endpoint) {
|
||||||
|
const { url } = config;
|
||||||
|
return `${url}/api/${endpoint}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data: speedtestData, error: speedtestError } = useSWR(buildApiUrl("speedtest/latest"));
|
||||||
|
|
||||||
|
if (speedtestError) {
|
||||||
|
return <Widget error="Speedtest API Error" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!speedtestData) {
|
||||||
|
return (
|
||||||
|
<Widget>
|
||||||
|
<Block label="Download" />
|
||||||
|
<Block label="Upload" />
|
||||||
|
<Block label="Ping" />
|
||||||
|
</Widget>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Widget>
|
||||||
|
<Block label="Download" value={`${formatBits(speedtestData.data.download * 1024 * 1024)}ps`} />
|
||||||
|
<Block label="Upload" value={`${formatBits(speedtestData.data.upload * 1024 * 1024)}ps`} />
|
||||||
|
<Block label="Ping" value={`${speedtestData.data.ping} ms`} />
|
||||||
|
</Widget>
|
||||||
|
);
|
||||||
|
}
|
@ -21,3 +21,15 @@ export function formatBytes(bytes, decimals = 2) {
|
|||||||
|
|
||||||
return parseFloat(bytes / Math.pow(k, i)).toFixed(dm) + " " + sizes[i];
|
return parseFloat(bytes / Math.pow(k, i)).toFixed(dm) + " " + sizes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatBits(bytes, decimals = 2) {
|
||||||
|
if (bytes === 0) return "0 Bytes";
|
||||||
|
|
||||||
|
const k = 1024;
|
||||||
|
const dm = decimals < 0 ? 0 : decimals;
|
||||||
|
const sizes = ["B", "Kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Yb"];
|
||||||
|
|
||||||
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||||
|
|
||||||
|
return parseFloat(bytes / Math.pow(k, i)).toFixed(dm) + " " + sizes[i];
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user