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) {
|
if (widget) {
|
||||||
const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...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 = {
|
const headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@ -47,9 +46,6 @@ export default async function credentialedProxyHandler(req, res, map) {
|
|||||||
} else if (widget.type === "cloudflared") {
|
} else if (widget.type === "cloudflared") {
|
||||||
headers["X-Auth-Email"] = `${widget.email}`;
|
headers["X-Auth-Email"] = `${widget.email}`;
|
||||||
headers["X-Auth-Key"] = `${widget.key}`;
|
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 {
|
} else {
|
||||||
headers["X-API-Key"] = `${widget.key}`;
|
headers["X-API-Key"] = `${widget.key}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
import Container from "components/services/widget/container";
|
import Container from "components/services/widget/container";
|
||||||
import Block from "components/services/widget/block";
|
import Block from "components/services/widget/block";
|
||||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
|
|
||||||
export default function Component({ service }) {
|
export default function Component({ service }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
const { widget } = service;
|
const { widget } = service;
|
||||||
|
|
||||||
const { data: libraryData, error: libraryError } = useWidgetAPI(widget, "libraries");
|
const { data: libraryData, error: libraryError } = useWidgetAPI(widget, "libraries");
|
||||||
@ -18,18 +20,18 @@ export default function Component({ service }) {
|
|||||||
if (!libraryError || !seriesError || !bookError) {
|
if (!libraryError || !seriesError || !bookError) {
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="libraries" />
|
<Block label="komga.libraries" />
|
||||||
<Block label="series" />
|
<Block label="komga.series" />
|
||||||
<Block label="books" />
|
<Block label="komga.books" />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="libraries" value={parseInt(libraryData.measurements.value, 10) } />
|
<Block label="komga.libraries" value={t("common.number", { value: libraryData.total })} />
|
||||||
<Block label="series" value={parseInt(seriesData.measurements.value, 10) } />
|
<Block label="komga.series" value={t("common.number", { value: seriesData.totalElements })} />
|
||||||
<Block label="books" value={parseInt(bookData.measurements.value, 10) } />
|
<Block label="komga.books" value={t("common.number", { value: bookData.totalElements })} />
|
||||||
</Container>
|
</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 = {
|
const widget = {
|
||||||
api: "{url}/actuator/metrics/{endpoint}",
|
api: "{url}/api/v1/{endpoint}",
|
||||||
proxyHandler: credentialedProxyHandler,
|
proxyHandler: genericProxyHandler,
|
||||||
|
|
||||||
mappings: {
|
mappings: {
|
||||||
"libraries": {
|
libraries: {
|
||||||
endpoint: "komga.libraries"
|
endpoint: "libraries",
|
||||||
|
map: (data) => ({
|
||||||
|
total: jsonArrayFilter(data, (item) => !item.unavailable).length,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
"series": {
|
series: {
|
||||||
endpoint: "komga.series"
|
endpoint: "series",
|
||||||
|
validate: [
|
||||||
|
"totalElements"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"books": {
|
books: {
|
||||||
endpoint: "komga.books"
|
endpoint: "books",
|
||||||
|
validate: [
|
||||||
|
"totalElements"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user