mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-08 03:50:53 +01:00
Fix last pr with prettier
This commit is contained in:
parent
05c70635e1
commit
7eace081c1
7 changed files with 60 additions and 69 deletions
|
@ -63,9 +63,7 @@ export const userAPI = async (
|
||||||
|
|
||||||
/* Creating the response objects */
|
/* Creating the response objects */
|
||||||
const response: UserAPIResponse = { code: 200, message: 'OK' } as UserAPIResponse;
|
const response: UserAPIResponse = { code: 200, message: 'OK' } as UserAPIResponse;
|
||||||
const apiUser: APIUser = (await populateUserProperties(
|
const apiUser: APIUser = (await populateUserProperties(userResponse)) as APIUser;
|
||||||
userResponse,
|
|
||||||
)) as APIUser;
|
|
||||||
|
|
||||||
/* Finally, staple the User to the response and return it */
|
/* Finally, staple the User to the response and return it */
|
||||||
response.user = apiUser;
|
response.user = apiUser;
|
||||||
|
|
13
src/fetch.ts
13
src/fetch.ts
|
@ -210,14 +210,14 @@ export const fetchUser = async (
|
||||||
useElongator = false
|
useElongator = false
|
||||||
): Promise<GraphQLUserResponse> => {
|
): Promise<GraphQLUserResponse> => {
|
||||||
return (await twitterFetch(
|
return (await twitterFetch(
|
||||||
`${Constants.TWITTER_ROOT}/i/api/graphql/sLVLhk0bGj3MVFEKTdax1w/UserByScreenName?variables=${
|
`${
|
||||||
encodeURIComponent(
|
Constants.TWITTER_ROOT
|
||||||
|
}/i/api/graphql/sLVLhk0bGj3MVFEKTdax1w/UserByScreenName?variables=${encodeURIComponent(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
screen_name: username,
|
screen_name: username,
|
||||||
withSafetyModeUserFields: true
|
withSafetyModeUserFields: true
|
||||||
})
|
})
|
||||||
)
|
)}&features=${encodeURIComponent(
|
||||||
}&features=${encodeURIComponent(
|
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
blue_business_profile_image_shape_enabled: true,
|
blue_business_profile_image_shape_enabled: true,
|
||||||
responsive_web_graphql_exclude_directive_enabled: true,
|
responsive_web_graphql_exclude_directive_enabled: true,
|
||||||
|
@ -231,7 +231,10 @@ export const fetchUser = async (
|
||||||
// Validator function
|
// Validator function
|
||||||
(_res: unknown) => {
|
(_res: unknown) => {
|
||||||
const response = _res as GraphQLUserResponse;
|
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 !(
|
return !(
|
||||||
typeof conversation.globalObjects === 'undefined' &&
|
typeof conversation.globalObjects === 'undefined' &&
|
||||||
|
|
|
@ -142,8 +142,11 @@ const statusRequest = async (
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Handler for User Profiles */
|
/* Handler for User Profiles */
|
||||||
const profileRequest = async (request: IRequest, event: FetchEvent,
|
const profileRequest = async (
|
||||||
flags: InputFlags = {}) => {
|
request: IRequest,
|
||||||
|
event: FetchEvent,
|
||||||
|
flags: InputFlags = {}
|
||||||
|
) => {
|
||||||
const { handle } = request.params;
|
const { handle } = request.params;
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const userAgent = request.headers.get('User-Agent') || '';
|
const userAgent = request.headers.get('User-Agent') || '';
|
||||||
|
@ -181,12 +184,7 @@ const profileRequest = async (request: IRequest, event: FetchEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This throws the necessary data to handleStatus (in status.ts) */
|
/* This throws the necessary data to handleStatus (in status.ts) */
|
||||||
const profileResponse = await handleProfile(
|
const profileResponse = await handleProfile(username, userAgent, flags, event);
|
||||||
username,
|
|
||||||
userAgent,
|
|
||||||
flags,
|
|
||||||
event
|
|
||||||
);
|
|
||||||
|
|
||||||
/* Complete responses are normally sent just by errors. Normal embeds send a `text` value. */
|
/* Complete responses are normally sent just by errors. Normal embeds send a `text` value. */
|
||||||
if (profileResponse.response) {
|
if (profileResponse.response) {
|
||||||
|
@ -221,10 +219,7 @@ const profileRequest = async (request: IRequest, event: FetchEvent,
|
||||||
/* A human has clicked a fxtwitter.com/:screen_name link!
|
/* A human has clicked a fxtwitter.com/:screen_name link!
|
||||||
Obviously we just need to redirect to the user directly.*/
|
Obviously we just need to redirect to the user directly.*/
|
||||||
console.log('Matched human UA', userAgent);
|
console.log('Matched human UA', userAgent);
|
||||||
return Response.redirect(
|
return Response.redirect(`${Constants.TWITTER_ROOT}/${handle}`, 302);
|
||||||
`${Constants.TWITTER_ROOT}/${handle}`,
|
|
||||||
302
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
68
src/types/twitterTypes.d.ts
vendored
68
src/types/twitterTypes.d.ts
vendored
|
@ -198,36 +198,36 @@ type GraphQLUserResponse = {
|
||||||
data: {
|
data: {
|
||||||
user: {
|
user: {
|
||||||
result: GraphQLUser;
|
result: GraphQLUser;
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
type GraphQLUser = {
|
type GraphQLUser = {
|
||||||
__typename: "User";
|
__typename: 'User';
|
||||||
id: string; // "VXNlcjo3ODMyMTQ="
|
id: string; // "VXNlcjo3ODMyMTQ="
|
||||||
rest_id: string; // "783214",
|
rest_id: string; // "783214",
|
||||||
affiliates_highlighted_label: {
|
affiliates_highlighted_label: {
|
||||||
label?: {
|
label?: {
|
||||||
badge?: {
|
badge?: {
|
||||||
url?: string; // "https://pbs.twimg.com/semantic_core_img/1290392753013002240/mWq1iE5L?format=png&name=orig"
|
url?: string; // "https://pbs.twimg.com/semantic_core_img/1290392753013002240/mWq1iE5L?format=png&name=orig"
|
||||||
}
|
};
|
||||||
description?: string; // "United States government organization"
|
description?: string; // "United States government organization"
|
||||||
url?: {
|
url?: {
|
||||||
url?: string; // "https://help.twitter.com/rules-and-policies/state-affiliated"
|
url?: string; // "https://help.twitter.com/rules-and-policies/state-affiliated"
|
||||||
urlType: string; // "DeepLink"
|
urlType: string; // "DeepLink"
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
business_account: {
|
business_account: {
|
||||||
affiliates_count?: 20
|
affiliates_count?: 20;
|
||||||
}
|
};
|
||||||
is_blue_verified: boolean; // false,
|
is_blue_verified: boolean; // false,
|
||||||
profile_image_shape: 'Circle' | 'Square'|'Hexagon'; // "Circle",
|
profile_image_shape: 'Circle' | 'Square' | 'Hexagon'; // "Circle",
|
||||||
has_nft_avatar: boolean; // false,
|
has_nft_avatar: boolean; // false,
|
||||||
legacy: {
|
legacy: {
|
||||||
created_at: string; // "Tue Feb 20 14:35:54 +0000 2007",
|
created_at: string; // "Tue Feb 20 14:35:54 +0000 2007",
|
||||||
default_profile: boolean // false,
|
default_profile: boolean; // false,
|
||||||
default_profile_image: boolean // false,
|
default_profile_image: boolean; // false,
|
||||||
description: string; // "What's happening?!",
|
description: string; // "What's happening?!",
|
||||||
entities: {
|
entities: {
|
||||||
description?: {
|
description?: {
|
||||||
|
@ -235,14 +235,11 @@ type GraphQLUser = {
|
||||||
display_url: string; // "about.twitter.com",
|
display_url: string; // "about.twitter.com",
|
||||||
expanded_url: string; // "https://about.twitter.com/",
|
expanded_url: string; // "https://about.twitter.com/",
|
||||||
url: string; // "https://t.co/DAtOo6uuHk",
|
url: string; // "https://t.co/DAtOo6uuHk",
|
||||||
indices: [
|
indices: [0, 23];
|
||||||
0,
|
}[];
|
||||||
23
|
};
|
||||||
]
|
};
|
||||||
}[]
|
fast_followers_count: 0;
|
||||||
}
|
|
||||||
},
|
|
||||||
fast_followers_count: 0,
|
|
||||||
favourites_count: number; // 126708,
|
favourites_count: number; // 126708,
|
||||||
followers_count: number; // 4996,
|
followers_count: number; // 4996,
|
||||||
friends_count: number; // 2125,
|
friends_count: number; // 2125,
|
||||||
|
@ -262,20 +259,20 @@ type GraphQLUser = {
|
||||||
statuses_count: number; // 15047
|
statuses_count: number; // 15047
|
||||||
translator_type: string; // "regular"
|
translator_type: string; // "regular"
|
||||||
verified: boolean; // false
|
verified: boolean; // false
|
||||||
verified_type: 'Business'|'Government';
|
verified_type: 'Business' | 'Government';
|
||||||
withheld_in_countries: []
|
withheld_in_countries: [];
|
||||||
},
|
};
|
||||||
professional: {
|
professional: {
|
||||||
rest_id: string; // "1503055759638159366",
|
rest_id: string; // "1503055759638159366",
|
||||||
professional_type: string; // "Creator",
|
professional_type: string; // "Creator",
|
||||||
category: [
|
category: [
|
||||||
{
|
{
|
||||||
id: number; // 354,
|
id: number; // 354,
|
||||||
name: string // "Community",
|
name: string; // "Community",
|
||||||
icon_name: string; // "IconBriefcaseStroke"
|
icon_name: string; // "IconBriefcaseStroke"
|
||||||
}
|
}
|
||||||
]
|
];
|
||||||
},
|
};
|
||||||
legacy_extended_profile: {
|
legacy_extended_profile: {
|
||||||
birthdate?: {
|
birthdate?: {
|
||||||
day: number; // 7,
|
day: number; // 7,
|
||||||
|
@ -286,8 +283,8 @@ type GraphQLUser = {
|
||||||
};
|
};
|
||||||
profile_image_shape: string; // "Circle",
|
profile_image_shape: string; // "Circle",
|
||||||
rest_id: string; // "783214",
|
rest_id: string; // "783214",
|
||||||
},
|
};
|
||||||
is_profile_translatable: false,
|
is_profile_translatable: false;
|
||||||
verification_info: {
|
verification_info: {
|
||||||
reason: {
|
reason: {
|
||||||
description: {
|
description: {
|
||||||
|
@ -299,9 +296,10 @@ type GraphQLUser = {
|
||||||
};
|
};
|
||||||
to_index: number; // 108
|
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';
|
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";
|
||||||
}
|
};
|
||||||
|
};
|
||||||
}
|
};
|
||||||
|
};
|
||||||
|
|
4
src/types/types.d.ts
vendored
4
src/types/types.d.ts
vendored
|
@ -165,6 +165,6 @@ interface APIUser extends BaseUser {
|
||||||
birthday: {
|
birthday: {
|
||||||
day?: number;
|
day?: number;
|
||||||
month?: number;
|
month?: number;
|
||||||
year?: number
|
year?: number;
|
||||||
}
|
};
|
||||||
}
|
}
|
|
@ -48,9 +48,7 @@ export const handleProfile = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Base headers included in all responses */
|
/* Base headers included in all responses */
|
||||||
const headers = [
|
const headers = [`<meta property="twitter:site" content="@${user.screen_name}"/>`];
|
||||||
`<meta property="twitter:site" content="@${user.screen_name}"/>`,
|
|
||||||
];
|
|
||||||
|
|
||||||
// TODO Add card creation logic here
|
// TODO Add card creation logic here
|
||||||
|
|
||||||
|
|
|
@ -191,7 +191,6 @@ test('API fetch multi-photo Tweet', async () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test('API fetch poll Tweet', async () => {
|
test('API fetch poll Tweet', async () => {
|
||||||
const result = await cacheWrapper(
|
const result = await cacheWrapper(
|
||||||
new Request('https://api.fxtwitter.com/status/1055475950543167488', {
|
new Request('https://api.fxtwitter.com/status/1055475950543167488', {
|
||||||
|
|
Loading…
Add table
Reference in a new issue