From e76777d29884eb26f5dc1a05cbb8b5da9e84c07f Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:23:06 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=8A=20fix:=20OpenID=20proxy=20support?= =?UTF-8?q?=20for=20downloading=20profile=20pictures=20(#3263)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to #3261 Add proxy support to `downloadImage` function in `openidStrategy.js` * Import `HttpsProxyAgent` from `https-proxy-agent`. * Add `agent` property to the fetch options in `downloadImage` function if `process.env.PROXY` is set. * Update the `fetch` call in `downloadImage` function to use the proxy agent if available. --- api/strategies/openidStrategy.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api/strategies/openidStrategy.js b/api/strategies/openidStrategy.js index 794a38778d..2beeaa13eb 100644 --- a/api/strategies/openidStrategy.js +++ b/api/strategies/openidStrategy.js @@ -25,12 +25,18 @@ const downloadImage = async (url, accessToken) => { } try { - const response = await fetch(url, { + const options = { method: 'GET', headers: { Authorization: `Bearer ${accessToken}`, }, - }); + }; + + if (process.env.PROXY) { + options.agent = new HttpsProxyAgent(process.env.PROXY); + } + + const response = await fetch(url, options); if (response.ok) { const buffer = await response.buffer();