atmosphere explorer
0
fork

Configure Feed

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

move functions

+31 -33
+31 -7
src/App.tsx
··· 15 15 useLocation, 16 16 useParams, 17 17 } from "@solidjs/router"; 18 - import { getPDS, resolveHandle } from "./utils/api.js"; 19 18 import { JSONValue } from "./lib/json.jsx"; 20 19 import { AiFillGithub, Bluesky, TbMoonStar, TbSun } from "./lib/svg.jsx"; 21 20 22 - let rpc: XRPC; 21 + let rpc = new XRPC({ 22 + handler: new CredentialManager({ service: "https://public.api.bsky.app" }), 23 + }); 23 24 const [notice, setNotice] = createSignal(""); 24 25 const [pds, setPDS] = createSignal<string>(); 26 + 27 + const getPDS = query(async (did: string) => { 28 + const res = await fetch( 29 + did.startsWith("did:web") ? 30 + `https://${did.split(":")[2]}/.well-known/did.json` 31 + : "https://plc.directory/" + did, 32 + ); 33 + 34 + return res.json().then((doc) => { 35 + for (const service of doc.service) { 36 + if (service.id === "#atproto_pds") return service.serviceEndpoint; 37 + } 38 + }); 39 + }, "getPDS"); 25 40 26 41 const processInput = action(async (formData: FormData) => { 27 42 const input = formData.get("input")?.toString(); ··· 41 56 .replace("/post/", "/app.bsky.feed.post/"); 42 57 let did = ""; 43 58 try { 44 - if (uri.startsWith("did:")) did = uri.split("/")[0]; 45 - else did = await resolveHandle(uri.split("/")[0]); 59 + did = uri.split("/")[0]; 60 + if (!uri.startsWith("did:")) { 61 + const res = await rpc.get("com.atproto.identity.resolveHandle", { 62 + params: { handle: uri.split("/")[0] }, 63 + }); 64 + did = res.data.did; 65 + } 46 66 if (!did) throw Error; 47 67 setPDS(await getPDS(did)); 48 68 } catch (err) { ··· 55 75 56 76 const resolvePDS = async (repo: string) => { 57 77 try { 58 - let did; 59 - if (repo.startsWith("did:")) did = repo; 60 - else did = await resolveHandle(repo); 78 + let did = repo; 79 + if (!repo.startsWith("did:")) { 80 + const res = await rpc.get("com.atproto.identity.resolveHandle", { 81 + params: { handle: repo }, 82 + }); 83 + did = res.data.did; 84 + } 61 85 if (!did) throw Error; 62 86 const pds = await getPDS(did); 63 87 setPDS(pds.replace("https://", ""));
-26
src/utils/api.ts
··· 1 - import { query } from "@solidjs/router"; 2 - 3 - const getPDS = query(async (did: string) => { 4 - const res = await fetch( 5 - did.startsWith("did:web") ? 6 - `https://${did.split(":")[2]}/.well-known/did.json` 7 - : "https://plc.directory/" + did, 8 - ); 9 - 10 - return res.json().then((doc) => { 11 - for (const service of doc.service) { 12 - if (service.id === "#atproto_pds") return service.serviceEndpoint; 13 - } 14 - }); 15 - }, "getPDS"); 16 - 17 - const resolveHandle = query(async (handle: string) => { 18 - const res = await fetch( 19 - `https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle?handle=` + 20 - handle, 21 - ); 22 - 23 - return res.json().then((json) => json.did); 24 - }, "resolveHandle"); 25 - 26 - export { getPDS, resolveHandle };