From 370936095ebc7fe49d3d46a4a84d29baa2d9c8d5 Mon Sep 17 00:00:00 2001 From: grimsi <9295182+grimsi@users.noreply.github.com> Date: Sat, 1 Jun 2024 02:06:48 +0200 Subject: [PATCH] Implement mailcow widget --- docs/widgets/services/mailcow.md | 15 +++++++++++ public/locales/de/common.json | 6 +++++ public/locales/en/common.json | 6 +++++ src/widgets/components.js | 1 + src/widgets/mailcow/component.jsx | 41 +++++++++++++++++++++++++++++++ src/widgets/mailcow/widget.js | 8 ++++++ src/widgets/widgets.js | 2 ++ 7 files changed, 79 insertions(+) create mode 100644 docs/widgets/services/mailcow.md create mode 100644 src/widgets/mailcow/component.jsx create mode 100644 src/widgets/mailcow/widget.js diff --git a/docs/widgets/services/mailcow.md b/docs/widgets/services/mailcow.md new file mode 100644 index 00000000..3cb2ac18 --- /dev/null +++ b/docs/widgets/services/mailcow.md @@ -0,0 +1,15 @@ +--- +title: Mailcow +description: Mailcow Widget Configuration +--- + +Learn more about [Mailcow](https://github.com/mailcow/mailcow-dockerized). + +Allowed fields: `["domains", "mailboxes", "mails", "storage"]`. + +```yaml +widget: + type: mailcow + url: https://mailcow.host.or.ip + key: mailcowapikey +``` diff --git a/public/locales/de/common.json b/public/locales/de/common.json index a2cafb84..c202b7d7 100644 --- a/public/locales/de/common.json +++ b/public/locales/de/common.json @@ -252,6 +252,12 @@ "queued": "In Warteschlange", "artists": "Künstler" }, + "mailcow": { + "domains": "Domänen", + "mailboxes": "E-Mail-Postfächer", + "mails": "E-Mails", + "storage": "Speicher" + }, "readarr": { "wanted": "Gesucht", "queued": "In Warteschlange", diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 3e582a4d..53da9ab7 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -252,6 +252,12 @@ "queued": "Queued", "artists": "Artists" }, + "mailcow": { + "domains": "Domains", + "mailboxes": "Mailboxes", + "mails": "Mails", + "storage": "Storage" + }, "readarr": { "wanted": "Wanted", "queued": "Queued", diff --git a/src/widgets/components.js b/src/widgets/components.js index 36b9de07..181a4a8a 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -53,6 +53,7 @@ const components = { komga: dynamic(() => import("./komga/component")), kopia: dynamic(() => import("./kopia/component")), lidarr: dynamic(() => import("./lidarr/component")), + mailcow: dynamic(() => import("./mailcow/component")), mastodon: dynamic(() => import("./mastodon/component")), mealie: dynamic(() => import("./mealie/component")), medusa: dynamic(() => import("./medusa/component")), diff --git a/src/widgets/mailcow/component.jsx b/src/widgets/mailcow/component.jsx new file mode 100644 index 00000000..686671d2 --- /dev/null +++ b/src/widgets/mailcow/component.jsx @@ -0,0 +1,41 @@ +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: resultData, error: resultError } = useWidgetAPI(widget, "result"); + + if (resultError) { + return ; + } + + if (!resultData) { + return ( + + , + + + + + ); + } + + const domains = resultData.length; + const mailboxes = resultData.reduce((acc, val) => acc + val.mboxes_in_domain, 0); + const mails = resultData.reduce((acc, val) => acc + val.msgs_total, 0); + const storage = resultData.reduce((acc, val) => acc + val.bytes_total, 0); + + return ( + + + + + + + ); +} diff --git a/src/widgets/mailcow/widget.js b/src/widgets/mailcow/widget.js new file mode 100644 index 00000000..00724499 --- /dev/null +++ b/src/widgets/mailcow/widget.js @@ -0,0 +1,8 @@ +import credentialedProxyHandler from "../../utils/proxy/handlers/credentialed"; + +const widget = { + api: "{url}/api/v1/get/domain/all", + proxyHandler: credentialedProxyHandler, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 950954b0..94a85f17 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -45,6 +45,7 @@ import kavita from "./kavita/widget"; import komga from "./komga/widget"; import kopia from "./kopia/widget"; import lidarr from "./lidarr/widget"; +import mailcow from "./mailcow/widget"; import mastodon from "./mastodon/widget"; import mealie from "./mealie/widget"; import medusa from "./medusa/widget"; @@ -163,6 +164,7 @@ const widgets = { komga, kopia, lidarr, + mailcow, mastodon, mealie, medusa,