From 9f4f7cac6512330481ea3e2de0633fc893788c33 Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Fri, 5 May 2023 11:09:05 -0400 Subject: initial pomelo implementation --- src/api/routes/users/@me/index.ts | 2 ++ src/api/routes/users/@me/relationships.ts | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src/api/routes/users/@me') diff --git a/src/api/routes/users/@me/index.ts b/src/api/routes/users/@me/index.ts index ad11a428..1d209542 100644 --- a/src/api/routes/users/@me/index.ts +++ b/src/api/routes/users/@me/index.ts @@ -140,6 +140,7 @@ router.patch( newToken = (await generateToken(user.id)) as string; } + // TODO: pomelo: disallow if pomelo is enabled if (body.username) { const check_username = body?.username?.replace(/\s/g, ""); if (!check_username) { @@ -162,6 +163,7 @@ router.patch( } } + // TODO: pomelo: disallow if pomelo is enabled if (body.discriminator) { if ( await User.findOne({ diff --git a/src/api/routes/users/@me/relationships.ts b/src/api/routes/users/@me/relationships.ts index bce0a654..08342602 100644 --- a/src/api/routes/users/@me/relationships.ts +++ b/src/api/routes/users/@me/relationships.ts @@ -114,19 +114,26 @@ router.post( }, }), async (req: Request, res: Response) => { + const { pomeloEnabled } = Config.get().general; + const where = pomeloEnabled + ? { + // TODO: pomelo: should we use username or add global_name property to the request? + global_name: req.body.username, + } + : { + discriminator: String(req.body.discriminator).padStart( + 4, + "0", + ), //Discord send the discriminator as integer, we need to add leading zeroes + username: req.body.username, + }; return await updateRelationship( req, res, await User.findOneOrFail({ relations: ["relationships", "relationships.to"], select: userProjection, - where: { - discriminator: String(req.body.discriminator).padStart( - 4, - "0", - ), //Discord send the discriminator as integer, we need to add leading zeroes - username: req.body.username, - }, + where, }), req.body.type, ); -- cgit 1.5.1