feat(twitter): add UserMedia support and enhance pagination logic

This commit is contained in:
DIYgod
2025-12-01 22:57:09 +08:00
parent 295a4f845e
commit 7f5ae64a2f
3 changed files with 7 additions and 17 deletions
+4 -15
View File
@@ -84,21 +84,10 @@ const getUserTweetsAndReplies = (id: string, params?: Record<string, any>) =>
);
const getUserMedia = (id: string, params?: Record<string, any>) =>
cacheTryGet(id, params, async (id, params = {}) => {
const cursorSource = await paginationTweets('UserMedia', id, {
...params,
count: 20,
includePromotedContent: false,
withClientEventToken: false,
withBirdwatchNotes: false,
withVoice: true,
withV2Timeline: true,
});
const cursor = cursorSource.find((i) => i.content?.cursorType === 'Top').content.value;
return gatherLegacyFromData(
cacheTryGet(id, params, async (id, params = {}) =>
gatherLegacyFromData(
await paginationTweets('UserMedia', id, {
...params,
cursor,
count: 20,
includePromotedContent: false,
withClientEventToken: false,
@@ -106,8 +95,8 @@ const getUserMedia = (id: string, params?: Record<string, any>) =>
withVoice: true,
withV2Timeline: true,
})
);
});
)
);
const getUserLikes = (id: string, params?: Record<string, any>) =>
cacheTryGet(id, params, async (id, params = {}) =>
+1 -1
View File
@@ -15,7 +15,7 @@ const graphQLEndpointsPlain = [
const gqlMap = Object.fromEntries(graphQLEndpointsPlain.map((endpoint) => [endpoint.split('/')[3].replace(/V2$|Query$|QueryV2$/, ''), endpoint]));
const thirdPartySupportedAPI = ['UserByScreenName', 'UserByRestId', 'UserTweets', 'UserTweetsAndReplies', 'ListLatestTweetsTimeline', 'SearchTimeline'];
const thirdPartySupportedAPI = ['UserByScreenName', 'UserByRestId', 'UserTweets', 'UserTweetsAndReplies', 'ListLatestTweetsTimeline', 'SearchTimeline', 'UserMedia'];
const gqlFeatureUser = {
hidden_profile_subscriptions_enabled: true,
+2 -1
View File
@@ -270,8 +270,9 @@ export const paginationTweets = async (endpoint: string, userId: number | undefi
const moduleItems = instructions.find((i) => i.type === 'TimelineAddToModule')?.moduleItems;
const entries = instructions.find((i) => i.type === 'TimelineAddEntries')?.entries;
const gridEntries = entries.find((i) => i.entryId === 'profile-grid-0')?.content?.items;
return moduleItems || entries || [];
return gridEntries || moduleItems || entries || [];
};
export function gatherLegacyFromData(entries: any[], filterNested?: string[], userId?: number | string) {