From 8f57f389ef313d3a2178756eba21bad07767b4d3 Mon Sep 17 00:00:00 2001 From: dangered wolf Date: Thu, 2 Nov 2023 05:22:09 -0400 Subject: [PATCH] Fix tests --- src/embed/status.ts | 16 +++++++++------- src/worker.ts | 5 ++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/embed/status.ts b/src/embed/status.ts index 7fae148..1a58182 100644 --- a/src/embed/status.ts +++ b/src/embed/status.ts @@ -25,19 +25,21 @@ export const returnError = (error: string): StatusResponse => { Like Twitter, we use the terminologies interchangably. */ export const handleStatus = async ( status: string, - mediaNumber?: number, - userAgent?: string, - flags?: InputFlags, - language?: string, - event?: FetchEvent + mediaNumber: number | undefined, + userAgent: string, + flags: InputFlags, + language: string, + event: FetchEvent, + request: IRequest // eslint-disable-next-line sonarjs/cognitive-complexity ): Promise => { console.log('Direct?', flags?.direct); - const request = (event as FetchEvent).request as IRequest; + console.log('event', event) + let fetchWithThreads = false; - if (request.headers.get('user-agent')?.includes('Telegram') && !flags?.direct) { + if (request?.headers.get('user-agent')?.includes('Telegram') && !flags?.direct) { fetchWithThreads = true; } diff --git a/src/worker.ts b/src/worker.ts index 8acd6c1..c907606 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -132,6 +132,8 @@ const statusRequest = async (request: IRequest, event: FetchEvent, flags: InputF console.log('Bypass bot check'); } + console.log('event', event) + /* This throws the necessary data to handleStatus (in status.ts) */ const statusResponse = await handleStatus( id?.match(/\d{2,20}/)?.[0] || '0', @@ -139,7 +141,8 @@ const statusRequest = async (request: IRequest, event: FetchEvent, flags: InputF userAgent, flags, language, - event + event, + request ); /* Complete responses are normally sent just by errors. Normal embeds send a `text` value. */