Skip to content

Commit 7f3202b

Browse files
authored
Fix pagination: fetch all existing ATProto documents via cursor-based pagination
1 parent c87dd2a commit 7f3202b

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

scripts/publish-episodes.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,28 @@ async function main() {
9999
console.log(`✅ Logged in as ${publisher.getDid()}`);
100100

101101
// Get existing documents to avoid duplicates
102-
const existingDocs = await publisher.listDocuments(100);
103-
const existingPaths = new Set(
104-
existingDocs
105-
.map((doc) => doc.value.path)
106-
.filter(Boolean)
107-
);
102+
const existingPaths = new Set<string>();
103+
let cursor: string | undefined;
104+
105+
// Paginate through all existing documents (ATProto caps at 100 per request)
106+
do {
107+
const agent = publisher.getAtpAgent();
108+
const response = await agent.api.com.atproto.repo.listRecords({
109+
repo: publisher.getDid(),
110+
collection: 'site.standard.document',
111+
limit: 100,
112+
cursor
113+
});
114+
115+
for (const record of response.data.records) {
116+
const doc = record.value as { path?: string };
117+
if (doc.path) {
118+
existingPaths.add(doc.path);
119+
}
120+
}
121+
122+
cursor = response.data.cursor;
123+
} while (cursor);
108124

109125
let published = 0;
110126
let skipped = 0;

0 commit comments

Comments
 (0)