an attempt to make a lightweight, easily self-hostable, scoped bluesky appview
at main 96 lines 2.4 kB view raw
1import { genericIndexServer } from "../main-index.ts"; 2import { config } from "../config.ts" 3import { FINEPDSAndHandleFromDid } from "../utils/identity.ts"; 4 5 6const collections = [ 7 "app.bsky.actor.profile", 8 "app.bsky.feed.generator", 9 "app.bsky.feed.like", 10 "app.bsky.feed.post", 11 "app.bsky.feed.repost", 12 "app.bsky.feed.threadgate", 13 "app.bsky.graph.block", 14 "app.bsky.graph.follow", 15 "app.bsky.graph.list", 16 "app.bsky.graph.listblock", 17 "app.bsky.graph.listitem", 18 "app.bsky.notification.declaration", 19]; 20 21export async function fetchAllRecordsForDID(did: string) { 22 const pdshandle = await FINEPDSAndHandleFromDid(did); 23 const pds = pdshandle?.pds; 24 if (!pds) return new Error("not an atproto user (missing PDS)") 25 26 for (const collection of collections) { 27 let cursor: string | undefined = undefined; 28 29 while (true) { 30 const url = new URL(`${pds}/xrpc/com.atproto.repo.listRecords`); 31 url.searchParams.set("repo", did); 32 url.searchParams.set("collection", collection); 33 if (cursor) url.searchParams.set("cursor", cursor); 34 35 const res = await fetch(url.toString(), { 36 headers: { Accept: "application/json" }, 37 }); 38 39 if (!res.ok) { 40 console.warn( 41 `[ERROR] Fetching ${collection} failed for DID ${did}: ${res.status}` 42 ); 43 break; 44 } 45 46 const data: { 47 cursor?: string; 48 records: { uri: string; cid: string; value: any }[]; 49 } = await res.json(); 50 51 for (const record of data.records) { 52 handleOnboardingBackfill(did, collection, record.uri, record.value); 53 } 54 55 if (!data.cursor) break; 56 cursor = data.cursor; 57 } 58 } 59} 60 61function handleOnboardingBackfill( 62 did: string, 63 collection: string, 64 uri: string, 65 value: any 66): void { 67 const op = "create"; 68 const doer = did; 69 const rev = undefined; 70 const aturi = uri; 71 const db = genericIndexServer.userManager.getDbForDid(doer); 72 if (!db) return; 73 74 genericIndexServer.indexServerIndexer({ 75 op, 76 doer, 77 rev, 78 aturi, 79 value, 80 indexsrc: "onboarding_backfill", 81 db: db, 82 }) 83 return; 84 // console.log(`[BACKFILL] ${collection} -> ${uri}`); 85 86 // const record = validateRecord(value); 87 // switch (record?.$type) { 88 // case "app.bsky.feed.like": { 89 // return; 90 // } 91 // default: { 92 // // what the hell 93 // return; 94 // } 95 // } 96}