mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-03 14:03:40 +01:00
Feature: MySpeed widget (#3662)
--------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
parent
f07d595ed9
commit
148511e6f8
15
docs/widgets/services/myspeed.md
Normal file
15
docs/widgets/services/myspeed.md
Normal file
@ -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/mjpeg.md
|
||||||
- widgets/services/moonraker.md
|
- widgets/services/moonraker.md
|
||||||
- widgets/services/mylar.md
|
- widgets/services/mylar.md
|
||||||
|
- widgets/services/myspeed.md
|
||||||
- widgets/services/navidrome.md
|
- widgets/services/navidrome.md
|
||||||
- widgets/services/netdata.md
|
- widgets/services/netdata.md
|
||||||
- widgets/services/netalertx.md
|
- widgets/services/netalertx.md
|
||||||
|
@ -888,5 +888,10 @@
|
|||||||
"auth": "With Auth",
|
"auth": "With Auth",
|
||||||
"outdated": "Outdated",
|
"outdated": "Outdated",
|
||||||
"banned": "Banned"
|
"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")}`;
|
headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`;
|
||||||
} else if (widget.type === "plantit") {
|
} else if (widget.type === "plantit") {
|
||||||
headers.Key = `${widget.key}`;
|
headers.Key = `${widget.key}`;
|
||||||
|
} else if (widget.type === "myspeed") {
|
||||||
|
headers.Password = `${widget.password}`;
|
||||||
} else {
|
} else {
|
||||||
headers["X-API-Key"] = `${widget.key}`;
|
headers["X-API-Key"] = `${widget.key}`;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ const components = {
|
|||||||
mjpeg: dynamic(() => import("./mjpeg/component")),
|
mjpeg: dynamic(() => import("./mjpeg/component")),
|
||||||
moonraker: dynamic(() => import("./moonraker/component")),
|
moonraker: dynamic(() => import("./moonraker/component")),
|
||||||
mylar: dynamic(() => import("./mylar/component")),
|
mylar: dynamic(() => import("./mylar/component")),
|
||||||
|
myspeed: dynamic(() => import("./myspeed/component")),
|
||||||
navidrome: dynamic(() => import("./navidrome/component")),
|
navidrome: dynamic(() => import("./navidrome/component")),
|
||||||
netalertx: dynamic(() => import("./netalertx/component")),
|
netalertx: dynamic(() => import("./netalertx/component")),
|
||||||
netdata: dynamic(() => import("./netdata/component")),
|
netdata: dynamic(() => import("./netdata/component")),
|
||||||
|
60
src/widgets/myspeed/component.jsx
Normal file
60
src/widgets/myspeed/component.jsx
Normal file
@ -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
src/widgets/myspeed/widget.js
Normal file
14
src/widgets/myspeed/widget.js
Normal file
@ -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 mjpeg from "./mjpeg/widget";
|
||||||
import moonraker from "./moonraker/widget";
|
import moonraker from "./moonraker/widget";
|
||||||
import mylar from "./mylar/widget";
|
import mylar from "./mylar/widget";
|
||||||
|
import myspeed from "./myspeed/widget";
|
||||||
import navidrome from "./navidrome/widget";
|
import navidrome from "./navidrome/widget";
|
||||||
import netalertx from "./netalertx/widget";
|
import netalertx from "./netalertx/widget";
|
||||||
import netdata from "./netdata/widget";
|
import netdata from "./netdata/widget";
|
||||||
@ -172,6 +173,7 @@ const widgets = {
|
|||||||
mjpeg,
|
mjpeg,
|
||||||
moonraker,
|
moonraker,
|
||||||
mylar,
|
mylar,
|
||||||
|
myspeed,
|
||||||
navidrome,
|
navidrome,
|
||||||
netalertx,
|
netalertx,
|
||||||
netdata,
|
netdata,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user