Fix last pr with prettier

This commit is contained in:
dangered wolf 2023-05-12 14:56:35 -04:00
parent 05c70635e1
commit 7eace081c1
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
7 changed files with 60 additions and 69 deletions

View file

@ -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;

View file

@ -210,28 +210,31 @@ export const fetchUser = async (
useElongator = false
): Promise<GraphQLUserResponse> => {
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' &&

View file

@ -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);
}
};

View file

@ -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 its 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';
}
}
}
}
text?:
| 'This account is verified because its 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";
};
};
};
};

View file

@ -165,6 +165,6 @@ interface APIUser extends BaseUser {
birthday: {
day?: number;
month?: number;
year?: number
}
}
year?: number;
};
}

View file

@ -48,9 +48,7 @@ export const handleProfile = async (
}
/* Base headers included in all responses */
const headers = [
`<meta property="twitter:site" content="@${user.screen_name}"/>`,
];
const headers = [`<meta property="twitter:site" content="@${user.screen_name}"/>`];
// TODO Add card creation logic here

View file

@ -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', {