From 33073b08a69f01d34f179819e3243bf2dbdff0f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gromos=C5=82aw=20Kroczka?= Date: Mon, 15 May 2023 20:14:53 +0200 Subject: [PATCH] add github widget --- src/utils/proxy/handlers/credentialed.js | 2 ++ src/widgets/components.js | 1 + src/widgets/github/component.jsx | 30 ++++++++++++++++++++++++ src/widgets/github/widget.js | 8 +++++++ src/widgets/widgets.js | 2 ++ 5 files changed, 43 insertions(+) create mode 100644 src/widgets/github/component.jsx create mode 100644 src/widgets/github/widget.js diff --git a/src/utils/proxy/handlers/credentialed.js b/src/utils/proxy/handlers/credentialed.js index 5d4b7e3b..85a10397 100644 --- a/src/utils/proxy/handlers/credentialed.js +++ b/src/utils/proxy/handlers/credentialed.js @@ -55,6 +55,8 @@ export default async function credentialedProxyHandler(req, res, map) { } else { headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`; } + } else if (widget.type === "github") { + headers["User-Agent"] = `homepage`; } else { headers["X-API-Key"] = `${widget.key}`; } diff --git a/src/widgets/components.js b/src/widgets/components.js index 754898bf..d51d6785 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -20,6 +20,7 @@ const components = { flood: dynamic(() => import("./flood/component")), freshrss: dynamic(() => import("./freshrss/component")), ghostfolio: dynamic(() => import("./ghostfolio/component")), + github: dynamic(() => import("./github/component")), gluetun: dynamic(() => import("./gluetun/component")), gotify: dynamic(() => import("./gotify/component")), grafana: dynamic(() => import("./grafana/component")), diff --git a/src/widgets/github/component.jsx b/src/widgets/github/component.jsx new file mode 100644 index 00000000..8fc28be6 --- /dev/null +++ b/src/widgets/github/component.jsx @@ -0,0 +1,30 @@ +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 { widget } = service; + + const { data: githubData, error: githubError } = useWidgetAPI(widget); + + if (githubError) { + return ; + } + + if (!githubData) { + return ( + + + + + ); + } + + return ( + + + + + ); +} diff --git a/src/widgets/github/widget.js b/src/widgets/github/widget.js new file mode 100644 index 00000000..02eaea1e --- /dev/null +++ b/src/widgets/github/widget.js @@ -0,0 +1,8 @@ +import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; + +const widget = { + api: "https://api.github.com/repos/{owner}/{repo}", + proxyHandler: credentialedProxyHandler, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index f7b07a96..6035c15d 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -15,6 +15,7 @@ import fileflows from "./fileflows/widget"; import flood from "./flood/widget"; import freshrss from "./freshrss/widget"; import ghostfolio from "./ghostfolio/widget"; +import github from "./github/widget"; import gluetun from "./gluetun/widget"; import gotify from "./gotify/widget"; import grafana from "./grafana/widget"; @@ -99,6 +100,7 @@ const widgets = { flood, freshrss, ghostfolio, + github, gluetun, gotify, grafana,