atmosphere explorer pds.ls
tool typescript atproto
428
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix duplicate pds resolution

Juliet debdec52 15507075

+26 -20
+26 -20
src/lib/api.ts
··· 78 78 }), 79 79 ); 80 80 81 - const didPDSCache: Record<string, string> = {}; 81 + const didPDSCache: Record<string, Promise<string>> = {}; 82 82 const [labelerCache, setLabelerCache] = createStore<Record<string, string>>({}); 83 83 const didDocCache: Record<string, DidDocument> = {}; 84 - const getPDS = async (did: string) => { 84 + const getPDS = (did: string): Promise<string> => { 85 85 if (did in didPDSCache) return didPDSCache[did]; 86 86 87 87 if (!isAtprotoDid(did)) { 88 - throw new Error("Not a valid DID identifier"); 88 + return Promise.reject(new Error("Not a valid DID identifier")); 89 89 } 90 90 91 - let doc: DidDocument; 92 - try { 93 - doc = await didDocumentResolver().resolve(did); 94 - didDocCache[did] = doc; 95 - } catch (e) { 96 - console.error(e); 97 - throw new Error("Error during did document resolution"); 98 - } 91 + didPDSCache[did] = (async () => { 92 + let doc: DidDocument; 93 + try { 94 + doc = await didDocumentResolver().resolve(did); 95 + didDocCache[did] = doc; 96 + } catch (e) { 97 + console.error(e); 98 + delete didPDSCache[did]; 99 + throw new Error("Error during did document resolution"); 100 + } 99 101 100 - const pds = getPdsEndpoint(doc); 101 - const labeler = getLabelerEndpoint(doc); 102 + const pds = getPdsEndpoint(doc); 103 + const labeler = getLabelerEndpoint(doc); 102 104 103 - if (labeler) { 104 - setLabelerCache(did, labeler); 105 - } 105 + if (labeler) { 106 + setLabelerCache(did, labeler); 107 + } 108 + 109 + if (!pds) { 110 + delete didPDSCache[did]; 111 + throw new Error("No PDS found"); 112 + } 106 113 107 - if (!pds) { 108 - throw new Error("No PDS found"); 109 - } 114 + return pds; 115 + })(); 110 116 111 - return (didPDSCache[did] = pds); 117 + return didPDSCache[did]; 112 118 }; 113 119 114 120 const resolveHandle = async (handle: Handle) => {