import { genericIndexServer } from "../main-index.ts"; import { config } from "../config.ts" import { FINEPDSAndHandleFromDid } from "../utils/identity.ts"; const collections = [ "app.bsky.actor.profile", "app.bsky.feed.generator", "app.bsky.feed.like", "app.bsky.feed.post", "app.bsky.feed.repost", "app.bsky.feed.threadgate", "app.bsky.graph.block", "app.bsky.graph.follow", "app.bsky.graph.list", "app.bsky.graph.listblock", "app.bsky.graph.listitem", "app.bsky.notification.declaration", ]; export async function fetchAllRecordsForDID(did: string) { const pdshandle = await FINEPDSAndHandleFromDid(did); const pds = pdshandle?.pds; if (!pds) return new Error("not an atproto user (missing PDS)") for (const collection of collections) { let cursor: string | undefined = undefined; while (true) { const url = new URL(`${pds}/xrpc/com.atproto.repo.listRecords`); url.searchParams.set("repo", did); url.searchParams.set("collection", collection); if (cursor) url.searchParams.set("cursor", cursor); const res = await fetch(url.toString(), { headers: { Accept: "application/json" }, }); if (!res.ok) { console.warn( `[ERROR] Fetching ${collection} failed for DID ${did}: ${res.status}` ); break; } const data: { cursor?: string; records: { uri: string; cid: string; value: any }[]; } = await res.json(); for (const record of data.records) { handleOnboardingBackfill(did, collection, record.uri, record.value); } if (!data.cursor) break; cursor = data.cursor; } } } function handleOnboardingBackfill( did: string, collection: string, uri: string, value: any ): void { const op = "create"; const doer = did; const rev = undefined; const aturi = uri; const db = genericIndexServer.userManager.getDbForDid(doer); if (!db) return; genericIndexServer.indexServerIndexer({ op, doer, rev, aturi, value, indexsrc: "onboarding_backfill", db: db, }) return; // console.log(`[BACKFILL] ${collection} -> ${uri}`); // const record = validateRecord(value); // switch (record?.$type) { // case "app.bsky.feed.like": { // return; // } // default: { // // what the hell // return; // } // } }