From 7060a94becab95aac83d26c6bc0a1adbfb27a75a Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 31 May 2026 06:42:00 +0200 Subject: [PATCH] Refactoring --- apps/api/src/services/fetch/fetch.service.ts | 26 +++++++++---------- .../interfaces/web-fetch-route.interface.ts | 5 +++- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/apps/api/src/services/fetch/fetch.service.ts b/apps/api/src/services/fetch/fetch.service.ts index 37bf055ad..f32e56a1c 100644 --- a/apps/api/src/services/fetch/fetch.service.ts +++ b/apps/api/src/services/fetch/fetch.service.ts @@ -29,10 +29,7 @@ export class FetchService implements OnModuleInit { )) ?? []; } - public async fetch( - input: RequestInfo | URL, - init?: RequestInit - ): Promise { + public async fetch(input: RequestInfo | URL, init?: RequestInit) { const method = ( init?.method ?? (input instanceof Request ? input.method : undefined) ?? @@ -45,13 +42,13 @@ export class FetchService implements OnModuleInit { Logger.debug(`${method} ${urlRedacted}`, 'FetchService'); if (method === 'GET') { - const matchedWebFetchRoute = this.getMatchingWebFetchRoute(url); + const webFetchRoute = this.getMatchingWebFetchRoute(url); - if (matchedWebFetchRoute) { - const response = await this.fetchViaWebFetchTool( + if (webFetchRoute) { + const response = await this.fetchViaWebFetchTool({ url, - matchedWebFetchRoute - ); + webFetchRoute + }); if (response) { return response; @@ -78,10 +75,13 @@ export class FetchService implements OnModuleInit { } } - private async fetchViaWebFetchTool( - url: string, - webFetchRoute: WebFetchRoute - ): Promise { + private async fetchViaWebFetchTool({ + url, + webFetchRoute + }: { + url: string; + webFetchRoute: WebFetchRoute; + }) { const [openRouterApiKey, openRouterModel] = await Promise.all([ this.propertyService.getByKey(PROPERTY_API_KEY_OPENROUTER), this.propertyService.getByKey(PROPERTY_OPENROUTER_MODEL) diff --git a/apps/api/src/services/fetch/interfaces/web-fetch-route.interface.ts b/apps/api/src/services/fetch/interfaces/web-fetch-route.interface.ts index 34d71a98e..efff09398 100644 --- a/apps/api/src/services/fetch/interfaces/web-fetch-route.interface.ts +++ b/apps/api/src/services/fetch/interfaces/web-fetch-route.interface.ts @@ -5,7 +5,10 @@ * Configured via the `WEB_FETCH_ROUTES` property as a JSON array, e.g. * * [ - * { "domain": "example.com", "responseContentType": "application/json" } + * { + * "domain": "example.com", + * "responseContentType": "application/json" + * } * ] * * Matches the domain itself and its subdomains (e.g. `api.example.com`).