From 7c72ab1674fd2afc9c951c8bd80f948e7fa8621f Mon Sep 17 00:00:00 2001 From: AlejandroAkbal <37181533+AlejandroAkbal@users.noreply.github.com> Date: Thu, 16 Jul 2026 12:02:19 +0000 Subject: [PATCH] feat: add proxy bypassing magic string to BooruOutboundProxyConfig Introduces the ability to bypass outbound proxies selectively in `booruQueriesDTO` proxy rotation settings. By explicitly supplying `"NONE"` as the `baseUrl` in the proxy policy, the system passes requests straight to the original origin without wrapping them in proxy URLs, enabling hybrid "some proxy, some direct" configurations (and thus naturally letting direct connections take their turn within the same round-robin schedule). --- src/booru/booru.service.spec.ts | 38 ++++++++++++++++++++++++++++++++- src/booru/booru.service.ts | 8 +++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/booru/booru.service.spec.ts b/src/booru/booru.service.spec.ts index 22257df..4f5e6d5 100644 --- a/src/booru/booru.service.spec.ts +++ b/src/booru/booru.service.spec.ts @@ -305,6 +305,34 @@ describe('BooruService', () => { expect(directUrl.searchParams.get('api_key')).toBe('pass_1') }) + it('should allow bypassing proxies with the NONE magic string', () => { + mockConfigService.get.mockImplementation((key: string) => { + if (key === 'BOORU_OUTBOUND_PROXY_CONFIG') { + return JSON.stringify({ + 'gelbooru.com': { + baseUrl: 'NONE' + } + }) + } + + return undefined + }) + + const queries = { + ...baseQueries, + baseEndpoint: 'gelbooru.com', + auth_user: 'managed_1', + auth_pass: 'pass_1' + } as booruQueriesDTO + + const directUrl = buildPostUrl(service.buildApiClass(mockParams, queries)) + + expect(directUrl.origin).toBe('https://gelbooru.com') + expect(directUrl.searchParams.get('tags')).toBe('diana') + expect(directUrl.searchParams.get('user_id')).toBe('managed_1') + expect(directUrl.searchParams.get('api_key')).toBe('pass_1') + }) + it('should rotate through multiple configured provider proxies', () => { mockConfigService.get.mockImplementation((key: string) => { if (key === 'BOORU_OUTBOUND_PROXY_CONFIG') { @@ -317,6 +345,9 @@ describe('BooruService', () => { { baseUrl: 'https://cors-proxy.refinedsoftware00.workers.dev/', targetParam: 'q' + }, + { + baseUrl: 'NONE' } ] }) @@ -335,10 +366,12 @@ describe('BooruService', () => { const firstUrl = buildPostUrl(service.buildApiClass(mockParams, queries)) const secondUrl = buildPostUrl(service.buildApiClass(mockParams, queries)) const thirdUrl = buildPostUrl(service.buildApiClass(mockParams, queries)) + const fourthUrl = buildPostUrl(service.buildApiClass(mockParams, queries)) expect(firstUrl.origin).toBe('https://cors-proxy2.rule34.workers.dev') expect(secondUrl.origin).toBe('https://cors-proxy.refinedsoftware00.workers.dev') - expect(thirdUrl.origin).toBe('https://cors-proxy2.rule34.workers.dev') + expect(thirdUrl.origin).toBe('https://gelbooru.com') + expect(fourthUrl.origin).toBe('https://cors-proxy2.rule34.workers.dev') }) it('should not rotate proxies while building an API that never fetches', () => { @@ -353,6 +386,9 @@ describe('BooruService', () => { { baseUrl: 'https://cors-proxy.refinedsoftware00.workers.dev/', targetParam: 'q' + }, + { + baseUrl: 'NONE' } ] }) diff --git a/src/booru/booru.service.ts b/src/booru/booru.service.ts index 67e035e..0c86ec2 100644 --- a/src/booru/booru.service.ts +++ b/src/booru/booru.service.ts @@ -42,7 +42,7 @@ interface BooruQueryIdentifierDefaults { } interface BooruOutboundProxyPolicy { - baseUrl: string + baseUrl: string | 'NONE' targetParam: string } @@ -421,7 +421,7 @@ export class BooruService { const upstreamUrl = originalMethod.apply(api, args) as URL const proxyPolicy = this.getOutboundProxyPolicy(domain) - if (proxyPolicy === undefined) { + if (proxyPolicy === undefined || proxyPolicy.baseUrl === 'NONE') { return upstreamUrl } @@ -523,6 +523,10 @@ export class BooruService { const baseUrl = policy['baseUrl'] const targetParam = policy['targetParam'] ?? 'q' + if (baseUrl === 'NONE') { + return { baseUrl, targetParam: 'q' } + } + if (typeof baseUrl !== 'string' || !URL.canParse(baseUrl)) { throw new Error(`Invalid BOORU_OUTBOUND_PROXY_CONFIG baseUrl for ${domain}`) }