From 59c84952ede26df776cc33c6da57e75ef9dfc258 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Fri, 16 Jan 2026 09:01:41 +0000 Subject: [PATCH] fix(fetcher): make FlareSolverr work again, use single session and pass proxy --- src/utils/Fetcher.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/utils/Fetcher.ts b/src/utils/Fetcher.ts index e574ac8..b2cb741 100644 --- a/src/utils/Fetcher.ts +++ b/src/utils/Fetcher.ts @@ -127,7 +127,7 @@ export class Fetcher { } protected async fetchWithTimeout(ctx: Context, url: URL, requestConfig?: CustomRequestConfig, tryCount = 0): Promise { - const proxyUrl = this.getProxyForUrl(url); + const proxyUrl = this.getProxyForUrl(ctx, url); let message = `Fetch ${requestConfig?.method ?? 'GET'} ${url}`; /* istanbul ignore if */ @@ -244,8 +244,17 @@ export class Fetcher { this.logger.info(`Query FlareSolverr for ${url.href}`, ctx); - const data = { cmd: 'request.get', url: url.href, session: 'default' }; - const challengeResult = (await this.queuedFetch(ctx, new URL(flareSolverrEndpoint), { method: 'POST', data, headers: { 'Content-Type': 'application/json' }, queueLimit: 1, timeout: 15000 })).data as FlareSolverrResult; + const data = { + cmd: 'request.get', + url: url.href, + session: 'default', + maxTimeout: 60000, + ...(proxyUrl && { proxy: { url: proxyUrl.href } }), + }; + + const requestConfig = { method: 'POST', data, headers: { 'Content-Type': 'application/json' }, timeout: 60000 }; + const challengeResult = JSON.parse((await this.queuedFetch(ctx, new URL('/v1', flareSolverrEndpoint), requestConfig)).data) as FlareSolverrResult; + if (challengeResult.status !== 'ok') { this.logger.warn(`FlareSolverr issue: ${JSON.stringify(challengeResult)}`, ctx); throw new BlockedError(url, BlockedReason.flaresolverr_failed, {}); @@ -344,7 +353,16 @@ export class Fetcher { return new Promise(sleep => setTimeout(sleep, ms)); } - private getProxyForUrl(url: URL): URL | undefined { + private getProxyForUrl(ctx: Context, url: URL): URL | undefined { + if (ctx.config.mediaFlowProxyUrl && url.href.includes(ctx.config.mediaFlowProxyUrl)) { + return undefined; + } + + const flareSolverrEndpoint = envGet('FLARESOLVERR_ENDPOINT'); + if (flareSolverrEndpoint && url.href.startsWith(flareSolverrEndpoint)) { + return undefined; + } + const proxyConfig = process.env['PROXY_CONFIG']; if (proxyConfig) {