[READ ONLY MIRROR] Spark Social AppView Server
github.com/sprksocial/server
atproto
deno
hono
lexicon
1import { mapDefined } from "@atp/common";
2import type { DatetimeString, HandleString, UnknownObject } from "@atp/lex";
3import { INVALID_HANDLE } from "@atp/syntax";
4import { Server } from "@atp/xrpc-server";
5
6import { AppContext } from "../../../../context.ts";
7import * as com from "../../../../lex/com.ts";
8import type { $OutputBody } from "../../../../lex/com/atproto/admin/getAccountInfos.ts";
9
10export default function (server: Server, ctx: AppContext) {
11 server.add(com.atproto.admin.getAccountInfos, {
12 auth: ctx.authVerifier.optionalStandardOrRole,
13 handler: async ({ params, auth }) => {
14 const { dids } = params;
15 const { includeTakedowns } = ctx.authVerifier.parseCreds(auth);
16
17 const actors = await ctx.hydrator.actor.getActors(dids, {
18 includeTakedowns: true,
19 });
20
21 const infos: $OutputBody["infos"] = mapDefined(dids, (did) => {
22 const info = actors.get(did);
23 if (!info) return;
24 if (info.takedownRef && !includeTakedowns) return;
25 const profileRecord = !info.profileTakedownRef || includeTakedowns
26 ? info.profile
27 : undefined;
28
29 return {
30 did,
31 handle: (info.handle ?? INVALID_HANDLE) as HandleString,
32 relatedRecords: profileRecord
33 ? [profileRecord as UnknownObject]
34 : undefined,
35 indexedAt: (info.sortedAt ?? new Date(0))
36 .toISOString() as DatetimeString,
37 };
38 });
39
40 return {
41 encoding: "application/json",
42 body: {
43 infos,
44 },
45 };
46 },
47 });
48}