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",
"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") {

View File

@ -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>
);
}

View File

@ -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()}});

View File

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