Feature: MySpeed widget (#3662)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
pull/3667/head
Mathias Wagner 4 months ago committed by GitHub
parent f07d595ed9
commit 148511e6f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,15 @@
---
title: MySpeed
description: MySpeed Widget Configuration
---
Learn more about [MySpeed](https://myspeed.dev/).
Allowed fields: `["ping", "download", "upload"]`.
```yaml
widget:
type: myspeed
url: http://myspeed.host.or.ip:port
password: password # only required if password is set
```

@ -88,6 +88,7 @@ nav:
- widgets/services/mjpeg.md
- widgets/services/moonraker.md
- widgets/services/mylar.md
- widgets/services/myspeed.md
- widgets/services/navidrome.md
- widgets/services/netdata.md
- widgets/services/netalertx.md

@ -888,5 +888,10 @@
"auth": "With Auth",
"outdated": "Outdated",
"banned": "Banned"
},
"myspeed": {
"ping": "Ping",
"download": "Download",
"upload": "Upload"
}
}

@ -69,6 +69,8 @@ export default async function credentialedProxyHandler(req, res, map) {
headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`;
} else if (widget.type === "plantit") {
headers.Key = `${widget.key}`;
} else if (widget.type === "myspeed") {
headers.Password = `${widget.password}`;
} else {
headers["X-API-Key"] = `${widget.key}`;
}

@ -62,6 +62,7 @@ const components = {
mjpeg: dynamic(() => import("./mjpeg/component")),
moonraker: dynamic(() => import("./moonraker/component")),
mylar: dynamic(() => import("./mylar/component")),
myspeed: dynamic(() => import("./myspeed/component")),
navidrome: dynamic(() => import("./navidrome/component")),
netalertx: dynamic(() => import("./netalertx/component")),
netdata: dynamic(() => import("./netdata/component")),

@ -0,0 +1,60 @@
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, error } = useWidgetAPI(widget, "info");
if (error || (data && data.message) || (data && data[0] && data[0].error)) {
let finalError = error ?? data;
if (data && data[0] && data[0].error) {
try {
finalError = JSON.parse(data[0].error);
} catch (e) {
finalError = data[0].error;
}
}
return <Container service={service} error={finalError} />;
}
if (!data || (data && data.length === 0)) {
return (
<Container service={service}>
<Block label="myspeed.ping" />
<Block label="myspeed.download" />
<Block label="myspeed.upload" />
</Container>
);
}
return (
<Container service={service}>
<Block
label="myspeed.ping"
value={t("common.ms", {
value: data[0].ping,
style: "unit",
unit: "millisecond",
})}
/>
<Block
label="myspeed.download"
value={t("common.bitrate", {
value: data[0].download * 1000 * 1000,
decimals: 2,
})}
/>
<Block
label="myspeed.upload"
value={t("common.bitrate", {
value: data[0].upload * 1000 * 1000,
decimals: 2,
})}
/>
</Container>
);
}

@ -0,0 +1,14 @@
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
const widget = {
api: "{url}/api/{endpoint}",
proxyHandler: credentialedProxyHandler,
mappings: {
info: {
endpoint: "speedtests?limit=1",
},
},
};
export default widget;

@ -54,6 +54,7 @@ import mikrotik from "./mikrotik/widget";
import mjpeg from "./mjpeg/widget";
import moonraker from "./moonraker/widget";
import mylar from "./mylar/widget";
import myspeed from "./myspeed/widget";
import navidrome from "./navidrome/widget";
import netalertx from "./netalertx/widget";
import netdata from "./netdata/widget";
@ -172,6 +173,7 @@ const widgets = {
mjpeg,
moonraker,
mylar,
myspeed,
navidrome,
netalertx,
netdata,

Loading…
Cancel
Save