summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2024-08-14 14:04:30 +1000
committerGitHub <noreply@github.com>2024-08-14 14:04:30 +1000
commit2f1449e65fe91d7689478b40880b8b58cd1be91b (patch)
tree59f7799d23eb4fb78fbbd753a9ce3f624dc3ff5a /src/api
parentMerge pull request #1159 from DEVTomatoCake/feat/request-guild-members (diff)
parentUpdate schema for bio max length config (diff)
downloadserver-ts-2f1449e65fe91d7689478b40880b8b58cd1be91b.tar.xz
Merge pull request #1161 from DEVTomatoCake/feat/bio-max-length-config
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/users/#id/profile.ts20
-rw-r--r--src/api/routes/users/@me/index.ts18
2 files changed, 32 insertions, 6 deletions
diff --git a/src/api/routes/users/#id/profile.ts b/src/api/routes/users/#id/profile.ts

index db0922d6..44271cad 100644 --- a/src/api/routes/users/#id/profile.ts +++ b/src/api/routes/users/#id/profile.ts
@@ -1,17 +1,17 @@ /* Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Copyright (C) 2023 Spacebar and Spacebar Contributors - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ @@ -19,6 +19,8 @@ import { route } from "@spacebar/api"; import { Badge, + Config, + FieldErrors, Member, PrivateUserProjection, User, @@ -136,6 +138,18 @@ router.patch( select: [...PrivateUserProjection, "data"], }); + if (body.bio) { + const { maxBio } = Config.get().limits.user; + if (body.bio.length > maxBio) { + throw FieldErrors({ + bio: { + code: "BIO_INVALID", + message: `Bio must be less than ${maxBio} in length`, + }, + }); + } + } + user.assign(body); await user.save(); diff --git a/src/api/routes/users/@me/index.ts b/src/api/routes/users/@me/index.ts
index cddc3a08..5caf0d11 100644 --- a/src/api/routes/users/@me/index.ts +++ b/src/api/routes/users/@me/index.ts
@@ -1,17 +1,17 @@ /* Spacebar: A FOSS re-implementation and extension of the Discord.com backend. Copyright (C) 2023 Spacebar and Spacebar Contributors - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ @@ -189,6 +189,18 @@ router.patch( } } + if (body.bio) { + const { maxBio } = Config.get().limits.user; + if (body.bio.length > maxBio) { + throw FieldErrors({ + bio: { + code: "BIO_INVALID", + message: `Bio must be less than ${maxBio} in length`, + }, + }); + } + } + user.assign(body); user.validate(); await user.save();