Enhancement: support speedtest v1.2 API (#4695)

pull/4701/head
shamoon 3 weeks ago committed by GitHub
parent cbacf458b2
commit 07dff4c8a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -8,7 +8,12 @@ Learn more about [Speedtest Tracker](https://github.com/alexjustesen/speedtest-t
No extra configuration is required.
This widget is compatible with both [alexjustesen/speedtest-tracker](https://github.com/alexjustesen/speedtest-tracker) and [henrywhitaker3/Speedtest-Tracker](https://github.com/henrywhitaker3/Speedtest-Tracker).
Version 1 of the widget is compatible with both [alexjustesen/speedtest-tracker](https://github.com/alexjustesen/speedtest-tracker) and [henrywhitaker3/Speedtest-Tracker](https://github.com/henrywhitaker3/Speedtest-Tracker), while version 2 is only compatible with [alexjustesen/speedtest-tracker](https://github.com/alexjustesen/speedtest-tracker).
| Speedtest Version (AJ) | Speedtest Version (HW) | Homepage Widget Version |
| ---------------------- | ---------------------- | ----------------------- |
| < 1.2.1 | 1.12.0 | 1 (default) |
| >= 1.2.1 | N/A | 2 |
Allowed fields: `["download", "upload", "ping"]`.
@ -16,5 +21,7 @@ Allowed fields: `["download", "upload", "ping"]`.
widget:
type: speedtest
url: http://speedtest.host.or.ip
version: 1 # optional, default is 1
key: speedtestapikey # required for version 2
bitratePrecision: 3 # optional, default is 0
```

@ -432,7 +432,7 @@ export function cleanServiceGroups(groups) {
// frigate
enableRecentEvents,
// beszel, glances, immich, mealie, pihole, pfsense
// beszel, glances, immich, mealie, pihole, pfsense, speedtest
version,
// glances
@ -610,7 +610,7 @@ export function cleanServiceGroups(groups) {
if (snapshotHost) widget.snapshotHost = snapshotHost;
if (snapshotPath) widget.snapshotPath = snapshotPath;
}
if (["beszel", "glances", "immich", "mealie", "pfsense", "pihole"].includes(type)) {
if (["beszel", "glances", "immich", "mealie", "pfsense", "pihole", "speedtest"].includes(type)) {
if (version) widget.version = parseInt(version, 10);
}
if (type === "glances") {

@ -99,6 +99,11 @@ export default async function credentialedProxyHandler(req, res, map) {
headers.Authorization = widget.password;
} else if (widget.type === "gitlab") {
headers["PRIVATE-TOKEN"] = widget.key;
} else if (widget.type === "speedtest") {
if (widget.key) {
// v1 does not require a key
headers.Authorization = `Bearer ${widget.key}`;
}
} else {
headers["X-API-Key"] = `${widget.key}`;
}

@ -9,18 +9,19 @@ export default function Component({ service }) {
const { widget } = service;
const { data: speedtestData, error: speedtestError } = useWidgetAPI(widget, "speedtest/latest");
const endpoint = widget.version === 2 ? "latestv2" : "latestv1";
const { data: speedtestData, error: speedtestError } = useWidgetAPI(widget, endpoint);
const bitratePrecision =
!widget?.bitratePrecision || Number.isNaN(widget?.bitratePrecision) || widget?.bitratePrecision < 0
? 0
: widget.bitratePrecision;
if (speedtestError) {
return <Container service={service} error={speedtestError} />;
if (speedtestError || speedtestData?.error) {
return <Container service={service} error={speedtestError ?? speedtestData.error} />;
}
if (!speedtestData) {
if (!speedtestData?.data) {
return (
<Container service={service}>
<Block label="speedtest.download" />

@ -1,14 +1,18 @@
import genericProxyHandler from "utils/proxy/handlers/generic";
import genericProxyHandler from "utils/proxy/handlers/credentialed";
const widget = {
api: "{url}/api/{endpoint}",
proxyHandler: genericProxyHandler,
mappings: {
"speedtest/latest": {
latestv1: {
endpoint: "speedtest/latest",
validate: ["data"],
},
latestv2: {
endpoint: "v1/results/latest",
validate: ["data"],
},
},
};

Loading…
Cancel
Save