From eb67cf1d6ff3645b547570fd50ad76f3be14cc94 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 21 Aug 2023 19:31:48 -0700 Subject: [PATCH] Revert "Calibre web widget (#1829)" This reverts commit 4c49767a0fd4df8f212efacc803d9b3b1601bf71. --- public/locales/en/common.json | 5 -- src/widgets/calibreweb/component.jsx | 37 -------------- src/widgets/calibreweb/proxy.js | 73 ---------------------------- src/widgets/calibreweb/widget.js | 20 -------- src/widgets/components.js | 1 - src/widgets/widgets.js | 2 - 6 files changed, 138 deletions(-) delete mode 100644 src/widgets/calibreweb/component.jsx delete mode 100644 src/widgets/calibreweb/proxy.js delete mode 100644 src/widgets/calibreweb/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 373a9bea5..ca560f928 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -667,11 +667,6 @@ "monitoring": "Monitoring", "updates": "Updates" }, - "calibreweb": { - "books": "Books", - "authors": "Authors", - "series": "Series" - }, "jdownloader": { "downloadCount": "Queue", "downloadBytesRemaining": "Remaining", diff --git a/src/widgets/calibreweb/component.jsx b/src/widgets/calibreweb/component.jsx deleted file mode 100644 index 450297af7..000000000 --- a/src/widgets/calibreweb/component.jsx +++ /dev/null @@ -1,37 +0,0 @@ -import { useTranslation } from "next-i18next"; - -import Container from "components/services/widget/container"; -import Block from "components/services/widget/block"; -import useWidgetAPI from "utils/proxy/use-widget-api"; - -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"); - - if (booksError || authorsError || seriesError) { - const finalError = booksError ?? authorsError ?? seriesError; - return ; - } - - if (!booksData || !authorsData || !seriesData) { - return ( - - - - - - ); - } - - return ( - - - - - - ); -} diff --git a/src/widgets/calibreweb/proxy.js b/src/widgets/calibreweb/proxy.js deleted file mode 100644 index 4328e43cd..000000000 --- a/src/widgets/calibreweb/proxy.js +++ /dev/null @@ -1,73 +0,0 @@ -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"; -import createLogger from "utils/logger"; -import widgets from "widgets/widgets"; - -const proxyName = "calibreWebProxyHandler"; -const logger = createLogger(proxyName); - -async function getWidget(req) { - const { group, service } = req.query; - - if (!group || !service) { - logger.debug("Invalid or missing service '%s' or group '%s'", service, group); - return null; - } - - const widget = await getServiceWidget(group, service); - - if (!widget) { - logger.debug("Invalid or missing widget for service '%s' in group '%s'", service, group); - return null; - } - - return widget; -} - -async function apiCall(widget, endpoint) { - const { api } = widgets[widget.type]; - const apiUrl = new URL(formatApiCall(api, { endpoint, ...widget })); - const headers = { - Authorization: `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}` - }; - - const [status, contentType, data] = await httpProxy(apiUrl, { - withCredentials: true, - credentials: "include", - headers, - }); - - if (status !== 200) { - logger.error("Error getting data from CalibreWeb: %s status %d. Data: %s", apiUrl, status, data); - 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}; - } -} - -export default async function calibreWebProxyHandler(req, res) { - const widget = await getWidget(req); - - const { endpoint } = req.query; - - if (!widget) { - return res.status(400).json({ error: "Invalid proxy service type" }); - } - - const { status, data } = await apiCall(widget, endpoint); - - 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(data); -} diff --git a/src/widgets/calibreweb/widget.js b/src/widgets/calibreweb/widget.js deleted file mode 100644 index ea898dd1a..000000000 --- a/src/widgets/calibreweb/widget.js +++ /dev/null @@ -1,20 +0,0 @@ -import calibreWebProxyHandler from "./proxy"; - -const widget = { - api: "{url}/{endpoint}", - proxyHandler: calibreWebProxyHandler, - - mappings: { - books: { - endpoint: "opds/books/letter/00", - }, - authors: { - endpoint: "opds/author/letter/00", - }, - series: { - endpoint: "opds/series/letter/00", - }, - }, -}; - -export default widget; diff --git a/src/widgets/components.js b/src/widgets/components.js index 4662a8c38..481c1386f 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -9,7 +9,6 @@ const components = { azuredevops: dynamic(() => import("./azuredevops/component")), bazarr: dynamic(() => import("./bazarr/component")), caddy: dynamic(() => import("./caddy/component")), - calibreweb: dynamic(() => import("./calibreweb/component")), changedetectionio: dynamic(() => import("./changedetectionio/component")), channelsdvrserver: dynamic(() => import("./channelsdvrserver/component")), cloudflared: dynamic(() => import("./cloudflared/component")), diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index f17a47675..b44e72dd7 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -6,7 +6,6 @@ import autobrr from "./autobrr/widget"; import azuredevops from "./azuredevops/widget"; import bazarr from "./bazarr/widget"; import caddy from "./caddy/widget"; -import calibreweb from "./calibreweb/widget"; import changedetectionio from "./changedetectionio/widget"; import channelsdvrserver from "./channelsdvrserver/widget"; import cloudflared from "./cloudflared/widget"; @@ -104,7 +103,6 @@ const widgets = { azuredevops, bazarr, caddy, - calibreweb, changedetectionio, channelsdvrserver, cloudflared,