From 7eace081c18a60731d8d197db3dd88a3b2f7f918 Mon Sep 17 00:00:00 2001 From: dangered wolf Date: Fri, 12 May 2023 14:56:35 -0400 Subject: [PATCH] Fix last pr with prettier --- src/api/user.ts | 4 +-- src/fetch.ts | 25 ++++++++------ src/server.ts | 21 +++++------- src/types/twitterTypes.d.ts | 68 ++++++++++++++++++------------------- src/types/types.d.ts | 6 ++-- src/user.ts | 4 +-- test/index.test.ts | 1 - 7 files changed, 60 insertions(+), 69 deletions(-) diff --git a/src/api/user.ts b/src/api/user.ts index 7cbc488..593c047 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -63,9 +63,7 @@ export const userAPI = async ( /* Creating the response objects */ const response: UserAPIResponse = { code: 200, message: 'OK' } as UserAPIResponse; - const apiUser: APIUser = (await populateUserProperties( - userResponse, - )) as APIUser; + const apiUser: APIUser = (await populateUserProperties(userResponse)) as APIUser; /* Finally, staple the User to the response and return it */ response.user = apiUser; diff --git a/src/fetch.ts b/src/fetch.ts index ebab8d7..c78c579 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -210,28 +210,31 @@ export const fetchUser = async ( useElongator = false ): Promise => { return (await twitterFetch( - `${Constants.TWITTER_ROOT}/i/api/graphql/sLVLhk0bGj3MVFEKTdax1w/UserByScreenName?variables=${ - encodeURIComponent( - JSON.stringify({ - screen_name: username, - withSafetyModeUserFields: true - }) - ) - }&features=${encodeURIComponent( + `${ + Constants.TWITTER_ROOT + }/i/api/graphql/sLVLhk0bGj3MVFEKTdax1w/UserByScreenName?variables=${encodeURIComponent( + JSON.stringify({ + screen_name: username, + withSafetyModeUserFields: true + }) + )}&features=${encodeURIComponent( JSON.stringify({ blue_business_profile_image_shape_enabled: true, responsive_web_graphql_exclude_directive_enabled: true, responsive_web_graphql_skip_user_profile_image_extensions_enabled: false, responsive_web_graphql_timeline_navigation_enabled: false, verified_phone_label_enabled: true - }) - )}`, + }) + )}`, event, useElongator, // Validator function (_res: unknown) => { const response = _res as GraphQLUserResponse; - return !(response?.data?.user?.result?.__typename !== 'User' || typeof response.data.user.result.legacy === 'undefined'); + return !( + response?.data?.user?.result?.__typename !== 'User' || + typeof response.data.user.result.legacy === 'undefined' + ); /* return !( typeof conversation.globalObjects === 'undefined' && diff --git a/src/server.ts b/src/server.ts index c797ecf..51a87d1 100644 --- a/src/server.ts +++ b/src/server.ts @@ -142,8 +142,11 @@ const statusRequest = async ( }; /* Handler for User Profiles */ -const profileRequest = async (request: IRequest, event: FetchEvent, - flags: InputFlags = {}) => { +const profileRequest = async ( + request: IRequest, + event: FetchEvent, + flags: InputFlags = {} +) => { const { handle } = request.params; const url = new URL(request.url); const userAgent = request.headers.get('User-Agent') || ''; @@ -171,7 +174,7 @@ const profileRequest = async (request: IRequest, event: FetchEvent, console.log('JSON API request'); flags.api = true; } - + /* Direct media or API access bypasses bot check, returning same response regardless of UA */ if (isBotUA || flags.api) { if (isBotUA) { @@ -181,12 +184,7 @@ const profileRequest = async (request: IRequest, event: FetchEvent, } /* This throws the necessary data to handleStatus (in status.ts) */ - const profileResponse = await handleProfile( - username, - userAgent, - flags, - event - ); + const profileResponse = await handleProfile(username, userAgent, flags, event); /* Complete responses are normally sent just by errors. Normal embeds send a `text` value. */ if (profileResponse.response) { @@ -221,10 +219,7 @@ const profileRequest = async (request: IRequest, event: FetchEvent, /* A human has clicked a fxtwitter.com/:screen_name link! Obviously we just need to redirect to the user directly.*/ console.log('Matched human UA', userAgent); - return Response.redirect( - `${Constants.TWITTER_ROOT}/${handle}`, - 302 - ); + return Response.redirect(`${Constants.TWITTER_ROOT}/${handle}`, 302); } }; diff --git a/src/types/twitterTypes.d.ts b/src/types/twitterTypes.d.ts index da2dd91..2a79da7 100644 --- a/src/types/twitterTypes.d.ts +++ b/src/types/twitterTypes.d.ts @@ -198,36 +198,36 @@ type GraphQLUserResponse = { data: { user: { result: GraphQLUser; - } - } -} + }; + }; +}; type GraphQLUser = { - __typename: "User"; + __typename: 'User'; id: string; // "VXNlcjo3ODMyMTQ=" rest_id: string; // "783214", affiliates_highlighted_label: { label?: { badge?: { url?: string; // "https://pbs.twimg.com/semantic_core_img/1290392753013002240/mWq1iE5L?format=png&name=orig" - } + }; description?: string; // "United States government organization" url?: { url?: string; // "https://help.twitter.com/rules-and-policies/state-affiliated" urlType: string; // "DeepLink" - } - } - } + }; + }; + }; business_account: { - affiliates_count?: 20 - } + affiliates_count?: 20; + }; is_blue_verified: boolean; // false, - profile_image_shape: 'Circle' | 'Square'|'Hexagon'; // "Circle", + profile_image_shape: 'Circle' | 'Square' | 'Hexagon'; // "Circle", has_nft_avatar: boolean; // false, legacy: { created_at: string; // "Tue Feb 20 14:35:54 +0000 2007", - default_profile: boolean // false, - default_profile_image: boolean // false, + default_profile: boolean; // false, + default_profile_image: boolean; // false, description: string; // "What's happening?!", entities: { description?: { @@ -235,14 +235,11 @@ type GraphQLUser = { display_url: string; // "about.twitter.com", expanded_url: string; // "https://about.twitter.com/", url: string; // "https://t.co/DAtOo6uuHk", - indices: [ - 0, - 23 - ] - }[] - } - }, - fast_followers_count: 0, + indices: [0, 23]; + }[]; + }; + }; + fast_followers_count: 0; favourites_count: number; // 126708, followers_count: number; // 4996, friends_count: number; // 2125, @@ -262,20 +259,20 @@ type GraphQLUser = { statuses_count: number; // 15047 translator_type: string; // "regular" verified: boolean; // false - verified_type: 'Business'|'Government'; - withheld_in_countries: [] - }, + verified_type: 'Business' | 'Government'; + withheld_in_countries: []; + }; professional: { rest_id: string; // "1503055759638159366", professional_type: string; // "Creator", category: [ { id: number; // 354, - name: string // "Community", + name: string; // "Community", icon_name: string; // "IconBriefcaseStroke" } - ] - }, + ]; + }; legacy_extended_profile: { birthdate?: { day: number; // 7, @@ -286,8 +283,8 @@ type GraphQLUser = { }; profile_image_shape: string; // "Circle", rest_id: string; // "783214", - }, - is_profile_translatable: false, + }; + is_profile_translatable: false; verification_info: { reason: { description: { @@ -299,9 +296,10 @@ type GraphQLUser = { }; to_index: number; // 108 }[]; - text?: 'This account is verified because it’s subscribed to Twitter Blue or is a legacy verified account. Learn more'|'This account is verified because it\'s an official organisation on Twitter. Learn more'; - } - } - } - -} \ No newline at end of file + text?: + | 'This account is verified because it’s subscribed to Twitter Blue or is a legacy verified account. Learn more' + | "This account is verified because it's an official organisation on Twitter. Learn more"; + }; + }; + }; +}; diff --git a/src/types/types.d.ts b/src/types/types.d.ts index aaff12f..fc5d971 100644 --- a/src/types/types.d.ts +++ b/src/types/types.d.ts @@ -165,6 +165,6 @@ interface APIUser extends BaseUser { birthday: { day?: number; month?: number; - year?: number - } -} \ No newline at end of file + year?: number; + }; +} diff --git a/src/user.ts b/src/user.ts index d92d163..736f600 100644 --- a/src/user.ts +++ b/src/user.ts @@ -48,9 +48,7 @@ export const handleProfile = async ( } /* Base headers included in all responses */ - const headers = [ - ``, - ]; + const headers = [``]; // TODO Add card creation logic here diff --git a/test/index.test.ts b/test/index.test.ts index 033a358..f5b06f0 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -191,7 +191,6 @@ test('API fetch multi-photo Tweet', async () => { ); }); - test('API fetch poll Tweet', async () => { const result = await cacheWrapper( new Request('https://api.fxtwitter.com/status/1055475950543167488', {