Add Gitea widget
This commit is contained in:
parent
42e8d1bd21
commit
1d3aba973e
@ -620,5 +620,10 @@
|
|||||||
"movies": "Movies",
|
"movies": "Movies",
|
||||||
"ovas": "OVAs",
|
"ovas": "OVAs",
|
||||||
"others": "Others"
|
"others": "Others"
|
||||||
|
},
|
||||||
|
"gitea": {
|
||||||
|
"repos": "Repositories",
|
||||||
|
"users": "Users",
|
||||||
|
"orgs": "Organizations"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ const components = {
|
|||||||
flood: dynamic(() => import("./flood/component")),
|
flood: dynamic(() => import("./flood/component")),
|
||||||
freshrss: dynamic(() => import("./freshrss/component")),
|
freshrss: dynamic(() => import("./freshrss/component")),
|
||||||
ghostfolio: dynamic(() => import("./ghostfolio/component")),
|
ghostfolio: dynamic(() => import("./ghostfolio/component")),
|
||||||
|
gitea: dynamic(() => import("./gitea/component")),
|
||||||
gluetun: dynamic(() => import("./gluetun/component")),
|
gluetun: dynamic(() => import("./gluetun/component")),
|
||||||
gotify: dynamic(() => import("./gotify/component")),
|
gotify: dynamic(() => import("./gotify/component")),
|
||||||
grafana: dynamic(() => import("./grafana/component")),
|
grafana: dynamic(() => import("./grafana/component")),
|
||||||
|
|||||||
35
src/widgets/gitea/component.jsx
Normal file
35
src/widgets/gitea/component.jsx
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
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: giteaData, error: giteaError } = useWidgetAPI(widget);
|
||||||
|
|
||||||
|
if (giteaError) {
|
||||||
|
return <Container service={service} error={giteaError} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!giteaData) {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="gitea.repos" />
|
||||||
|
<Block label="gitea.users" />
|
||||||
|
<Block label="gitea.orgs" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="gitea.repos" value={t("common.number", { value: giteaData.repos })} />
|
||||||
|
<Block label="gitea.users" value={t("common.number", { value: giteaData.users })} />
|
||||||
|
<Block label="gitea.orgs" value={t("common.number", { value: giteaData.orgs })} />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
48
src/widgets/gitea/proxy.js
Normal file
48
src/widgets/gitea/proxy.js
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import { httpProxy } from "utils/proxy/http";
|
||||||
|
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||||
|
import getServiceWidget from "utils/config/service-helpers";
|
||||||
|
import createLogger from "utils/logger";
|
||||||
|
import widgets from "widgets/widgets";
|
||||||
|
|
||||||
|
const proxyName = "giteaProxyHandler";
|
||||||
|
const logger = createLogger(proxyName);
|
||||||
|
|
||||||
|
async function apiCall(widget, endpoint) {
|
||||||
|
const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...widget }));
|
||||||
|
const params = { method: "GET", headers: { Authorization: `token ${widget.token}` } };
|
||||||
|
|
||||||
|
const [status, contentType, data, responseHeaders] = await httpProxy(url, params);
|
||||||
|
|
||||||
|
if (status !== 200) {
|
||||||
|
logger.error("Error getting data from Gitea: %s status %d. Data: %s", url, status, data);
|
||||||
|
return { status, contentType, data: null, responseHeaders };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { status, contentType, data: JSON.parse(data.toString()), responseHeaders };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function giteaProxyHandler(req, res) {
|
||||||
|
const { group, service } = req.query;
|
||||||
|
|
||||||
|
if (!group || !service) {
|
||||||
|
logger.debug("Invalid or missing service '%s' or group '%s'", service, group);
|
||||||
|
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||||
|
}
|
||||||
|
|
||||||
|
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 { responseHeaders: reposHeaders } = await apiCall(widget, "repos/search");
|
||||||
|
const { responseHeaders: usersHeaders } = await apiCall(widget, "admin/users");
|
||||||
|
const { responseHeaders: orgsHeaders } = await apiCall(widget, "admin/orgs");
|
||||||
|
|
||||||
|
return res.status(200).send({
|
||||||
|
repos: reposHeaders["x-total-count"],
|
||||||
|
users: usersHeaders["x-total-count"],
|
||||||
|
orgs: orgsHeaders["x-total-count"],
|
||||||
|
});
|
||||||
|
}
|
||||||
8
src/widgets/gitea/widget.js
Normal file
8
src/widgets/gitea/widget.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import giteaProxyHandler from "./proxy";
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
api: "{url}/api/v1/{endpoint}",
|
||||||
|
proxyHandler: giteaProxyHandler,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default widget;
|
||||||
@ -15,6 +15,7 @@ import fileflows from "./fileflows/widget";
|
|||||||
import flood from "./flood/widget";
|
import flood from "./flood/widget";
|
||||||
import freshrss from "./freshrss/widget";
|
import freshrss from "./freshrss/widget";
|
||||||
import ghostfolio from "./ghostfolio/widget";
|
import ghostfolio from "./ghostfolio/widget";
|
||||||
|
import gitea from "./gitea/widget";
|
||||||
import gluetun from "./gluetun/widget";
|
import gluetun from "./gluetun/widget";
|
||||||
import gotify from "./gotify/widget";
|
import gotify from "./gotify/widget";
|
||||||
import grafana from "./grafana/widget";
|
import grafana from "./grafana/widget";
|
||||||
@ -99,6 +100,7 @@ const widgets = {
|
|||||||
flood,
|
flood,
|
||||||
freshrss,
|
freshrss,
|
||||||
ghostfolio,
|
ghostfolio,
|
||||||
|
gitea,
|
||||||
gluetun,
|
gluetun,
|
||||||
gotify,
|
gotify,
|
||||||
grafana,
|
grafana,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user