Created
December 21, 2024 04:31
-
-
Save YonatanKra/1ba66ef769e0ed54ef98635be0a0bb75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async streamPosts(handle: string, onUpdate: (results: any) => any) { | |
while (true) { | |
try { | |
const result = await this.#agent.getAuthorFeed({ | |
actor: handle, | |
limit: 20, | |
cursor: undefined, | |
filter: 'posts_with_media' | |
}); | |
if (!result.data?.feed?.length) { | |
console.log('No more posts'); | |
onUpdate({ done: true }); | |
break; | |
} | |
onUpdate({result: result.data.feed, done: !result.data.cursor}); | |
if (!result.data.cursor) { | |
break; | |
} | |
} catch (e) { | |
await new Promise(res => setTimeout(res, 5000)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment