From 989039af810ddb04559f2d492c0eeb494506bc52 Mon Sep 17 00:00:00 2001 From: Wtfitsaduck <63978589+Wtfitsaduck@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:59:54 -0700 Subject: [PATCH] Enhancement: support Tdarr widget auth (#3940) --------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> --- docs/widgets/services/tdarr.md | 1 + src/widgets/tdarr/proxy.js | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/widgets/services/tdarr.md b/docs/widgets/services/tdarr.md index 763fc6268..3f201f053 100644 --- a/docs/widgets/services/tdarr.md +++ b/docs/widgets/services/tdarr.md @@ -11,4 +11,5 @@ Allowed fields: `["queue", "processed", "errored", "saved"]`. widget: type: tdarr url: http://tdarr.host.or.ip + key: tdarrapikey # optional, false if unused ``` diff --git a/src/widgets/tdarr/proxy.js b/src/widgets/tdarr/proxy.js index 898082f40..9e26fdc06 100644 --- a/src/widgets/tdarr/proxy.js +++ b/src/widgets/tdarr/proxy.js @@ -21,9 +21,13 @@ export default async function tdarrProxyHandler(req, res) { logger.debug("Invalid or missing widget for service '%s' in group '%s'", service, group); return res.status(400).json({ error: "Invalid proxy service type" }); } - + const headers = { + "content-type": "application/json", + }; + if (widget.key) { + headers["x-api-key"] = `${widget.key}`; + } const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint: undefined, ...widget })); - const [status, contentType, data] = await httpProxy(url, { method: "POST", body: JSON.stringify({ @@ -33,9 +37,7 @@ export default async function tdarrProxyHandler(req, res) { docID: "statistics", }, }), - headers: { - "content-type": "application/json", - }, + headers, }); if (status !== 200) {