import { Body, Button, Column, Input, Label, Row } from "./domlink.ts"; import { DidDocument } from "@atcute/identity"; let input_source_pds = [ "pds.tgirl.cloud", "pds.witchcraft.systems" ]; let view_pds_accounts = new Row(); type listReposItem = { active: boolean; did: string; head: string; rev: string; }; type listReposResponse = { cursor: string; repos: [listReposItem]; }; type repoDescriptor = { collections: [string]; did: string; didDoc: DidDocument; // would have crammed it in here but i dont really want to figure this out handle: string; handleIsCorrect: boolean; } async function xcall(host: string, method: string, params: Record | null = null): Promise { let url = `https://${host}/xrpc/${method}`; if (params) { let usp = new URLSearchParams(); for (let key in params) { usp.append(key, params[key].toString()); } url += "?" + usp.toString(); } return await (await fetch(url)).json(); } async function listActiveUsers(host: string) { let rsp = await xcall(host, "com.atproto.sync.listRepos", { limit: 100 }) as listReposResponse; let view_pds = new Column(); view_pds.add(`=== ${host.toUpperCase()} ===`); Body.add(view_pds); rsp.repos.filter(x=>x.active).forEach(async repo=>{ let view_pds_account = new Label(""); let rsp = await xcall(host, "com.atproto.repo.describeRepo", { repo: repo.did }) as repoDescriptor; if (!rsp.handleIsCorrect) { rsp.handle += "⚠️ "; } view_pds_account.text += rsp.handle; view_pds.add(view_pds_account); }); return view_pds; } let hostInput = new Input(); let last: any; let runButton = new Button("GO!",async ()=>{ (runButton.wraps as HTMLButtonElement).disabled = true; if (last) { Body.delete(last); } try { last = await listActiveUsers(hostInput.value); } catch (e) { last = new Label("Failed"); Body.add(last); } console.log(last); (runButton.wraps as HTMLButtonElement).disabled = false; }); Body.add(new Row().with( "List 100 active users on PDS: ", hostInput, runButton ));