Skip to content

Commit

Permalink
feat(route/twitter): only apply third-party api supported routes
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Dec 10, 2024
1 parent 17e2fc7 commit 844e658
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/routes/twitter/api/web-api/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const graphQLEndpointsPlain = [

const gqlMap = Object.fromEntries(graphQLEndpointsPlain.map((endpoint) => [endpoint.split('/')[3].replace(/V2$|Query$|QueryV2$/, ''), endpoint]));

const thirdPartySupportedAPI = ['UserByScreenName', 'UserByRestId', 'UserTweets', 'UserTweetsAndReplies'];

const gqlFeatureUser = {
hidden_profile_subscriptions_enabled: true,
rweb_tipjar_consumption_enabled: true,
Expand Down Expand Up @@ -112,4 +114,4 @@ const timelineParams = {

const bearerToken = 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA';

export { baseUrl, gqlMap, gqlFeatures, timelineParams, bearerToken };
export { baseUrl, gqlMap, gqlFeatures, timelineParams, bearerToken, thirdPartySupportedAPI };
4 changes: 2 additions & 2 deletions lib/routes/twitter/api/web-api/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ConfigNotFoundError from '@/errors/types/config-not-found';
import { baseUrl, gqlFeatures, bearerToken, gqlMap } from './constants';
import { baseUrl, gqlFeatures, bearerToken, gqlMap, thirdPartySupportedAPI } from './constants';
import { config } from '@/config';
import queryString from 'query-string';
import { Cookie, CookieJar } from 'tough-cookie';
Expand Down Expand Up @@ -228,7 +228,7 @@ export const paginationTweets = async (endpoint: string, userId: number | undefi
};

const fetchData = async () => {
if (config.twitter.thirdPartyApi) {
if (config.twitter.thirdPartyApi && thirdPartySupportedAPI.includes(endpoint)) {
const { data } = await ofetch(`${config.twitter.thirdPartyApi}${gqlMap[endpoint]}`, {
method: 'GET',
params,
Expand Down
6 changes: 5 additions & 1 deletion lib/routes/twitter/keyword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const route: Route = {
name: 'TWITTER_AUTH_TOKEN',
description: 'Please see above for details.',
},
{
name: 'TWITTER_THIRD_PARTY_API',
description: 'Please see above for details.',
},
],
requirePuppeteer: false,
antiCrawler: false,
Expand All @@ -30,7 +34,7 @@ export const route: Route = {
supportScihub: false,
},
name: 'Keyword',
maintainers: ['DIYgod', 'yindaheng98', 'Rongronggg9'],
maintainers: ['DIYgod', 'yindaheng98', 'Rongronggg9', 'pseudoyu'],
handler,
radar: [
{
Expand Down

0 comments on commit 844e658

Please sign in to comment.