Feature: MySpeed widget (#3662)
--------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>pull/3667/head
parent
f07d595ed9
commit
148511e6f8
@ -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
|
||||
```
|
@ -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;
|
Loading…
Reference in new issue