Skip to content

Commit

Permalink
Feature: MySpeed widget (#3662)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: shamoon <[email protected]>
  • Loading branch information
gnmyt and shamoon committed Jun 23, 2024
1 parent f07d595 commit 148511e
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/widgets/services/myspeed.md
Original file line number Diff line number Diff line change
@@ -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:https://myspeed.host.or.ip:port
password: password # only required if password is set
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -888,5 +888,10 @@
"auth": "With Auth",
"outdated": "Outdated",
"banned": "Banned"
},
"myspeed": {
"ping": "Ping",
"download": "Download",
"upload": "Upload"
}
}
2 changes: 2 additions & 0 deletions src/utils/proxy/handlers/credentialed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
Expand Down
1 change: 1 addition & 0 deletions src/widgets/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
60 changes: 60 additions & 0 deletions src/widgets/myspeed/component.jsx
Original file line number Diff line number Diff line change
@@ -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>
);
}
14 changes: 14 additions & 0 deletions src/widgets/myspeed/widget.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions src/widgets/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -172,6 +173,7 @@ const widgets = {
mjpeg,
moonraker,
mylar,
myspeed,
navidrome,
netalertx,
netdata,
Expand Down

0 comments on commit 148511e

Please sign in to comment.