fix(extension): paginate Twitter bookmark-folder imports past the first page (#1269)

This commit is contained in:
Abhay Singh 2026-07-22 17:54:14 +05:30 committed by GitHub
parent 90f709bf8d
commit fa16e853a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 16 deletions

View file

@ -113,19 +113,14 @@ export class TwitterImporter {
const headers = createTwitterAPIHeaders(tokens)
// Build API request with pagination
const variables =
this.config.isFolderImport && this.config.bookmarkCollectionId
? buildBookmarkCollectionVariables(this.config.bookmarkCollectionId)
: buildRequestVariables(cursor)
const urlWithCursor = cursor
? `${
this.config.isFolderImport && this.config.bookmarkCollectionId
? `${BOOKMARK_COLLECTION_URL}&variables=${encodeURIComponent(JSON.stringify(variables))}`
: BOOKMARKS_URL
}&variables=${encodeURIComponent(JSON.stringify(variables))}`
: this.config.isFolderImport && this.config.bookmarkCollectionId
? `${BOOKMARK_COLLECTION_URL}&variables=${encodeURIComponent(JSON.stringify(variables))}`
: `${BOOKMARKS_URL}&variables=${encodeURIComponent(JSON.stringify(variables))}`
const collectionId = this.config.isFolderImport
? this.config.bookmarkCollectionId
: undefined
const variables = collectionId
? buildBookmarkCollectionVariables(collectionId, cursor)
: buildRequestVariables(cursor)
const baseUrl = collectionId ? BOOKMARK_COLLECTION_URL : BOOKMARKS_URL
const urlWithCursor = `${baseUrl}&variables=${encodeURIComponent(JSON.stringify(variables))}`
const response = await fetch(urlWithCursor, {
method: "GET",
@ -199,7 +194,7 @@ export class TwitterImporter {
[]
const nextCursor = extractNextCursor(instructions)
if (nextCursor && tweets.length > 0 && !this.config.isFolderImport) {
if (nextCursor && tweets.length > 0) {
await new Promise((resolve) => setTimeout(resolve, 1000)) // Rate limiting
await this.batchImportAll(nextCursor, importedCount, uniqueGroupId)
} else {

View file

@ -434,9 +434,18 @@ export function buildRequestVariables(cursor?: string, count = 100) {
/**
* Build Twitter API request variables for bookmark collection
*/
export function buildBookmarkCollectionVariables(bookmarkCollectionId: string) {
return {
export function buildBookmarkCollectionVariables(
bookmarkCollectionId: string,
cursor?: string,
) {
const variables: Record<string, unknown> = {
bookmark_collection_id: bookmarkCollectionId,
includePromotedContent: true,
}
if (cursor) {
variables.cursor = cursor
}
return variables
}