From e9df285ef79b8a72e449323915b0f94bd44e9132 Mon Sep 17 00:00:00 2001 From: stringsplit <77242831+nbitzz@users.noreply.github.com> Date: Fri, 8 Mar 2024 21:39:03 +0000 Subject: [PATCH] Ahhhhh im gonna figure this out when i get homeee --- src/server/routes/api/v1/account.ts | 55 ++++++----------------------- 1 file changed, 11 insertions(+), 44 deletions(-) diff --git a/src/server/routes/api/v1/account.ts b/src/server/routes/api/v1/account.ts index 64f380d..3f49e07 100644 --- a/src/server/routes/api/v1/account.ts +++ b/src/server/routes/api/v1/account.ts @@ -148,54 +148,21 @@ export default function (files: Files) { ) router.patch( - "/dfv", + "/:user", requiresAccount, requiresPermissions("manage"), async (ctx) => { - const body = await ctx.req.json() - const Account = ctx.get("account")! as Accounts.Account + const body = await ctx.req.json() as UserUpdateParameters + const actor = ctx.get("account")! as Accounts.Account + const target = ctx.get("target")! as Accounts.Account + if (Array.isArray(body)) + return ServeError(ctx, 400, "invalid body") - if ( - ["public", "private", "anonymous"].includes( - body.defaultFileVisibility - ) - ) { - Account.defaultFileVisibility = body.defaultFileVisibility - - Accounts.save() - - return ctx.text( - `dfv has been set to ${Account.defaultFileVisibility}` - ) - } else { - return ServeError(ctx, 400, "invalid dfv") - } - } - ) - - router.patch( - "/dfv", - requiresAccount, - requiresPermissions("manage"), - async (ctx) => { - const body = await ctx.req.json() - const Account = ctx.get("account")! as Accounts.Account - - if ( - ["public", "private", "anonymous"].includes( - body.defaultFileVisibility - ) - ) { - Account.defaultFileVisibility = body.defaultFileVisibility - - Accounts.save() - - return ctx.text( - `dfv has been set to ${Account.defaultFileVisibility}` - ) - } else { - return ServeError(ctx, 400, "invalid dfv") - } + Object.entries(body).filter(e => e[1]).map(([x]) => { + if (x in validators) { + validators[x](actor, target, body as any) + } + }) } )