UNPKG

@atproto/ozone

Version:

Backend service for moderating the Bluesky network.

39 lines (32 loc) 1.08 kB
import { AuthRequiredError, InvalidRequestError } from '@atproto/xrpc-server' import { AppContext } from '../../context' import { Server } from '../../lexicon' export default function (server: Server, ctx: AppContext) { server.tools.ozone.set.upsertSet({ auth: ctx.authVerifier.modOrAdminToken, handler: async ({ input, auth }) => { const access = auth.credentials const db = ctx.db const { name, description } = input.body if (!access.isModerator) { throw new AuthRequiredError( 'Must be a moderator to create or update a set', ) } const setService = ctx.setService(db) await setService.upsert({ name, description: description ?? null, }) const setWithSize = await setService.getByNameWithSize(name) // Unlikely to happen since we just upserted the set if (!setWithSize) { throw new InvalidRequestError(`Set not found`) } return { encoding: 'application/json', body: setService.view(setWithSize), } }, }) }