changing endpoints and using json functions
This commit is contained in:
parent
78cc8152df
commit
dfbdf2ff25
@ -19,7 +19,6 @@ 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",
|
||||
@ -47,9 +46,6 @@ 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}`;
|
||||
}
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
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");
|
||||
@ -18,18 +20,18 @@ export default function Component({ service }) {
|
||||
if (!libraryError || !seriesError || !bookError) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="libraries" />
|
||||
<Block label="series" />
|
||||
<Block label="books" />
|
||||
<Block label="komga.libraries" />
|
||||
<Block label="komga.series" />
|
||||
<Block label="komga.books" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="libraries" value={parseInt(libraryData.measurements.value, 10) } />
|
||||
<Block label="series" value={parseInt(seriesData.measurements.value, 10) } />
|
||||
<Block label="books" value={parseInt(bookData.measurements.value, 10) } />
|
||||
<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>
|
||||
);
|
||||
}
|
||||
@ -1,18 +1,28 @@
|
||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||
import { jsonArrayFilter } from "utils/proxy/api-helpers";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/actuator/metrics/{endpoint}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
api: "{url}/api/v1/{endpoint}",
|
||||
proxyHandler: genericProxyHandler,
|
||||
|
||||
mappings: {
|
||||
"libraries": {
|
||||
endpoint: "komga.libraries"
|
||||
libraries: {
|
||||
endpoint: "libraries",
|
||||
map: (data) => ({
|
||||
total: jsonArrayFilter(data, (item) => !item.unavailable).length,
|
||||
}),
|
||||
},
|
||||
"series": {
|
||||
endpoint: "komga.series"
|
||||
series: {
|
||||
endpoint: "series",
|
||||
validate: [
|
||||
"totalElements"
|
||||
]
|
||||
},
|
||||
"books": {
|
||||
endpoint: "komga.books"
|
||||
books: {
|
||||
endpoint: "books",
|
||||
validate: [
|
||||
"totalElements"
|
||||
]
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user