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