Switch to new opds stats endpoint
This commit is contained in:
parent
c0afde1dda
commit
d0ec7b06b3
@ -8,16 +8,13 @@ export default function Component({ service }) {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { widget } = service;
|
const { widget } = service;
|
||||||
const { data: booksData, error: booksError } = useWidgetAPI(widget, "books");
|
const { data, error } = useWidgetAPI(widget, "stats");
|
||||||
const { data: authorsData, error: authorsError } = useWidgetAPI(widget, "authors");
|
|
||||||
const { data: seriesData, error: seriesError } = useWidgetAPI(widget, "series");
|
|
||||||
|
|
||||||
if (booksError || authorsError || seriesError) {
|
if (error) {
|
||||||
const finalError = booksError ?? authorsError ?? seriesError;
|
return <Container service={service} error={error} />;
|
||||||
return <Container service={service} error={finalError} />;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!booksData || !authorsData || !seriesData) {
|
if (!data) {
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="calibreweb.books" />
|
<Block label="calibreweb.books" />
|
||||||
@ -29,9 +26,9 @@ export default function Component({ service }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="calibreweb.books" value={t("common.number", { value: booksData.feed.entry?.length ?? 0 })} />
|
<Block label="calibreweb.books" value={t("common.number", { value: data.books })} />
|
||||||
<Block label="calibreweb.authors" value={t("common.number", { value: authorsData.feed.entry?.length ?? 0 })} />
|
<Block label="calibreweb.authors" value={t("common.number", { value: data.authors })} />
|
||||||
<Block label="calibreweb.series" value={t("common.number", { value: seriesData.feed.entry?.length ?? 0 })} />
|
<Block label="calibreweb.series" value={t("common.number", { value: data.series })} />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
import { xml2json } from "xml-js";
|
|
||||||
|
|
||||||
import { formatApiCall } from "utils/proxy/api-helpers";
|
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||||
import { httpProxy } from "utils/proxy/http";
|
import { httpProxy } from "utils/proxy/http";
|
||||||
import getServiceWidget from "utils/config/service-helpers";
|
import getServiceWidget from "utils/config/service-helpers";
|
||||||
@ -45,13 +43,7 @@ async function apiCall(widget, endpoint) {
|
|||||||
return { status, contentType, data: null };
|
return { status, contentType, data: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return {status, data: JSON.parse(data), contentType};
|
||||||
const dataDecoded = xml2json(data.toString(), { compact: true });
|
|
||||||
return {status, data: JSON.parse(dataDecoded), contentType};
|
|
||||||
} catch (e) {
|
|
||||||
logger.error("Error decoding CalibreWeb API data. Data: %s", data.toString());
|
|
||||||
return {status, data: null, contentType};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function calibreWebProxyHandler(req, res) {
|
export default async function calibreWebProxyHandler(req, res) {
|
||||||
|
|||||||
@ -5,14 +5,8 @@ const widget = {
|
|||||||
proxyHandler: calibreWebProxyHandler,
|
proxyHandler: calibreWebProxyHandler,
|
||||||
|
|
||||||
mappings: {
|
mappings: {
|
||||||
books: {
|
stats: {
|
||||||
endpoint: "opds/books/letter/00",
|
endpoint: "opds/stats",
|
||||||
},
|
|
||||||
authors: {
|
|
||||||
endpoint: "opds/author/letter/00",
|
|
||||||
},
|
|
||||||
series: {
|
|
||||||
endpoint: "opds/series/letter/00",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user