|
1 | | -import { baseUrl, gqlMap, gqlFeatures } from './constants'; |
| 1 | +import { baseUrl, gqlMap, gqlFeatures, gqlMapThirdParty } from './constants'; |
2 | 2 | import { config } from '@/config'; |
3 | 3 | import cache from '@/utils/cache'; |
4 | 4 | import { twitterGot, paginationTweets, gatherLegacyFromData } from './utils'; |
5 | 5 | import InvalidParameterError from '@/errors/types/invalid-parameter'; |
| 6 | +import ofetch from '@/utils/ofetch'; |
6 | 7 |
|
7 | 8 | const getUserData = (id) => |
8 | 9 | cache.tryGet(`twitter-userdata-${id}`, () => { |
9 | | - if (id.startsWith('+')) { |
10 | | - return twitterGot(`${baseUrl}${gqlMap.UserByRestId}`, { |
11 | | - variables: JSON.stringify({ |
12 | | - userId: id.slice(1), |
13 | | - withSafetyModeUserFields: true, |
14 | | - }), |
15 | | - features: JSON.stringify(gqlFeatures.UserByRestId), |
16 | | - fieldToggles: JSON.stringify({ |
17 | | - withAuxiliaryUserLabels: false, |
18 | | - }), |
| 10 | + const params = { |
| 11 | + variables: id.startsWith('+') |
| 12 | + ? JSON.stringify({ |
| 13 | + userId: id.slice(1), |
| 14 | + withSafetyModeUserFields: true, |
| 15 | + }) |
| 16 | + : JSON.stringify({ |
| 17 | + screen_name: id, |
| 18 | + withSafetyModeUserFields: true, |
| 19 | + }), |
| 20 | + features: JSON.stringify(id.startsWith('+') ? gqlFeatures.UserByRestId : gqlFeatures.UserByScreenName), |
| 21 | + fieldToggles: JSON.stringify({ |
| 22 | + withAuxiliaryUserLabels: false, |
| 23 | + }), |
| 24 | + }; |
| 25 | + |
| 26 | + if (config.twitter.thirdPartyApi) { |
| 27 | + const endpoint = id.startsWith('+') ? gqlMapThirdParty.UserByRestId : gqlMapThirdParty.UserByScreenName; |
| 28 | + |
| 29 | + return ofetch(`${config.twitter.thirdPartyApi}${endpoint}`, { |
| 30 | + method: 'GET', |
| 31 | + params, |
19 | 32 | }); |
20 | 33 | } |
21 | | - return twitterGot( |
22 | | - `${baseUrl}${gqlMap.UserByScreenName}`, |
23 | | - { |
24 | | - variables: JSON.stringify({ |
25 | | - screen_name: id, |
26 | | - withSafetyModeUserFields: true, |
27 | | - }), |
28 | | - features: JSON.stringify(gqlFeatures.UserByScreenName), |
29 | | - fieldToggles: JSON.stringify({ |
30 | | - withAuxiliaryUserLabels: false, |
31 | | - }), |
32 | | - }, |
33 | | - { |
34 | | - allowNoAuth: true, |
35 | | - } |
36 | | - ); |
| 34 | + |
| 35 | + return twitterGot(`${baseUrl}${id.startsWith('+') ? gqlMap.UserByRestId : gqlMap.UserByScreenName}`, params, { |
| 36 | + allowNoAuth: !id.startsWith('+'), |
| 37 | + }); |
37 | 38 | }); |
38 | 39 |
|
39 | 40 | const cacheTryGet = async (_id, params, func) => { |
|
0 commit comments