@@ -222,32 +222,49 @@ export const twitterGot = async (
222222} ;
223223
224224export const paginationTweets = async ( endpoint : string , userId : number | undefined , variables : Record < string , any > , path ?: string [ ] ) => {
225- const { data } = await twitterGot ( baseUrl + gqlMap [ endpoint ] , {
226- variables : JSON . stringify ( {
227- ...variables ,
228- userId,
229- } ) ,
225+ const params = {
226+ variables : JSON . stringify ( { ...variables , userId } ) ,
230227 features : JSON . stringify ( gqlFeatures [ endpoint ] ) ,
231- } ) ;
232- let instructions ;
233- if ( path ) {
234- instructions = data ;
235- for ( const p of path ) {
236- instructions = instructions [ p ] ;
228+ } ;
229+
230+ const fetchData = async ( ) => {
231+ if ( config . twitter . thirdPartyApi ) {
232+ const { data } = await ofetch ( `${ config . twitter . thirdPartyApi } ${ gqlMap [ endpoint ] } ` , {
233+ method : 'GET' ,
234+ params,
235+ } ) ;
236+ return data ;
237237 }
238- instructions = instructions . instructions ;
239- } else {
240- if ( data ?. user ?. result ?. timeline_v2 ?. timeline ?. instructions ) {
241- instructions = data . user . result . timeline_v2 . timeline . instructions ;
242- } else {
243- // throw new Error('Because Twitter Premium has features that hide your likes, this RSS link is not available for Twitter Premium accounts.');
238+ const { data } = await twitterGot ( baseUrl + gqlMap [ endpoint ] , params ) ;
239+ return data ;
240+ } ;
241+
242+ const getInstructions = ( data : any ) => {
243+ if ( path ) {
244+ let instructions = data ;
245+ for ( const p of path ) {
246+ instructions = instructions [ p ] ;
247+ }
248+ return instructions . instructions ;
249+ }
250+
251+ const instructions = data ?. user ?. result ?. timeline_v2 ?. timeline ?. instructions ;
252+ if ( ! instructions ) {
244253 logger . debug ( `twitter debug: instructions not found in data: ${ JSON . stringify ( data ) } ` ) ;
245254 }
255+ return instructions ;
256+ } ;
257+
258+ const data = await fetchData ( ) ;
259+ const instructions = getInstructions ( data ) ;
260+ if ( ! instructions ) {
261+ return [ ] ;
246262 }
247263
248- const entries1 = instructions ?. find ( ( i ) => i . type === 'TimelineAddToModule' ) ?. moduleItems ; // Media
249- const entries2 = instructions ?. find ( ( i ) => i . type === 'TimelineAddEntries' ) . entries ;
250- return entries1 || entries2 || [ ] ;
264+ const moduleItems = instructions . find ( ( i ) => i . type === 'TimelineAddToModule' ) ?. moduleItems ;
265+ const entries = instructions . find ( ( i ) => i . type === 'TimelineAddEntries' ) ?. entries ;
266+
267+ return moduleItems || entries || [ ] ;
251268} ;
252269
253270export function gatherLegacyFromData ( entries : any [ ] , filterNested ?: string [ ] , userId ?: number | string ) {
0 commit comments