mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-04 00:10:57 +00:00 
			
		
		
		
	Enhancement: support speedtest v1.2 API (#4695)
This commit is contained in:
		
							parent
							
								
									cbacf458b2
								
							
						
					
					
						commit
						07dff4c8a5
					
				@ -8,7 +8,12 @@ Learn more about [Speedtest Tracker](https://github.com/alexjustesen/speedtest-t
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
No extra configuration is required.
 | 
					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"]`.
 | 
					Allowed fields: `["download", "upload", "ping"]`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -16,5 +21,7 @@ Allowed fields: `["download", "upload", "ping"]`.
 | 
				
			|||||||
widget:
 | 
					widget:
 | 
				
			||||||
  type: speedtest
 | 
					  type: speedtest
 | 
				
			||||||
  url: http://speedtest.host.or.ip
 | 
					  url: http://speedtest.host.or.ip
 | 
				
			||||||
 | 
					  version: 1 # optional, default is 1
 | 
				
			||||||
 | 
					  key: speedtestapikey # required for version 2
 | 
				
			||||||
  bitratePrecision: 3 # optional, default is 0
 | 
					  bitratePrecision: 3 # optional, default is 0
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
				
			|||||||
@ -432,7 +432,7 @@ export function cleanServiceGroups(groups) {
 | 
				
			|||||||
          // frigate
 | 
					          // frigate
 | 
				
			||||||
          enableRecentEvents,
 | 
					          enableRecentEvents,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          // beszel, glances, immich, mealie, pihole, pfsense
 | 
					          // beszel, glances, immich, mealie, pihole, pfsense, speedtest
 | 
				
			||||||
          version,
 | 
					          version,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          // glances
 | 
					          // glances
 | 
				
			||||||
@ -610,7 +610,7 @@ export function cleanServiceGroups(groups) {
 | 
				
			|||||||
          if (snapshotHost) widget.snapshotHost = snapshotHost;
 | 
					          if (snapshotHost) widget.snapshotHost = snapshotHost;
 | 
				
			||||||
          if (snapshotPath) widget.snapshotPath = snapshotPath;
 | 
					          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 (version) widget.version = parseInt(version, 10);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (type === "glances") {
 | 
					        if (type === "glances") {
 | 
				
			||||||
 | 
				
			|||||||
@ -99,6 +99,11 @@ export default async function credentialedProxyHandler(req, res, map) {
 | 
				
			|||||||
        headers.Authorization = widget.password;
 | 
					        headers.Authorization = widget.password;
 | 
				
			||||||
      } else if (widget.type === "gitlab") {
 | 
					      } else if (widget.type === "gitlab") {
 | 
				
			||||||
        headers["PRIVATE-TOKEN"] = widget.key;
 | 
					        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 {
 | 
					      } else {
 | 
				
			||||||
        headers["X-API-Key"] = `${widget.key}`;
 | 
					        headers["X-API-Key"] = `${widget.key}`;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
				
			|||||||
@ -9,18 +9,19 @@ export default function Component({ service }) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  const { widget } = 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 =
 | 
					  const bitratePrecision =
 | 
				
			||||||
    !widget?.bitratePrecision || Number.isNaN(widget?.bitratePrecision) || widget?.bitratePrecision < 0
 | 
					    !widget?.bitratePrecision || Number.isNaN(widget?.bitratePrecision) || widget?.bitratePrecision < 0
 | 
				
			||||||
      ? 0
 | 
					      ? 0
 | 
				
			||||||
      : widget.bitratePrecision;
 | 
					      : widget.bitratePrecision;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (speedtestError) {
 | 
					  if (speedtestError || speedtestData?.error) {
 | 
				
			||||||
    return <Container service={service} error={speedtestError} />;
 | 
					    return <Container service={service} error={speedtestError ?? speedtestData.error} />;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!speedtestData) {
 | 
					  if (!speedtestData?.data) {
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      <Container service={service}>
 | 
					      <Container service={service}>
 | 
				
			||||||
        <Block label="speedtest.download" />
 | 
					        <Block label="speedtest.download" />
 | 
				
			||||||
 | 
				
			|||||||
@ -1,14 +1,18 @@
 | 
				
			|||||||
import genericProxyHandler from "utils/proxy/handlers/generic";
 | 
					import genericProxyHandler from "utils/proxy/handlers/credentialed";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const widget = {
 | 
					const widget = {
 | 
				
			||||||
  api: "{url}/api/{endpoint}",
 | 
					  api: "{url}/api/{endpoint}",
 | 
				
			||||||
  proxyHandler: genericProxyHandler,
 | 
					  proxyHandler: genericProxyHandler,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  mappings: {
 | 
					  mappings: {
 | 
				
			||||||
    "speedtest/latest": {
 | 
					    latestv1: {
 | 
				
			||||||
      endpoint: "speedtest/latest",
 | 
					      endpoint: "speedtest/latest",
 | 
				
			||||||
      validate: ["data"],
 | 
					      validate: ["data"],
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    latestv2: {
 | 
				
			||||||
 | 
					      endpoint: "v1/results/latest",
 | 
				
			||||||
 | 
					      validate: ["data"],
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user