Get it working
This commit is contained in:
parent
d3829dc4c5
commit
4000304fcb
@ -36,7 +36,8 @@ export default async function credentialedProxyHandler(req, res, map) {
|
||||
"tailscale",
|
||||
"truenas",
|
||||
"pterodactyl",
|
||||
].includes(widget.type)) {
|
||||
].includes(widget.type))
|
||||
{
|
||||
headers.Authorization = `Bearer ${widget.key}`;
|
||||
} else if (widget.type === "proxmox") {
|
||||
headers.Authorization = `PVEAPIToken=${widget.username}=${widget.password}`;
|
||||
|
||||
@ -29,9 +29,9 @@ export default function Component({ service }) {
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="calibreweb.books" value={t("common.number", { value: booksData.total })} />
|
||||
<Block label="calibreweb.authors" value={t("common.number", { value: authorsData.length })} />
|
||||
<Block label="calibreweb.series" value={t("common.number", { value: seriesData.length })} />
|
||||
<Block label="calibreweb.books" value={t("common.number", { value: booksData.feed.entry.length })} />
|
||||
<Block label="calibreweb.authors" value={t("common.number", { value: authorsData.feed.entry.length })} />
|
||||
<Block label="calibreweb.series" value={t("common.number", { value: seriesData.feed.entry.length })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
@ -28,8 +28,9 @@ async function getWidget(req) {
|
||||
return widget;
|
||||
}
|
||||
|
||||
async function apiCall(widget, endpoint) {
|
||||
const apiUrl = new URL(formatApiCall(endpoint, { endpoint, ...widget }));
|
||||
async function apiCall(widgets, widget, endpoint) {
|
||||
const api = widgets[widget.type].api;
|
||||
const apiUrl = new URL(formatApiCall(api, { endpoint, ...widget }));
|
||||
const headers = {
|
||||
Authorization: `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`
|
||||
};
|
||||
@ -57,14 +58,13 @@ async function apiCall(widget, endpoint) {
|
||||
export default async function calibreWebProxyHandler(req, res) {
|
||||
const widget = await getWidget(req);
|
||||
|
||||
const { service } = req.query;
|
||||
const { endpoint } = req.query;
|
||||
|
||||
if (!widget) {
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
|
||||
const endpoint = widgets[widget.type].mappings[service].endpoint;
|
||||
const { status, contentType, data } = await apiCall(widget, endpoint);
|
||||
const { status, data } = await apiCall(widgets, widget, endpoint);
|
||||
|
||||
if (status !== 200) {
|
||||
return res.status(status).json({error: {message: "HTTP error communicating with CalibreWeb API", data: Buffer.from(data).toString()}});
|
||||
|
||||
@ -8,6 +8,12 @@ const widget = {
|
||||
books: {
|
||||
endpoint: "opds/books/letter/00",
|
||||
},
|
||||
authors: {
|
||||
endpoint: "opds/author/letter/00",
|
||||
},
|
||||
series: {
|
||||
endpoint: "opds/series/letter/00",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user