Get it working

This commit is contained in:
Georges-Antoine Assi 2023-08-20 11:00:49 -04:00
parent d3829dc4c5
commit 4000304fcb
No known key found for this signature in database
GPG Key ID: E01F01B06E816D51
4 changed files with 17 additions and 10 deletions

View File

@ -36,8 +36,9 @@ export default async function credentialedProxyHandler(req, res, map) {
"tailscale", "tailscale",
"truenas", "truenas",
"pterodactyl", "pterodactyl",
].includes(widget.type)) { ].includes(widget.type))
headers.Authorization = `Bearer ${widget.key}`; {
headers.Authorization = `Bearer ${widget.key}`;
} else if (widget.type === "proxmox") { } else if (widget.type === "proxmox") {
headers.Authorization = `PVEAPIToken=${widget.username}=${widget.password}`; headers.Authorization = `PVEAPIToken=${widget.username}=${widget.password}`;
} else if (widget.type === "proxmoxbackupserver") { } else if (widget.type === "proxmoxbackupserver") {

View File

@ -29,9 +29,9 @@ export default function Component({ service }) {
return ( return (
<Container service={service}> <Container service={service}>
<Block label="calibreweb.books" value={t("common.number", { value: booksData.total })} /> <Block label="calibreweb.books" value={t("common.number", { value: booksData.feed.entry.length })} />
<Block label="calibreweb.authors" value={t("common.number", { value: authorsData.length })} /> <Block label="calibreweb.authors" value={t("common.number", { value: authorsData.feed.entry.length })} />
<Block label="calibreweb.series" value={t("common.number", { value: seriesData.length })} /> <Block label="calibreweb.series" value={t("common.number", { value: seriesData.feed.entry.length })} />
</Container> </Container>
); );
} }

View File

@ -28,8 +28,9 @@ async function getWidget(req) {
return widget; return widget;
} }
async function apiCall(widget, endpoint) { async function apiCall(widgets, widget, endpoint) {
const apiUrl = new URL(formatApiCall(endpoint, { endpoint, ...widget })); const api = widgets[widget.type].api;
const apiUrl = new URL(formatApiCall(api, { endpoint, ...widget }));
const headers = { const headers = {
Authorization: `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}` 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) { export default async function calibreWebProxyHandler(req, res) {
const widget = await getWidget(req); const widget = await getWidget(req);
const { service } = req.query; const { endpoint } = req.query;
if (!widget) { if (!widget) {
return res.status(400).json({ error: "Invalid proxy service type" }); return res.status(400).json({ error: "Invalid proxy service type" });
} }
const endpoint = widgets[widget.type].mappings[service].endpoint; const { status, data } = await apiCall(widgets, widget, endpoint);
const { status, contentType, data } = await apiCall(widget, endpoint);
if (status !== 200) { if (status !== 200) {
return res.status(status).json({error: {message: "HTTP error communicating with CalibreWeb API", data: Buffer.from(data).toString()}}); return res.status(status).json({error: {message: "HTTP error communicating with CalibreWeb API", data: Buffer.from(data).toString()}});

View File

@ -8,6 +8,12 @@ const widget = {
books: { books: {
endpoint: "opds/books/letter/00", endpoint: "opds/books/letter/00",
}, },
authors: {
endpoint: "opds/author/letter/00",
},
series: {
endpoint: "opds/series/letter/00",
},
}, },
}; };