This commit is contained in:
May 2024-05-24 15:47:22 -07:00
parent 93b277e5b8
commit 06856ae422

View file

@ -17,6 +17,14 @@ export const getAccount: RequestHandler = function (ctx, next) {
return next() return next()
} }
export function resolveTarget(actor: Accounts.Account, targetString: string) {
return targetString == "me"
? actor
: targetString.startsWith("@")
? Accounts.getFromUsername(targetString.slice(1))
: Accounts.getFromId(targetString)
}
/** /**
* @description use :user param to get a target for this route * @description use :user param to get a target for this route
*/ */
@ -29,12 +37,7 @@ export const getTarget: RequestHandler = async (ctx, next) => {
let actor = ctx.get("account") let actor = ctx.get("account")
let target = let target = resolveTarget(actor, ctx.req.param("user"))
ctx.req.param("user") == "me"
? actor
: ctx.req.param("user").startsWith("@")
? Accounts.getFromUsername(ctx.req.param("user").slice(1))
: Accounts.getFromId(ctx.req.param("user"))
if (!target) return ServeError(ctx, 404, "account does not exist") if (!target) return ServeError(ctx, 404, "account does not exist")