adding Komga

This commit is contained in:
KillahBee 2023-01-31 17:46:26 -05:00
parent b1fbbf2264
commit 8920217411
6 changed files with 68 additions and 0 deletions

View File

@ -447,5 +447,11 @@
"photos": "Photos",
"videos": "Videos",
"storage": "Storage"
},
"komga": {
"users": "Users",
"libraries": "Libraries",
"series": "Series",
"books": "Books"
}
}

View File

@ -19,6 +19,7 @@ export default async function credentialedProxyHandler(req, res, map) {
if (widget) {
const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...widget }));
const version = process.env.NEXT_PUBLIC_VERSION?.length ? process.env.NEXT_PUBLIC_VERSION : "dev";
const headers = {
"Content-Type": "application/json",
@ -46,6 +47,9 @@ export default async function credentialedProxyHandler(req, res, map) {
} else if (widget.type === "cloudflared") {
headers["X-Auth-Email"] = `${widget.email}`;
headers["X-Auth-Key"] = `${widget.key}`;
} else if (widget.type === "komga") {
headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`
headers["User-Agent"] = `HomepageRuntime/${version} `
} else {
headers["X-API-Key"] = `${widget.key}`;
}

View File

@ -21,6 +21,7 @@ const components = {
jackett: dynamic(() => import("./jackett/component")),
jellyfin: dynamic(() => import("./emby/component")),
jellyseerr: dynamic(() => import("./jellyseerr/component")),
komga: dynamic(() => import("./komga/component")),
lidarr: dynamic(() => import("./lidarr/component")),
mastodon: dynamic(() => import("./mastodon/component")),
medusa: dynamic(() => import("./medusa/component")),

View File

@ -0,0 +1,35 @@
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: libraryData, error: libraryError } = useWidgetAPI(widget, "komga.libraries");
const { data: seriesData, error: seriesError } = useWidgetAPI(widget, "komga.series");
const { data: bookData, error: bookError } = useWidgetAPI(widget, "komga.books");
if (libraryError || seriesError || bookError) {
const finalError = libraryError ?? seriesError ?? bookError;
return <Container error={finalError} />;
}
if (!libraryError || !seriesError || !bookError) {
return (
<Container service={service}>
<Block label="komga.libraries" />
<Block label="komga.series" />
<Block label="komga.books" />
</Container>
);
}
return (
<Container service={service}>
<Block label="komga.libraries" value={parseInt(libraryData.measurements.value, 10) } />
<Block label="komga.series" value={parseInt(seriesData.measurements.value, 10) } />
<Block label="komga.books" value={parseInt(bookData.measurements.value, 10) } />
</Container>
);
}

View File

@ -0,0 +1,20 @@
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
const widget = {
api: "{url}/actuator/metrics/{endpoint}",
proxyHandler: credentialedProxyHandler,
mappings: {
"komga.libraries": {
endpoint: "komga.libraries"
},
"komga.series": {
endpoint: "komga.series"
},
"komga.books": {
endpoint: "komga.books"
},
},
};
export default widget;

View File

@ -15,6 +15,7 @@ import hdhomerun from "./hdhomerun/widget";
import homebridge from "./homebridge/widget";
import jackett from "./jackett/widget";
import jellyseerr from "./jellyseerr/widget";
import komga from "./komga/widget";
import lidarr from "./lidarr/widget";
import mastodon from "./mastodon/widget";
import medusa from "./medusa/widget";
@ -78,6 +79,7 @@ const widgets = {
jackett,
jellyfin: emby,
jellyseerr,
komga,
lidarr,
mastodon,
medusa,