From 0d25f5789b2b46b8adb85eb31883f31fe07f61df Mon Sep 17 00:00:00 2001
From: Devedse <2350015+devedse@users.noreply.github.com>
Date: Fri, 16 Aug 2024 01:28:53 +0200
Subject: [PATCH] Feature: DeveLanCacheUI service widget (#3854)
---------
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
---
docs/widgets/services/develancacheui.md | 14 +++++++++
docs/widgets/services/index.md | 1 +
public/locales/en/common.json | 4 +++
src/widgets/components.js | 1 +
src/widgets/develancacheui/component.jsx | 39 ++++++++++++++++++++++++
src/widgets/develancacheui/widget.js | 14 +++++++++
src/widgets/widgets.js | 2 ++
7 files changed, 75 insertions(+)
create mode 100644 docs/widgets/services/develancacheui.md
create mode 100644 src/widgets/develancacheui/component.jsx
create mode 100644 src/widgets/develancacheui/widget.js
diff --git a/docs/widgets/services/develancacheui.md b/docs/widgets/services/develancacheui.md
new file mode 100644
index 000000000..d385fe782
--- /dev/null
+++ b/docs/widgets/services/develancacheui.md
@@ -0,0 +1,14 @@
+---
+title: DeveLanCacheUI
+description: DeveLanCacheUI Widget Configuration
+---
+
+Learn more about [DeveLanCacheUI](https://github.com/devedse/DeveLanCacheUI_Backend).
+
+```yaml
+widget:
+ type: develancacheui
+ url: http://your.develancacheui_backend.host:port
+```
+
+The url should point to the DeveLanCacheUI Backend (API)
diff --git a/docs/widgets/services/index.md b/docs/widgets/services/index.md
index c2c80ddb2..c39ac0f09 100644
--- a/docs/widgets/services/index.md
+++ b/docs/widgets/services/index.md
@@ -22,6 +22,7 @@ You can also find a list of all available service widgets in the sidebar navigat
- [CrowdSec](crowdsec.md)
- [Custom API](customapi.md)
- [Deluge](deluge.md)
+- [DeveLanCacheUI](develancacheui.md)
- [DiskStation](diskstation.md)
- [DownloadStation](downloadstation.md)
- [Emby](emby.md)
diff --git a/public/locales/en/common.json b/public/locales/en/common.json
index cd9b2c143..1ac41f901 100644
--- a/public/locales/en/common.json
+++ b/public/locales/en/common.json
@@ -226,6 +226,10 @@
"leech": "Leech",
"seed": "Seed"
},
+ "develancacheui": {
+ "cachehitbytes": "Cache Hit Bytes",
+ "cachemissbytes": "Cache Miss Bytes"
+ },
"downloadstation": {
"download": "Download",
"upload": "Upload",
diff --git a/src/widgets/components.js b/src/widgets/components.js
index 159202421..b2d6659e3 100644
--- a/src/widgets/components.js
+++ b/src/widgets/components.js
@@ -19,6 +19,7 @@ const components = {
iframe: dynamic(() => import("./iframe/component")),
customapi: dynamic(() => import("./customapi/component")),
deluge: dynamic(() => import("./deluge/component")),
+ develancacheui: dynamic(() => import("./develancacheui/component")),
diskstation: dynamic(() => import("./diskstation/component")),
downloadstation: dynamic(() => import("./downloadstation/component")),
docker: dynamic(() => import("./docker/component")),
diff --git a/src/widgets/develancacheui/component.jsx b/src/widgets/develancacheui/component.jsx
new file mode 100644
index 000000000..b13852c65
--- /dev/null
+++ b/src/widgets/develancacheui/component.jsx
@@ -0,0 +1,39 @@
+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: downloadStatsData, error: downloadStatsError } = useWidgetAPI(widget, "stats");
+
+ if (downloadStatsError) {
+ return ;
+ }
+
+ if (!downloadStatsData) {
+ return (
+
+
+
+
+ );
+ }
+
+ return (
+
+
+
+
+ );
+}
diff --git a/src/widgets/develancacheui/widget.js b/src/widgets/develancacheui/widget.js
new file mode 100644
index 000000000..e84b9d449
--- /dev/null
+++ b/src/widgets/develancacheui/widget.js
@@ -0,0 +1,14 @@
+import genericProxyHandler from "utils/proxy/handlers/generic";
+
+const widget = {
+ api: "{url}/{endpoint}",
+ proxyHandler: genericProxyHandler,
+
+ mappings: {
+ stats: {
+ endpoint: "DownloadStats/GetTotalDownloadStats",
+ },
+ },
+};
+
+export default widget;
diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js
index 684e2b7f7..f4e55d57c 100644
--- a/src/widgets/widgets.js
+++ b/src/widgets/widgets.js
@@ -15,6 +15,7 @@ import coinmarketcap from "./coinmarketcap/widget";
import crowdsec from "./crowdsec/widget";
import customapi from "./customapi/widget";
import deluge from "./deluge/widget";
+import develancacheui from "./develancacheui/widget";
import diskstation from "./diskstation/widget";
import downloadstation from "./downloadstation/widget";
import emby from "./emby/widget";
@@ -135,6 +136,7 @@ const widgets = {
crowdsec,
customapi,
deluge,
+ develancacheui,
diskstation,
downloadstation,
emby,