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 { widget } = service;
|
||||
const { data: booksData, error: booksError } = useWidgetAPI(widget, "books");
|
||||
const { data: authorsData, error: authorsError } = useWidgetAPI(widget, "authors");
|
||||
const { data: seriesData, error: seriesError } = useWidgetAPI(widget, "series");
|
||||
const { data, error } = useWidgetAPI(widget, "stats");
|
||||
|
||||
if (booksError || authorsError || seriesError) {
|
||||
const finalError = booksError ?? authorsError ?? seriesError;
|
||||
return <Container service={service} error={finalError} />;
|
||||
if (error) {
|
||||
return <Container service={service} error={error} />;
|
||||
}
|
||||
|
||||
if (!booksData || !authorsData || !seriesData) {
|
||||
if (!data) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="calibreweb.books" />
|
||||
@ -29,9 +26,9 @@ export default function Component({ service }) {
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="calibreweb.books" value={t("common.number", { value: booksData.feed.entry?.length ?? 0 })} />
|
||||
<Block label="calibreweb.authors" value={t("common.number", { value: authorsData.feed.entry?.length ?? 0 })} />
|
||||
<Block label="calibreweb.series" value={t("common.number", { value: seriesData.feed.entry?.length ?? 0 })} />
|
||||
<Block label="calibreweb.books" value={t("common.number", { value: data.books })} />
|
||||
<Block label="calibreweb.authors" value={t("common.number", { value: data.authors })} />
|
||||
<Block label="calibreweb.series" value={t("common.number", { value: data.series })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import { xml2json } from "xml-js";
|
||||
|
||||
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||
import { httpProxy } from "utils/proxy/http";
|
||||
import getServiceWidget from "utils/config/service-helpers";
|
||||
@ -45,13 +43,7 @@ async function apiCall(widget, endpoint) {
|
||||
return { status, contentType, data: null };
|
||||
}
|
||||
|
||||
try {
|
||||
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};
|
||||
}
|
||||
return {status, data: JSON.parse(data), contentType};
|
||||
}
|
||||
|
||||
export default async function calibreWebProxyHandler(req, res) {
|
||||
|
||||
@ -5,14 +5,8 @@ const widget = {
|
||||
proxyHandler: calibreWebProxyHandler,
|
||||
|
||||
mappings: {
|
||||
books: {
|
||||
endpoint: "opds/books/letter/00",
|
||||
},
|
||||
authors: {
|
||||
endpoint: "opds/author/letter/00",
|
||||
},
|
||||
series: {
|
||||
endpoint: "opds/series/letter/00",
|
||||
stats: {
|
||||
endpoint: "opds/stats",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user