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