[READ ONLY MIRROR] Spark Social AppView Server
github.com/sprksocial/server
atproto
deno
hono
lexicon
1import type { CidString } from "@atp/lex";
2import { InvalidRequestError, Server } from "@atp/xrpc-server";
3
4import { AppContext } from "../../../../context.ts";
5import * as com from "../../../../lex/com.ts";
6import { $OutputBody } from "../../../../lex/com/atproto/admin/getSubjectStatus.ts";
7
8export default function (server: Server, ctx: AppContext) {
9 server.add(com.atproto.admin.getSubjectStatus, {
10 auth: ctx.authVerifier.roleOrModService,
11 handler: async ({ params }) => {
12 const { did, uri, blob } = params;
13
14 let body: $OutputBody | null = null;
15 if (blob) {
16 if (!did) {
17 throw new InvalidRequestError(
18 "Must provide a did to request blob state",
19 );
20 }
21 const res = await ctx.dataplane.moderation.getBlobTakedown(
22 did,
23 blob,
24 );
25 body = {
26 subject: {
27 $type: "com.atproto.admin.defs#repoBlobRef",
28 did: did,
29 cid: blob,
30 },
31 takedown: {
32 applied: res.takenDown,
33 ref: res.takedownRef ? "TAKEDOWN" : undefined,
34 },
35 };
36 } else if (uri) {
37 const res = await ctx.hydrator.getRecord(uri, true);
38 if (res) {
39 body = {
40 subject: {
41 $type: "com.atproto.repo.strongRef",
42 uri,
43 cid: res.cid as CidString,
44 },
45 takedown: {
46 applied: !!res.takedownRef,
47 ref: res.takedownRef || undefined,
48 },
49 };
50 }
51 } else if (did) {
52 const res = (
53 await ctx.hydrator.actor.getActors([did], {
54 includeTakedowns: true,
55 })
56 ).get(did);
57 if (res) {
58 body = {
59 subject: {
60 $type: "com.atproto.admin.defs#repoRef",
61 did: did,
62 },
63 takedown: {
64 applied: !!res.takedownRef,
65 ref: res.takedownRef || undefined,
66 },
67 };
68 }
69 } else {
70 throw new InvalidRequestError("No provided subject");
71 }
72 if (body === null) {
73 throw new InvalidRequestError("Subject not found", "NotFound");
74 }
75 return {
76 encoding: "application/json",
77 body,
78 };
79 },
80 });
81}