From 2f9861b64d1e2d5046096ed9dfbeaf0d7b8241f6 Mon Sep 17 00:00:00 2001 From: Benoit Date: Thu, 12 Jan 2023 13:32:43 +0100 Subject: [PATCH] Synology widget : renaming widget to diskstation --- public/locales/en/common.json | 12 +----- src/widgets/components.js | 2 +- src/widgets/diskstation/component.jsx | 40 +++++++++++++++++++ .../{synology => diskstation}/proxy.js | 7 ++-- .../{synology => diskstation}/widget.js | 0 src/widgets/synology/component.jsx | 40 ------------------- src/widgets/widgets.js | 5 +-- 7 files changed, 47 insertions(+), 59 deletions(-) create mode 100644 src/widgets/diskstation/component.jsx rename src/widgets/{synology => diskstation}/proxy.js (98%) rename src/widgets/{synology => diskstation}/widget.js (100%) delete mode 100644 src/widgets/synology/component.jsx diff --git a/public/locales/en/common.json b/public/locales/en/common.json index ad77cbb2..9b4a30de 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -413,22 +413,12 @@ "wanUpload": "WAN Upload", "wanDownload": "WAN Download" }, - "synology": { + "diskstation": { "uptime": "Uptime", "volumeUsage": "Volume Usage", "cpuLoad": "CPU Load", "memoryUsage": "Memory Usage", "status": "Status", "volumeTotal": "Total space" - }, - "opnsense": { - "cpu": "CPU Load", - "memory": "Memory Used", - "uptime": "Uptime", - "wanUpload": "WAN Upload", - "wanDownload": "WAN Download", - "wanUploadRate": "WAN Upload Rate", - "wanDownloadRate": "WAN Download Rate" - } } diff --git a/src/widgets/components.js b/src/widgets/components.js index b25ecd31..70dbf6c5 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -47,7 +47,7 @@ const components = { sonarr: dynamic(() => import("./sonarr/component")), speedtest: dynamic(() => import("./speedtest/component")), strelaysrv: dynamic(() => import("./strelaysrv/component")), - synology: dynamic(() => import("./synology/component")), + diskstation: dynamic(() => import("./diskstation/component")), tautulli: dynamic(() => import("./tautulli/component")), tdarr: dynamic(() => import("./tdarr/component")), traefik: dynamic(() => import("./traefik/component")), diff --git a/src/widgets/diskstation/component.jsx b/src/widgets/diskstation/component.jsx new file mode 100644 index 00000000..aaf69d31 --- /dev/null +++ b/src/widgets/diskstation/component.jsx @@ -0,0 +1,40 @@ +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: dsData, error: dsError } = useWidgetAPI(widget); + + if (dsError) { + return ; + } + + if (!dsData) { + return ( + + + + + + + + ); + } + + + return ( + + + + + + + + ); +} diff --git a/src/widgets/synology/proxy.js b/src/widgets/diskstation/proxy.js similarity index 98% rename from src/widgets/synology/proxy.js rename to src/widgets/diskstation/proxy.js index aa1023bc..55d22e31 100644 --- a/src/widgets/synology/proxy.js +++ b/src/widgets/diskstation/proxy.js @@ -106,13 +106,12 @@ export default async function synologyProxyHandler(req, res) { const memoryUsage = 100 - (100 * (parseFloat(JSON.parse(data.toString()).data.memory.avail_real) + parseFloat(JSON.parse(data.toString()).data.memory.cached)) / parseFloat(JSON.parse(data.toString()).data.memory.total_real)); const cpuLoad = parseFloat(JSON.parse(data.toString()).data.cpu.user_load) + parseFloat(JSON.parse(data.toString()).data.cpu.system_load); - const resdata = { + if (contentType) res.setHeader("Content-Type", contentType); + return res.status(status).send(JSON.stringify({ uptime, usedVolume, totalSize, memoryUsage, cpuLoad, - } - if (contentType) res.setHeader("Content-Type", contentType); - return res.status(status).send(JSON.stringify(resdata)); + })); } diff --git a/src/widgets/synology/widget.js b/src/widgets/diskstation/widget.js similarity index 100% rename from src/widgets/synology/widget.js rename to src/widgets/diskstation/widget.js diff --git a/src/widgets/synology/component.jsx b/src/widgets/synology/component.jsx deleted file mode 100644 index 95405e84..00000000 --- a/src/widgets/synology/component.jsx +++ /dev/null @@ -1,40 +0,0 @@ -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: dsData, error: dsError } = useWidgetAPI(widget); - - if (dsError) { - return ; - } - - if (!dsData) { - return ( - - - - - - - - ); - } - - - return ( - - - - - - - - ); -} diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 93bb2aaa..7a96a128 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -42,7 +42,7 @@ import scrutiny from "./scrutiny/widget"; import sonarr from "./sonarr/widget"; import speedtest from "./speedtest/widget"; import strelaysrv from "./strelaysrv/widget"; -import synology from "./synology/widget"; +import diskstation from "./diskstation/widget"; import tautulli from "./tautulli/widget"; import tdarr from "./tdarr/widget"; import traefik from "./traefik/widget"; @@ -61,7 +61,7 @@ const widgets = { changedetectionio, coinmarketcap, deluge, - diskstation: downloadstation, + diskstation, downloadstation, emby, flood, @@ -100,7 +100,6 @@ const widgets = { sonarr, speedtest, strelaysrv, - synology, tautulli, tdarr, traefik,