mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-28 05:25:33 +00:00
fix(extension): paginate Twitter bookmark-folder imports past the first page (#1269)
This commit is contained in:
parent
90f709bf8d
commit
fa16e853a8
2 changed files with 20 additions and 16 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue