From ee042f6f13f45ea6202ea59d43f64a481fe06fe2 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 23 Mar 2024 01:32:22 -0700 Subject: [PATCH] minor code cleanup --- docs/widgets/services/jackett.md | 2 +- src/widgets/jackett/proxy.js | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/docs/widgets/services/jackett.md b/docs/widgets/services/jackett.md index 696e2c316..e102743be 100644 --- a/docs/widgets/services/jackett.md +++ b/docs/widgets/services/jackett.md @@ -13,5 +13,5 @@ Allowed fields: `["configured", "errored"]`. widget: type: jackett url: http://jackett.host.or.ip - password: JackettAdminPassword + password: jackettadminpassword # optional ``` diff --git a/src/widgets/jackett/proxy.js b/src/widgets/jackett/proxy.js index 91f7d507c..5292695fc 100644 --- a/src/widgets/jackett/proxy.js +++ b/src/widgets/jackett/proxy.js @@ -6,24 +6,22 @@ import widgets from "widgets/widgets"; const logger = createLogger("jackettProxyHandler"); -// Fetches the Jackett cookie; assumes implementation is similar to the previous discussion async function fetchJackettCookie(widget, loginURL) { const url = new URL(formatApiCall(loginURL, widget)); const loginData = `password=${encodeURIComponent(widget.password)}`; const [status, , , , params] = await httpProxy(url, { - method: 'POST', + method: "POST", headers: { - 'Content-Type': 'application/x-www-form-urlencoded' + "Content-Type": "application/x-www-form-urlencoded", }, body: loginData, }); - if (!(status === 200) || !params || !params.headers || !params.headers.Cookie) { + if (!(status === 200) || !params?.headers?.Cookie) { logger.error("Failed to fetch Jackett cookie, status: %d", status); return null; } - const cookieValue = params.headers.Cookie; - return cookieValue; + return params.headers.Cookie; } export default async function jackettProxyHandler(req, res) { @@ -49,11 +47,10 @@ export default async function jackettProxyHandler(req, res) { widget.headers = { ...widget.headers, Cookie: jackettCookie }; } - // Construct the API call to Jackett const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...widget })); try { - const [status, contentType, data] = await httpProxy(url.toString(), { + const [status, , data] = await httpProxy(url, { method: "GET", headers: widget.headers, }); @@ -63,9 +60,6 @@ export default async function jackettProxyHandler(req, res) { return res.status(status).json({ error: "Failed to call Jackett API", data }); } - if (contentType) { - res.setHeader("Content-Type", contentType); - } return res.status(status).send(data); } catch (error) { logger.error("Exception calling Jackett API: %s", error.message);