diff options
author | 2023-03-06 09:30:19 +0000 | |
---|---|---|
committer | 2023-03-06 10:30:19 +0100 | |
commit | f518f649f800e52d32fe53580c528ffa042f7154 (patch) | |
tree | c14bb8b513008d1c1e7bab0908cfc99fe18f1507 /internal/validate/formvalidation.go | |
parent | [chore]: Bump github.com/jackc/pgx/v4 from 4.17.2 to 4.18.1 (#1595) (diff) | |
download | gotosocial-f518f649f800e52d32fe53580c528ffa042f7154.tar.xz |
[feature] Add support for profile fields (#1483)
* Add go-playground/form pkg
* [feature] Add support for profile fields
* Add field attributes test
* Validate profile fields form
* Add profile field validation tests
* Add Field Attributes definition to swagger
---------
Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
Diffstat (limited to 'internal/validate/formvalidation.go')
-rw-r--r-- | internal/validate/formvalidation.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/validate/formvalidation.go b/internal/validate/formvalidation.go index 32aa1fd1e..e7839d1a3 100644 --- a/internal/validate/formvalidation.go +++ b/internal/validate/formvalidation.go @@ -43,6 +43,8 @@ const ( maximumUsernameLength = 64 maximumCustomCSSLength = 5000 maximumEmojiCategoryLength = 64 + maximumProfileFieldLength = 255 + maximumProfileFields = 4 ) // NewPassword returns an error if the given password is not sufficiently strong, or nil if it's ok. @@ -231,3 +233,20 @@ func SiteTerms(t string) error { func ULID(i string) bool { return regexes.ULID.MatchString(i) } + +func ProfileFieldsCount(fields []apimodel.UpdateField) error { + if length := len(fields); length > maximumProfileFields { + return fmt.Errorf("cannot have more than %d profile fields", maximumProfileFields) + } + + return nil +} + +func ProfileField(f *string) string { + s := []rune(*f) + if len(s) > maximumProfileFieldLength { + return string(s[:maximumProfileFieldLength]) // trim profile field to maximum allowed length + } + + return string(*f) +} |