A personal website powered by Astro and ATProto

paginated api calls

Changed files
+32 -10
src
+27
src/lib/atproto/atproto-browser.ts
··· 140 140 } 141 141 } 142 142 143 + // Get all records from a collection using pagination 144 + async getAllCollectionRecords( 145 + identifier: string, 146 + collection: string, 147 + maxTotal: number = 1000 148 + ): Promise<AtprotoRecord[]> { 149 + const results: AtprotoRecord[] = []; 150 + let cursor: string | undefined = undefined; 151 + 152 + try { 153 + while (true) { 154 + const page = await this.getCollectionRecords(identifier, collection, 100, cursor); 155 + if (!page) break; 156 + 157 + results.push(...page.records); 158 + 159 + if (!page.cursor) break; 160 + if (results.length >= maxTotal) break; 161 + cursor = page.cursor; 162 + } 163 + } catch (error) { 164 + console.error(`Error paginating collection ${collection}:`, error); 165 + } 166 + 167 + return results.slice(0, maxTotal); 168 + } 169 + 143 170 // Get all collections for a repository 144 171 async getAllCollections(identifier: string): Promise<string[]> { 145 172 try {