atproto explorer pdsls.dev
atproto tool
1import { ComAtprotoServerDescribeServer, ComAtprotoSyncListRepos } from "@atcute/atproto"; 2import { Client, CredentialManager } from "@atcute/client"; 3import { InferXRPCBodyOutput } from "@atcute/lexicons"; 4import * as TID from "@atcute/tid"; 5import { A, useLocation, useParams } from "@solidjs/router"; 6import { createResource, createSignal, For, Show } from "solid-js"; 7import { Button } from "../components/button"; 8import { CopyMenu, DropdownMenu, MenuProvider, NavMenu } from "../components/dropdown"; 9import { Modal } from "../components/modal"; 10import { setPDS } from "../components/navbar"; 11import Tooltip from "../components/tooltip"; 12import { localDateFromTimestamp } from "../utils/date"; 13 14const LIMIT = 1000; 15 16const PdsView = () => { 17 const params = useParams(); 18 const location = useLocation(); 19 const [version, setVersion] = createSignal<string>(); 20 const [serverInfos, setServerInfos] = 21 createSignal<InferXRPCBodyOutput<ComAtprotoServerDescribeServer.mainSchema["output"]>>(); 22 const [cursor, setCursor] = createSignal<string>(); 23 setPDS(params.pds); 24 const pds = 25 params.pds!.startsWith("localhost") ? `http://${params.pds}` : `https://${params.pds}`; 26 const rpc = new Client({ handler: new CredentialManager({ service: pds }) }); 27 28 const getVersion = async () => { 29 // @ts-expect-error: undocumented endpoint 30 const res = await rpc.get("_health", {}); 31 setVersion((res.data as any).version); 32 }; 33 34 const describeServer = async () => { 35 const res = await rpc.get("com.atproto.server.describeServer"); 36 if (!res.ok) console.error(res.data.error); 37 else setServerInfos(res.data); 38 }; 39 40 const fetchRepos = async () => { 41 getVersion(); 42 describeServer(); 43 const res = await rpc.get("com.atproto.sync.listRepos", { 44 params: { limit: LIMIT, cursor: cursor() }, 45 }); 46 if (!res.ok) throw new Error(res.data.error); 47 setCursor(res.data.repos.length < LIMIT ? undefined : res.data.cursor); 48 setRepos(repos()?.concat(res.data.repos) ?? res.data.repos); 49 return res.data; 50 }; 51 52 const [response, { refetch }] = createResource(fetchRepos); 53 const [repos, setRepos] = createSignal<ComAtprotoSyncListRepos.Repo[]>(); 54 55 const RepoCard = (repo: ComAtprotoSyncListRepos.Repo) => { 56 const [openInfo, setOpenInfo] = createSignal(false); 57 58 return ( 59 <div class="flex items-center gap-0.5"> 60 <A 61 href={`/at://${repo.did}`} 62 class="grow truncate rounded-md p-0.5 font-mono hover:bg-neutral-200 active:bg-neutral-300 dark:hover:bg-neutral-700 dark:active:bg-neutral-600" 63 > 64 {repo.did} 65 </A> 66 <Show when={!repo.active}> 67 <Tooltip text={repo.status ?? "Unknown status"}> 68 <span class="iconify lucide--unplug text-red-500 dark:text-red-400"></span> 69 </Tooltip> 70 </Show> 71 <button 72 onclick={() => setOpenInfo(true)} 73 class="flex items-center rounded-md p-1.5 hover:bg-neutral-200 active:bg-neutral-300 dark:hover:bg-neutral-700 dark:active:bg-neutral-600" 74 > 75 <span class="iconify lucide--info"></span> 76 </button> 77 <Modal open={openInfo()} onClose={() => setOpenInfo(false)}> 78 <div class="dark:bg-dark-300 dark:shadow-dark-700 absolute top-70 left-[50%] w-max max-w-full -translate-x-1/2 rounded-lg border-[0.5px] border-neutral-300 bg-white p-3 shadow-md transition-opacity duration-200 sm:max-w-xl dark:border-neutral-700 starting:opacity-0"> 79 <div class="mb-2 flex items-center justify-between gap-4"> 80 <p class="truncate font-semibold">{repo.did}</p> 81 <button 82 onclick={() => setOpenInfo(false)} 83 class="flex shrink-0 items-center rounded-md p-1.5 text-neutral-500 hover:bg-neutral-100 hover:text-neutral-700 active:bg-neutral-200 dark:text-neutral-400 dark:hover:bg-neutral-700 dark:hover:text-neutral-200 dark:active:bg-neutral-600" 84 > 85 <span class="iconify lucide--x"></span> 86 </button> 87 </div> 88 <div class="grid grid-cols-[auto_1fr] items-baseline gap-x-1 text-sm"> 89 <span class="font-medium">Head:</span> 90 <span class="wrap-anywhere text-neutral-700 dark:text-neutral-300">{repo.head}</span> 91 92 <Show when={TID.validate(repo.rev)}> 93 <span class="font-medium">Rev:</span> 94 <div class="flex flex-col"> 95 <span class="text-neutral-700 dark:text-neutral-300">{repo.rev}</span> 96 <span class="text-neutral-600 dark:text-neutral-400"> 97 {localDateFromTimestamp(TID.parse(repo.rev).timestamp / 1000)} 98 </span> 99 </div> 100 </Show> 101 102 <Show when={repo.active !== undefined}> 103 <span class="font-medium">Active:</span> 104 <span 105 class={`iconify self-center ${ 106 repo.active ? 107 "lucide--check text-green-500 dark:text-green-400" 108 : "lucide--x text-red-500 dark:text-red-400" 109 }`} 110 ></span> 111 </Show> 112 113 <Show when={repo.status}> 114 <span class="font-medium">Status:</span> 115 <span class="text-neutral-700 dark:text-neutral-300">{repo.status}</span> 116 </Show> 117 </div> 118 </div> 119 </Modal> 120 </div> 121 ); 122 }; 123 124 const Tab = (props: { tab: "repos" | "info"; label: string }) => ( 125 <A 126 classList={{ 127 "border-b-2": true, 128 "border-transparent hover:border-neutral-400 dark:hover:border-neutral-600": 129 (!!location.hash && location.hash !== `#${props.tab}`) || 130 (!location.hash && props.tab !== "repos"), 131 }} 132 href={`/${params.pds}#${props.tab}`} 133 > 134 {props.label} 135 </A> 136 ); 137 138 return ( 139 <Show when={repos() || response()}> 140 <div class="flex w-full flex-col"> 141 <div class="dark:shadow-dark-700 dark:bg-dark-300 mb-2 flex w-full justify-between rounded-lg border-[0.5px] border-neutral-300 bg-neutral-50 p-2 text-sm shadow-xs dark:border-neutral-700"> 142 <div class="ml-1 flex items-center gap-3"> 143 <Tab tab="repos" label="Repositories" /> 144 <Tab tab="info" label="Info" /> 145 </div> 146 <MenuProvider> 147 <DropdownMenu 148 icon="lucide--ellipsis-vertical" 149 buttonClass="rounded-sm p-1.5" 150 menuClass="top-9 p-2 text-sm" 151 > 152 <CopyMenu content={params.pds!} label="Copy PDS" icon="lucide--copy" /> 153 <NavMenu 154 href={`/firehose?instance=wss://${params.pds}`} 155 label="Firehose" 156 icon="lucide--radio-tower" 157 /> 158 </DropdownMenu> 159 </MenuProvider> 160 </div> 161 <div class="flex flex-col gap-1 px-2"> 162 <Show when={!location.hash || location.hash === "#repos"}> 163 <div class="flex flex-col divide-y-[0.5px] divide-neutral-300 dark:divide-neutral-700"> 164 <For each={repos()}>{(repo) => <RepoCard {...repo} />}</For> 165 </div> 166 </Show> 167 <Show when={location.hash === "#info"}> 168 <Show when={version()}> 169 {(version) => ( 170 <div class="flex items-baseline gap-x-1"> 171 <span class="font-semibold">Version</span> 172 <span class="truncate text-sm">{version()}</span> 173 </div> 174 )} 175 </Show> 176 <Show when={serverInfos()}> 177 {(server) => ( 178 <> 179 <div class="flex items-baseline gap-x-1"> 180 <span class="font-semibold">DID</span> 181 <span class="truncate text-sm">{server().did}</span> 182 </div> 183 <Show when={server().inviteCodeRequired}> 184 <span class="font-semibold">Invite Code Required</span> 185 </Show> 186 <Show when={server().phoneVerificationRequired}> 187 <span class="font-semibold">Phone Verification Required</span> 188 </Show> 189 <Show when={server().availableUserDomains.length}> 190 <div class="flex flex-col"> 191 <span class="font-semibold">Available User Domains</span> 192 <For each={server().availableUserDomains}> 193 {(domain) => <span class="text-sm wrap-anywhere">{domain}</span>} 194 </For> 195 </div> 196 </Show> 197 <Show when={server().links?.privacyPolicy}> 198 <div class="flex flex-col"> 199 <span class="font-semibold">Privacy Policy</span> 200 <a 201 href={server().links?.privacyPolicy} 202 class="text-sm hover:underline" 203 target="_blank" 204 rel="noopener" 205 > 206 {server().links?.privacyPolicy} 207 </a> 208 </div> 209 </Show> 210 <Show when={server().links?.termsOfService}> 211 <div class="flex flex-col"> 212 <span class="font-semibold">Terms of Service</span> 213 <a 214 href={server().links?.termsOfService} 215 class="text-sm hover:underline" 216 target="_blank" 217 rel="noopener" 218 > 219 {server().links?.termsOfService} 220 </a> 221 </div> 222 </Show> 223 <Show when={server().contact?.email}> 224 <div class="flex flex-col"> 225 <span class="font-semibold">Contact</span> 226 <a href={`mailto:${server().contact?.email}`} class="text-sm hover:underline"> 227 {server().contact?.email} 228 </a> 229 </div> 230 </Show> 231 </> 232 )} 233 </Show> 234 </Show> 235 </div> 236 </div> 237 <Show when={!location.hash || location.hash === "#repos"}> 238 <div class="dark:bg-dark-500 fixed bottom-0 z-5 flex w-screen justify-center bg-neutral-100 py-2"> 239 <div class="flex flex-col items-center gap-1 pb-2"> 240 <p>{repos()?.length} loaded</p> 241 <Show when={!response.loading && cursor()}> 242 <Button onClick={() => refetch()}>Load More</Button> 243 </Show> 244 <Show when={response.loading}> 245 <span class="iconify lucide--loader-circle animate-spin py-3.5 text-xl"></span> 246 </Show> 247 </div> 248 </div> 249 </Show> 250 </Show> 251 ); 252}; 253 254export { PdsView };