diff --git a/src/lib/atproto/client.ts b/src/lib/atproto/client.ts index ad92d77..6bfc9c3 100644 --- a/src/lib/atproto/client.ts +++ b/src/lib/atproto/client.ts @@ -138,25 +138,31 @@ async function getJson2(url: string): Promise { return res.json(); } -/** Resolve a DID's PDS endpoint (did:plc via plc.directory). Cached. */ +/** Resolve a DID's PDS endpoint (did:plc via plc.directory). Cached. A failed lookup is retried + * once and NOT cached: caching null let one plc.directory blip strip every event thumbnail of + * that account for the rest of the build while the event cards themselves still rendered. */ export async function resolvePds(did: string): Promise { if (pdsCache.has(did)) return pdsCache.get(did) ?? null; - let pds: string | null = null; - try { - if (did.startsWith('did:plc:')) { + if (!did.startsWith('did:plc:')) { + pdsCache.set(did, null); + return null; + } + for (let attempt = 0; attempt < 2; attempt++) { + try { const doc = (await getJson2(`https://plc.directory/${did}`)) as { service?: Array<{ id?: string; type?: string; serviceEndpoint?: string }>; }; const svc = (doc.service ?? []).find( (s) => s.id?.endsWith('atproto_pds') || /pds/i.test(s.type ?? ''), ); - pds = svc?.serviceEndpoint ?? null; + const pds = svc?.serviceEndpoint ?? null; + pdsCache.set(did, pds); + return pds; + } catch { + if (attempt === 0) await new Promise((r) => setTimeout(r, 1000)); } - } catch { - pds = null; } - pdsCache.set(did, pds); - return pds; + return null; } /** List records of a collection straight from the repo's PDS (public, no auth). */