From 4000304fcbbcabb8f8f08b34f27879f2c3575398 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sun, 20 Aug 2023 11:00:49 -0400 Subject: [PATCH] Get it working --- src/utils/proxy/handlers/credentialed.js | 5 +++-- src/widgets/calibreweb/component.jsx | 6 +++--- src/widgets/calibreweb/proxy.js | 10 +++++----- src/widgets/calibreweb/widget.js | 6 ++++++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/utils/proxy/handlers/credentialed.js b/src/utils/proxy/handlers/credentialed.js index a13058e9..9840c30a 100644 --- a/src/utils/proxy/handlers/credentialed.js +++ b/src/utils/proxy/handlers/credentialed.js @@ -36,8 +36,9 @@ export default async function credentialedProxyHandler(req, res, map) { "tailscale", "truenas", "pterodactyl", - ].includes(widget.type)) { - headers.Authorization = `Bearer ${widget.key}`; + ].includes(widget.type)) + { + headers.Authorization = `Bearer ${widget.key}`; } else if (widget.type === "proxmox") { headers.Authorization = `PVEAPIToken=${widget.username}=${widget.password}`; } else if (widget.type === "proxmoxbackupserver") { diff --git a/src/widgets/calibreweb/component.jsx b/src/widgets/calibreweb/component.jsx index 7b98779d..0a2fcf2b 100644 --- a/src/widgets/calibreweb/component.jsx +++ b/src/widgets/calibreweb/component.jsx @@ -29,9 +29,9 @@ export default function Component({ service }) { return ( - - - + + + ); } diff --git a/src/widgets/calibreweb/proxy.js b/src/widgets/calibreweb/proxy.js index cab5277d..e28dcdff 100644 --- a/src/widgets/calibreweb/proxy.js +++ b/src/widgets/calibreweb/proxy.js @@ -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()}}); diff --git a/src/widgets/calibreweb/widget.js b/src/widgets/calibreweb/widget.js index 6b9b1efb..ea898dd1 100644 --- a/src/widgets/calibreweb/widget.js +++ b/src/widgets/calibreweb/widget.js @@ -8,6 +8,12 @@ const widget = { books: { endpoint: "opds/books/letter/00", }, + authors: { + endpoint: "opds/author/letter/00", + }, + series: { + endpoint: "opds/series/letter/00", + }, }, };