Komga Widget (#922)

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
pull/934/head
Bryan 2 years ago committed by GitHub
parent aee8ba1e1d
commit f851085ebf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -454,5 +454,10 @@
"uptime": "Uptime",
"incident": "Incident",
"m": "m"
},
"komga": {
"libraries": "Libraries",
"series": "Series",
"books": "Books"
}
}

@ -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")),

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

@ -0,0 +1,30 @@
import genericProxyHandler from "utils/proxy/handlers/generic";
import { jsonArrayFilter } from "utils/proxy/api-helpers";
const widget = {
api: "{url}/api/v1/{endpoint}",
proxyHandler: genericProxyHandler,
mappings: {
libraries: {
endpoint: "libraries",
map: (data) => ({
total: jsonArrayFilter(data, (item) => !item.unavailable).length,
}),
},
series: {
endpoint: "series",
validate: [
"totalElements"
]
},
books: {
endpoint: "books",
validate: [
"totalElements"
]
},
},
};
export default widget;

@ -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";
@ -79,6 +80,7 @@ const widgets = {
jackett,
jellyfin: emby,
jellyseerr,
komga,
lidarr,
mastodon,
medusa,

Loading…
Cancel
Save