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"> 60 <A 61 href={`/at://${repo.did}`} 62 class="grow truncate rounded py-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-lg 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-neutral-50 p-3 wrap-break-word shadow-md transition-opacity duration-200 sm:max-w-lg dark:border-neutral-700 starting:opacity-0"> 79 <div class="mb-1 flex justify-between gap-2"> 80 <div class="flex items-center gap-1"> 81 <span class="iconify lucide--info"></span> 82 <span class="font-semibold">{repo.did}</span> 83 </div> 84 <button 85 onclick={() => setOpenInfo(false)} 86 class="flex items-center rounded-lg p-1 hover:bg-neutral-200 active:bg-neutral-300 dark:hover:bg-neutral-700 dark:active:bg-neutral-600" 87 > 88 <span class="iconify lucide--x"></span> 89 </button> 90 </div> 91 <div class="flex flex-col text-sm"> 92 <span> 93 Head: <span class="text-xs">{repo.head}</span> 94 </span> 95 <Show when={TID.validate(repo.rev)}> 96 <span> 97 Rev: {repo.rev} ({localDateFromTimestamp(TID.parse(repo.rev).timestamp / 1000)}) 98 </span> 99 </Show> 100 <Show when={repo.active !== undefined}> 101 <span>Active: {repo.active ? "true" : "false"}</span> 102 </Show> 103 <Show when={repo.status}> 104 <span>Status: {repo.status}</span> 105 </Show> 106 </div> 107 </div> 108 </Modal> 109 </div> 110 ); 111 }; 112 113 const Tab = (props: { tab: "repos" | "info"; label: string }) => ( 114 <div class="flex items-center gap-0.5"> 115 <A 116 classList={{ 117 "flex items-center gap-1 border-b-2": true, 118 "border-transparent hover:border-neutral-400 dark:hover:border-neutral-600": 119 (!!location.hash && location.hash !== `#${props.tab}`) || 120 (!location.hash && props.tab !== "repos"), 121 }} 122 href={`/${params.pds}#${props.tab}`} 123 > 124 {props.label} 125 </A> 126 </div> 127 ); 128 129 return ( 130 <Show when={repos() || response()}> 131 <div class="flex w-full flex-col"> 132 <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"> 133 <div class="ml-1 flex gap-3"> 134 <Tab tab="repos" label="Repositories" /> 135 <Tab tab="info" label="Info" /> 136 </div> 137 <MenuProvider> 138 <DropdownMenu 139 icon="lucide--ellipsis-vertical" 140 buttonClass="rounded-sm p-1.5" 141 menuClass="top-9 p-2 text-sm" 142 > 143 <CopyMenu content={params.pds!} label="Copy PDS" icon="lucide--copy" /> 144 <NavMenu 145 href={`/firehose?instance=wss://${params.pds}`} 146 label="Firehose" 147 icon="lucide--radio-tower" 148 /> 149 </DropdownMenu> 150 </MenuProvider> 151 </div> 152 <div class="flex flex-col gap-1 px-2"> 153 <Show when={!location.hash || location.hash === "#repos"}> 154 <div class="flex flex-col divide-y-[0.5px] divide-neutral-300 dark:divide-neutral-700"> 155 <For each={repos()}>{(repo) => <RepoCard {...repo} />}</For> 156 </div> 157 </Show> 158 <Show when={location.hash === "#info"}> 159 <Show when={version()}> 160 {(version) => ( 161 <div class="flex items-baseline gap-x-1"> 162 <span class="font-semibold">Version</span> 163 <span class="truncate text-sm">{version()}</span> 164 </div> 165 )} 166 </Show> 167 <Show when={serverInfos()}> 168 {(server) => ( 169 <> 170 <div class="flex items-baseline gap-x-1"> 171 <span class="font-semibold">DID</span> 172 <span class="truncate text-sm">{server().did}</span> 173 </div> 174 <Show when={server().inviteCodeRequired}> 175 <span class="font-semibold">Invite Code Required</span> 176 </Show> 177 <Show when={server().phoneVerificationRequired}> 178 <span class="font-semibold">Phone Verification Required</span> 179 </Show> 180 <Show when={server().availableUserDomains.length}> 181 <div class="flex flex-col"> 182 <span class="font-semibold">Available User Domains</span> 183 <For each={server().availableUserDomains}> 184 {(domain) => <span class="text-sm wrap-anywhere">{domain}</span>} 185 </For> 186 </div> 187 </Show> 188 <Show when={server().links?.privacyPolicy}> 189 <div class="flex flex-col"> 190 <span class="font-semibold">Privacy Policy</span> 191 <a 192 href={server().links?.privacyPolicy} 193 class="text-sm hover:underline" 194 target="_blank" 195 rel="noopener" 196 > 197 {server().links?.privacyPolicy} 198 </a> 199 </div> 200 </Show> 201 <Show when={server().links?.termsOfService}> 202 <div class="flex flex-col"> 203 <span class="font-semibold">Terms of Service</span> 204 <a 205 href={server().links?.termsOfService} 206 class="text-sm hover:underline" 207 target="_blank" 208 rel="noopener" 209 > 210 {server().links?.termsOfService} 211 </a> 212 </div> 213 </Show> 214 <Show when={server().contact?.email}> 215 <div class="flex flex-col"> 216 <span class="font-semibold">Contact</span> 217 <a href={`mailto:${server().contact?.email}`} class="text-sm hover:underline"> 218 {server().contact?.email} 219 </a> 220 </div> 221 </Show> 222 </> 223 )} 224 </Show> 225 </Show> 226 </div> 227 </div> 228 <Show when={!location.hash || location.hash === "#repos"}> 229 <div class="dark:bg-dark-500 fixed bottom-0 z-5 flex w-screen justify-center bg-neutral-100 py-2"> 230 <div class="flex flex-col items-center gap-1 pb-2"> 231 <p>{repos()?.length} loaded</p> 232 <Show when={!response.loading && cursor()}> 233 <Button onClick={() => refetch()}>Load More</Button> 234 </Show> 235 <Show when={response.loading}> 236 <span class="iconify lucide--loader-circle animate-spin py-3.5 text-xl"></span> 237 </Show> 238 </div> 239 </div> 240 </Show> 241 </Show> 242 ); 243}; 244 245export { PdsView };