From 147a165bbcc28bdb50b0f3842a717e4a4dd626c3 Mon Sep 17 00:00:00 2001 From: Lukas Holota Date: Tue, 31 Jan 2023 13:51:44 +0100 Subject: [PATCH 01/10] Allow Custom CSS --- src/pages/_app.jsx | 1 + src/styles/custom.css | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 src/styles/custom.css diff --git a/src/pages/_app.jsx b/src/pages/_app.jsx index e99303ab..e304ccae 100644 --- a/src/pages/_app.jsx +++ b/src/pages/_app.jsx @@ -6,6 +6,7 @@ import Head from "next/head"; import "styles/globals.css"; import "styles/theme.css"; import "styles/manrope.css"; +import "styles/custom.css"; import nextI18nextConfig from "../../next-i18next.config"; import { ColorProvider } from "utils/contexts/color"; diff --git a/src/styles/custom.css b/src/styles/custom.css new file mode 100644 index 00000000..cbc9cf6a --- /dev/null +++ b/src/styles/custom.css @@ -0,0 +1,3 @@ +/* +Mount this file and define your custom styles +*/ \ No newline at end of file From 49d2dabe5335301df598ed784ab43cb5bdd8d014 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 31 Jan 2023 16:09:16 +0000 Subject: [PATCH 02/10] Bump docker/build-push-action from 3 to 4 Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 3 to 4. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v3...v4) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index bacc1fa7..bd80a153 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -88,7 +88,7 @@ jobs: # https://github.com/docker/build-push-action - name: Build and push Docker image id: build-and-push - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v4 with: context: . push: ${{ github.event_name != 'pull_request' }} From 224d5da982b79a3e61e0fe1baed483dc35436313 Mon Sep 17 00:00:00 2001 From: gallegonovato Date: Tue, 31 Jan 2023 12:28:37 +0000 Subject: [PATCH 03/10] Translated using Weblate (Spanish) Currently translated at 100.0% (311 of 311 strings) Translation: Homepage/Homepage Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/es/ --- public/locales/es/common.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/locales/es/common.json b/public/locales/es/common.json index d0540c10..d2db4ce5 100644 --- a/public/locales/es/common.json +++ b/public/locales/es/common.json @@ -280,8 +280,8 @@ "quicklaunch": { "bookmark": "Marcadores", "service": "Servicio", - "search": "Search", - "custom": "Custom" + "search": "Buscar", + "custom": "Personalizado" }, "homebridge": { "available_update": "Sistema", @@ -434,9 +434,9 @@ "memory_usage": "Memoria" }, "immich": { - "users": "Users", - "photos": "Photos", - "videos": "Videos", - "storage": "Storage" + "users": "Usuarios", + "photos": "Fotos", + "videos": "Vídeos", + "storage": "Almacenamiento" } } From dfc787b0045595b244d6099cf34517f631418a56 Mon Sep 17 00:00:00 2001 From: Nonoss117 Date: Tue, 31 Jan 2023 17:56:48 +0000 Subject: [PATCH 04/10] Translated using Weblate (French) Currently translated at 100.0% (311 of 311 strings) Translation: Homepage/Homepage Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/fr/ --- public/locales/fr/common.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/locales/fr/common.json b/public/locales/fr/common.json index 8384535c..ae4f28fe 100644 --- a/public/locales/fr/common.json +++ b/public/locales/fr/common.json @@ -280,8 +280,8 @@ "quicklaunch": { "bookmark": "Signet", "service": "Service", - "search": "Search", - "custom": "Custom" + "search": "Recherche", + "custom": "Personnalisé" }, "homebridge": { "available_update": "Système", From fb1e11b6cbe69ca2e887fec894147bada54e209f Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 31 Jan 2023 22:53:25 +0000 Subject: [PATCH 05/10] Translated using Weblate (Ukrainian) Currently translated at 100.0% (311 of 311 strings) Translation: Homepage/Homepage Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/uk/ --- public/locales/uk/common.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/public/locales/uk/common.json b/public/locales/uk/common.json index b22fed8a..81219c0b 100644 --- a/public/locales/uk/common.json +++ b/public/locales/uk/common.json @@ -342,8 +342,8 @@ "quicklaunch": { "bookmark": "Закладка", "service": "Сервіс", - "search": "Search", - "custom": "Custom" + "search": "Пошук", + "custom": "Користувацький" }, "homebridge": { "available_update": "Система", @@ -428,15 +428,15 @@ "status": "Стан" }, "proxmoxbackupserver": { - "datastore_usage": "Datastore", - "failed_tasks_24h": "Failed Tasks 24h", + "datastore_usage": "Сховище даних", + "failed_tasks_24h": "Невиконані завдання 24 години", "cpu_usage": "CPU", - "memory_usage": "Memory" + "memory_usage": "Пам'ять" }, "immich": { - "users": "Users", - "photos": "Photos", - "videos": "Videos", - "storage": "Storage" + "users": "Користувачі", + "photos": "Фотографії", + "videos": "Відео", + "storage": "Сховище" } } From 41a2e5932fadc34c637cc8d93f1d6378ec4c0885 Mon Sep 17 00:00:00 2001 From: Mateus Date: Wed, 1 Feb 2023 04:07:38 +0000 Subject: [PATCH 06/10] Translated using Weblate (Portuguese (Brazil)) Currently translated at 55.6% (173 of 311 strings) Translation: Homepage/Homepage Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/pt_BR/ --- public/locales/pt-BR/common.json | 102 +++++++++++++++---------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/public/locales/pt-BR/common.json b/public/locales/pt-BR/common.json index e20ebf03..90d2e298 100644 --- a/public/locales/pt-BR/common.json +++ b/public/locales/pt-BR/common.json @@ -31,10 +31,10 @@ "missing_type": "Tipo de Widget ausente: {{type}}", "api_error": "Erro da API", "status": "Status", - "information": "Information", + "information": "Informação", "url": "URL", "raw_error": "Raw Error", - "response_data": "Response Data" + "response_data": "Dados de Resposta" }, "weather": { "current": "Localização atual", @@ -53,13 +53,13 @@ "cpu": "CPU" }, "docker": { - "rx": "Rx", - "tx": "Tx", - "mem": "Mem", + "rx": "Recebido", + "tx": "Transmitido", + "mem": "Memória", "cpu": "CPU", "offline": "Desligado", - "error": "Error", - "unknown": "Unknown" + "error": "Erro", + "unknown": "Desconhecido" }, "emby": { "playing": "Reproduzindo", @@ -99,7 +99,7 @@ "wanted": "Desejado", "queued": "Na fila", "movies": "Filmes", - "missing": "Missing" + "missing": "Faltando" }, "lidarr": { "wanted": "Desejado", @@ -129,7 +129,7 @@ "pending": "Pendente", "approved": "Aprovado", "available": "Disponível", - "processing": "Processing" + "processing": "Processando" }, "pihole": { "queries": "Consultas", @@ -148,9 +148,9 @@ "ping": "Ping" }, "traefik": { - "routers": "Rotas", + "routers": "Roteadores", "services": "Serviços", - "middleware": "Middleware" + "middleware": "Software intermediario" }, "npm": { "enabled": "Habilitado", @@ -164,10 +164,10 @@ }, "prowlarr": { "enableIndexers": "Indexadores", - "numberOfGrabs": "Grabs", - "numberOfQueries": "Queries", + "numberOfGrabs": "Pegos", + "numberOfQueries": "Consultas", "numberOfFailGrabs": "Fail Grabs", - "numberOfFailQueries": "Fail Queries" + "numberOfFailQueries": "Consultas Falhas" }, "jackett": { "configured": "Configurado", @@ -179,36 +179,36 @@ "domain_count": "Domínios" }, "authentik": { - "users": "Users", + "users": "Usuários", "loginsLast24H": "Logins (24h)", "failedLoginsLast24H": "Failed Logins (24h)" }, "proxmox": { - "mem": "MEM", - "cpu": "CPU", + "mem": "Memória", + "cpu": "Processador", "lxc": "LXC", "vms": "VMs" }, "unifi": { - "users": "Users", - "uptime": "System Uptime", - "days": "Days", + "users": "Usuários", + "uptime": "Tempo de Funcionamento", + "days": "Dias", "wan": "WAN", - "lan_users": "LAN Users", - "wlan_users": "WLAN Users", - "up": "UP", - "down": "DOWN", - "wait": "Please wait", + "lan_users": "Usuarios locais", + "wlan_users": "Usuarios WLAN", + "up": "LIGADO", + "down": "CÁIDO", + "wait": "Por favor guarde", "lan": "LAN", "wlan": "WLAN", - "devices": "Devices", - "lan_devices": "LAN Devices", - "wlan_devices": "WLAN Devices" + "devices": "Dispositivos", + "lan_devices": "Dispositivos LAN", + "wlan_devices": "Dispositivos WLAN" }, "plex": { - "streams": "Active Streams", - "movies": "Movies", - "tv": "TV Shows" + "streams": "Transmissões ativas", + "movies": "Filmes", + "tv": "Séries de TV" }, "glances": { "cpu": "CPU", @@ -222,10 +222,10 @@ "wmo": { "1-night": "Mainly Clear", "2-day": "Partly Cloudy", - "2-night": "Partly Cloudy", - "3-day": "Cloudy", - "3-night": "Cloudy", - "45-day": "Foggy", + "2-night": "Parcialmente nublado", + "3-day": "Nublado", + "3-night": "Nublado", + "45-day": "Névoa", "45-night": "Foggy", "48-day": "Foggy", "48-night": "Foggy", @@ -233,9 +233,9 @@ "57-day": "Freezing Drizzle", "99-day": "Thunderstorm With Hail", "99-night": "Thunderstorm With Hail", - "0-day": "Sunny", + "0-day": "Ensolarado", "53-day": "Drizzle", - "0-night": "Clear", + "0-night": "Limpo", "1-day": "Mainly Sunny", "51-day": "Light Drizzle", "51-night": "Light Drizzle", @@ -315,8 +315,8 @@ "time": "{{value, number(style: unit; unitDisplay: long;)}}" }, "navidrome": { - "nothing_streaming": "No Active Streams", - "please_wait": "Please Wait" + "nothing_streaming": "Sem transmissões ativas", + "please_wait": "Por favor aguarde" }, "pyload": { "speed": "Speed", @@ -334,7 +334,7 @@ "hd": "HD" }, "ping": { - "error": "Error", + "error": "Erro", "ping": "Ping" }, "scrutiny": { @@ -359,14 +359,14 @@ "seed": "Seed" }, "tdarr": { - "queue": "Queue", - "processed": "Processed", - "errored": "Errored", - "saved": "Saved" + "queue": "Fila", + "processed": "Processado", + "errored": "Erro", + "saved": "Salvo" }, "miniflux": { - "read": "Read", - "unread": "Unread" + "read": "Lidos", + "unread": "Não Lidos" }, "nextdns": { "wait": "Please Wait", @@ -377,11 +377,11 @@ "bibitrate": "{{value, rate(bits: true; binary: true)}}" }, "omada": { - "connectedAp": "Connected APs", - "activeUser": "Active devices", - "alerts": "Alerts", - "connectedGateway": "Connected gateways", - "connectedSwitches": "Connected switches" + "connectedAp": "Pontos de acesso conectados", + "activeUser": "Dispositivos ativos", + "alerts": "Alertas", + "connectedGateway": "Gateways conectados", + "connectedSwitches": "Interruptores conectados" }, "downloadstation": { "download": "Download", From ff27b1ef510e07a7a866c3a2815a430cef588aaf Mon Sep 17 00:00:00 2001 From: Ean McLaughlin Date: Wed, 1 Feb 2023 15:32:10 -0700 Subject: [PATCH 07/10] Show container status if health is an empty string If data.health is an empty string, ?? will accept it and not use the right side value; instead, we should use || which treats empty string as false and returns the right side value. This will show "RUNNING" in the status box if health is "". --- src/components/services/status.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/services/status.jsx b/src/components/services/status.jsx index eaf32030..81d48589 100644 --- a/src/components/services/status.jsx +++ b/src/components/services/status.jsx @@ -30,8 +30,8 @@ export default function Status({ service }) { } return ( -
-
{data.health ?? data.status}
+
+
{data.health || data.status}
); } From 167f3a4f84557ffd1d0f672f2223eacce3e690e1 Mon Sep 17 00:00:00 2001 From: hymbz Date: Thu, 2 Feb 2023 03:38:47 +0000 Subject: [PATCH 08/10] Translated using Weblate (Chinese (Simplified)) Currently translated at 62.3% (194 of 311 strings) Translation: Homepage/Homepage Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/zh_Hans/ --- public/locales/zh-CN/common.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/locales/zh-CN/common.json b/public/locales/zh-CN/common.json index d98ce40f..408dc9c6 100644 --- a/public/locales/zh-CN/common.json +++ b/public/locales/zh-CN/common.json @@ -12,7 +12,7 @@ "placeholder": "搜索…" }, "resources": { - "total": "共", + "total": "总计", "free": "空闲", "used": "已用", "load": "负载", From c3d15a61c3734bec879172c3bedaa26e1000c4fd Mon Sep 17 00:00:00 2001 From: chain710 Date: Wed, 1 Feb 2023 23:22:59 +0800 Subject: [PATCH 09/10] Implement uptime-kuma widget --- public/locales/en/common.json | 10 ++- src/widgets/components.js | 1 + src/widgets/uptimekuma/component.jsx | 45 +++++++++++++ src/widgets/uptimekuma/proxy.js | 95 ++++++++++++++++++++++++++++ src/widgets/uptimekuma/widget.js | 8 +++ src/widgets/widgets.js | 2 + 6 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 src/widgets/uptimekuma/component.jsx create mode 100644 src/widgets/uptimekuma/proxy.js create mode 100644 src/widgets/uptimekuma/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 52db2cb4..b4716368 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -447,5 +447,13 @@ "photos": "Photos", "videos": "Videos", "storage": "Storage" + }, + "uptimekuma": { + "status": "status", + "uptime": "uptime", + "good": "All Systems Operational", + "warn": "Partially Degraded Service", + "bad": "Degraded Service", + "unknown": "Unknown service status" } -} +} \ No newline at end of file diff --git a/src/widgets/components.js b/src/widgets/components.js index 43a46fa9..505807c4 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -63,6 +63,7 @@ const components = { watchtower: dynamic(() => import("./watchtower/component")), xteve: dynamic(() => import("./xteve/component")), immich: dynamic(() => import("./immich/component")), + uptimekuma: dynamic(() => import("./uptimekuma/component")), }; export default components; diff --git a/src/widgets/uptimekuma/component.jsx b/src/widgets/uptimekuma/component.jsx new file mode 100644 index 00000000..dd112db4 --- /dev/null +++ b/src/widgets/uptimekuma/component.jsx @@ -0,0 +1,45 @@ +import { useTranslation } from "next-i18next"; + +import Container from "components/services/widget/container"; +import useWidgetAPI from "utils/proxy/use-widget-api"; +import Block from "components/services/widget/block"; + +const Status = { + good: "uptimekuma.good", + warn: "uptimekuma.warn", + bad: "uptimekuma.bad", + unknown: "uptimekuma.unknown", +}; + +export default function Component({ service }) { + const { t } = useTranslation(); + + const { widget } = service; + + const { data: statusData, error: statusError } = useWidgetAPI(widget); + + if (statusError) { + return ; + } + + if (!statusData) { + return ( + + + + + ); + } + + if (statusData.icon) { + // eslint-disable-next-line no-param-reassign + service.icon = statusData.icon; + } + + return ( + + + + + ); +} diff --git a/src/widgets/uptimekuma/proxy.js b/src/widgets/uptimekuma/proxy.js new file mode 100644 index 00000000..6722de85 --- /dev/null +++ b/src/widgets/uptimekuma/proxy.js @@ -0,0 +1,95 @@ +import { httpProxy } from "utils/proxy/http"; +import getServiceWidget from "utils/config/service-helpers"; +import createLogger from "utils/logger"; + +const logger = createLogger("uptimeKumaProxyHandler"); + +async function getStatus(widget) { + const url = new URL(`${widget.url}/api/status-page/${widget.slug}`).toString(); + logger.debug("get status %s", url); + const params = { method: "GET", headers: {} }; + const [status, , data] = await httpProxy(url, params); + try { + return [status, JSON.parse(data)]; + } catch (e) { + logger.error("Error decoding status data. Data: %s", data.toString()); + return [status, null]; + } +} + +async function getHeartbeat(widget) { + const url = new URL(`${widget.url}/api/status-page/heartbeat/${widget.slug}`).toString(); + logger.debug("get heartbeat %s", url); + const params = { method: "GET", headers: {} }; + const [status, , data] = await httpProxy(url, params); + try { + return [status, JSON.parse(data)]; + } catch (e) { + logger.error("Error decoding heartbeat data. Data: %s", data.toString()); + return [status, null]; + } +} + +function statusMessage(data) { + if (!data || Object.keys(data.heartbeatList) === 0) { + return "unknown"; + } + + let result = "good"; + let hasUp = false; + Object.values(data.heartbeatList).forEach((el) => { + const index = el.length - 1; + if (el[index].status === 1) { + hasUp = true; + } else { + result = "warn"; + } + }); + + if (!hasUp) { + result = "bad"; + } + return result; +} + +function uptime(data) { + if (!data) { + return 0; + } + + const uptimeList = Object.values(data.uptimeList); + const percent = uptimeList.reduce((a, b) => a + b, 0) / uptimeList.length || 0; + return (percent * 100).toFixed(1); +} + +export default async function uptimeKumaProxyHandler(req, res) { + const { group, service } = req.query; + const widget = await getServiceWidget(group, service); + if (!widget) { + logger.debug("Invalid or missing widget for service '%s' in group '%s'", service, group); + return res.status(400).json({ error: "Invalid proxy service type" }); + } + + const [[statusCode, statusData], [heartbeatCode, heartbeatData]] = await Promise.all([ + getStatus(widget), + getHeartbeat(widget), + ]); + + if (statusCode !== 200) { + logger.error("HTTP %d getting status data error. Data: %s", statusCode, statusData); + return res.status(statusCode).send(statusData); + } + + if (heartbeatCode !== 200) { + logger.error("HTTP %d getting heartbeat data error. Data: %s", heartbeatCode, heartbeatData); + return res.status(heartbeatCode).send(heartbeatData); + } + + const icon = statusData?.config ? statusData.config.icon : null; + return res.status(200).send({ + uptime: uptime(heartbeatData), + message: statusMessage(heartbeatData), + incident: statusData?.incident ? statusData.incident.title : "", + icon: `${widget.url}${icon}`, + }); +} diff --git a/src/widgets/uptimekuma/widget.js b/src/widgets/uptimekuma/widget.js new file mode 100644 index 00000000..9687e1a4 --- /dev/null +++ b/src/widgets/uptimekuma/widget.js @@ -0,0 +1,8 @@ +// import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; +import uptimeKumaProxyHandler from "./proxy"; + +const widget = { + proxyHandler: uptimeKumaProxyHandler, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 133903fb..7da77a0a 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -57,6 +57,7 @@ import unifi from "./unifi/widget"; import watchtower from "./watchtower/widget"; import xteve from "./xteve/widget"; import immich from "./immich/widget"; +import uptimekuma from "./uptimekuma/widget"; const widgets = { adguard, @@ -121,6 +122,7 @@ const widgets = { watchtower, xteve, immich, + uptimekuma, }; export default widgets; From 015d7dac52badcb4966076b6c7c0d669c249074b Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 2 Feb 2023 00:28:18 -0800 Subject: [PATCH 10/10] Rework uptime kuma remove proxy display more info --- public/locales/en/common.json | 11 ++-- src/widgets/uptimekuma/component.jsx | 46 ++++++++------ src/widgets/uptimekuma/proxy.js | 95 ---------------------------- src/widgets/uptimekuma/widget.js | 14 +++- 4 files changed, 45 insertions(+), 121 deletions(-) delete mode 100644 src/widgets/uptimekuma/proxy.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index b4716368..f144182f 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -449,11 +449,10 @@ "storage": "Storage" }, "uptimekuma": { - "status": "status", - "uptime": "uptime", - "good": "All Systems Operational", - "warn": "Partially Degraded Service", - "bad": "Degraded Service", - "unknown": "Unknown service status" + "up": "Sites Up", + "down": "Sites Down", + "uptime": "Uptime", + "incident": "Incident", + "m": "m" } } \ No newline at end of file diff --git a/src/widgets/uptimekuma/component.jsx b/src/widgets/uptimekuma/component.jsx index dd112db4..d71f9a63 100644 --- a/src/widgets/uptimekuma/component.jsx +++ b/src/widgets/uptimekuma/component.jsx @@ -4,42 +4,52 @@ import Container from "components/services/widget/container"; import useWidgetAPI from "utils/proxy/use-widget-api"; import Block from "components/services/widget/block"; -const Status = { - good: "uptimekuma.good", - warn: "uptimekuma.warn", - bad: "uptimekuma.bad", - unknown: "uptimekuma.unknown", -}; - export default function Component({ service }) { const { t } = useTranslation(); const { widget } = service; - const { data: statusData, error: statusError } = useWidgetAPI(widget); + const { data: statusData, error: statusError } = useWidgetAPI(widget, "status_page"); + const { data: heartbeatData, error: heartbeatError } = useWidgetAPI(widget, "heartbeat"); - if (statusError) { - return ; + if (statusError || heartbeatError) { + return ; } - if (!statusData) { + if (!statusData || !heartbeatData) { return ( - + + + ); } - if (statusData.icon) { - // eslint-disable-next-line no-param-reassign - service.icon = statusData.icon; - } + let sitesUp = 0; + let sitesDown = 0; + Object.values(heartbeatData.heartbeatList).forEach((siteList) => { + const lastHeartbeat = siteList[siteList.length - 1]; + if (lastHeartbeat?.status === 1) { + sitesUp += 1; + } else { + sitesDown += 1; + } + }); + + // Adapted from https://github.com/bastienwirtz/homer/blob/b7cd8f9482e6836a96b354b11595b03b9c3d67cd/src/components/services/UptimeKuma.vue#L105 + const uptimeList = Object.values(heartbeatData.uptimeList); + const percent = uptimeList.reduce((a, b) => a + b, 0) / uptimeList.length || 0; + const uptime = (percent * 100).toFixed(1); + const incidentTime = statusData.incident ? (Math.abs(new Date(statusData.incident?.createdDate) - new Date()) / 1000) / (60 * 60) : null; return ( - - + + + + {incidentTime && } ); } diff --git a/src/widgets/uptimekuma/proxy.js b/src/widgets/uptimekuma/proxy.js deleted file mode 100644 index 6722de85..00000000 --- a/src/widgets/uptimekuma/proxy.js +++ /dev/null @@ -1,95 +0,0 @@ -import { httpProxy } from "utils/proxy/http"; -import getServiceWidget from "utils/config/service-helpers"; -import createLogger from "utils/logger"; - -const logger = createLogger("uptimeKumaProxyHandler"); - -async function getStatus(widget) { - const url = new URL(`${widget.url}/api/status-page/${widget.slug}`).toString(); - logger.debug("get status %s", url); - const params = { method: "GET", headers: {} }; - const [status, , data] = await httpProxy(url, params); - try { - return [status, JSON.parse(data)]; - } catch (e) { - logger.error("Error decoding status data. Data: %s", data.toString()); - return [status, null]; - } -} - -async function getHeartbeat(widget) { - const url = new URL(`${widget.url}/api/status-page/heartbeat/${widget.slug}`).toString(); - logger.debug("get heartbeat %s", url); - const params = { method: "GET", headers: {} }; - const [status, , data] = await httpProxy(url, params); - try { - return [status, JSON.parse(data)]; - } catch (e) { - logger.error("Error decoding heartbeat data. Data: %s", data.toString()); - return [status, null]; - } -} - -function statusMessage(data) { - if (!data || Object.keys(data.heartbeatList) === 0) { - return "unknown"; - } - - let result = "good"; - let hasUp = false; - Object.values(data.heartbeatList).forEach((el) => { - const index = el.length - 1; - if (el[index].status === 1) { - hasUp = true; - } else { - result = "warn"; - } - }); - - if (!hasUp) { - result = "bad"; - } - return result; -} - -function uptime(data) { - if (!data) { - return 0; - } - - const uptimeList = Object.values(data.uptimeList); - const percent = uptimeList.reduce((a, b) => a + b, 0) / uptimeList.length || 0; - return (percent * 100).toFixed(1); -} - -export default async function uptimeKumaProxyHandler(req, res) { - const { group, service } = req.query; - const widget = await getServiceWidget(group, service); - if (!widget) { - logger.debug("Invalid or missing widget for service '%s' in group '%s'", service, group); - return res.status(400).json({ error: "Invalid proxy service type" }); - } - - const [[statusCode, statusData], [heartbeatCode, heartbeatData]] = await Promise.all([ - getStatus(widget), - getHeartbeat(widget), - ]); - - if (statusCode !== 200) { - logger.error("HTTP %d getting status data error. Data: %s", statusCode, statusData); - return res.status(statusCode).send(statusData); - } - - if (heartbeatCode !== 200) { - logger.error("HTTP %d getting heartbeat data error. Data: %s", heartbeatCode, heartbeatData); - return res.status(heartbeatCode).send(heartbeatData); - } - - const icon = statusData?.config ? statusData.config.icon : null; - return res.status(200).send({ - uptime: uptime(heartbeatData), - message: statusMessage(heartbeatData), - incident: statusData?.incident ? statusData.incident.title : "", - icon: `${widget.url}${icon}`, - }); -} diff --git a/src/widgets/uptimekuma/widget.js b/src/widgets/uptimekuma/widget.js index 9687e1a4..928534b3 100644 --- a/src/widgets/uptimekuma/widget.js +++ b/src/widgets/uptimekuma/widget.js @@ -1,8 +1,18 @@ // import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; -import uptimeKumaProxyHandler from "./proxy"; +import genericProxyHandler from "utils/proxy/handlers/generic"; const widget = { - proxyHandler: uptimeKumaProxyHandler, + api: "{url}/api/{endpoint}/{slug}", + proxyHandler: genericProxyHandler, + + mappings: { + status_page: { + endpoint: "status-page", + }, + heartbeat: { + endpoint: "status-page/heartbeat", + }, + } }; export default widget;