From 4b0eefbcc9c30f1f34092be89a83936ab9ca04ed Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 23 Feb 2024 19:28:09 +0100 Subject: [PATCH] [chore] Increase default max image description to 1500 chars, collapse cw char count into status (#2682) * [chore] Make default max image description 1500 chars, collapse cw char count into status * oops * tests --- docs/configuration/media.md | 6 ++--- docs/configuration/statuses.md | 11 ++++----- example/config.yaml | 17 ++++++------- internal/api/client/statuses/statuscreate.go | 16 +++---------- internal/config/config.go | 3 +-- internal/config/defaults.go | 3 +-- internal/config/flags.go | 1 - internal/config/helpers.gen.go | 25 -------------------- test/envparsing.sh | 1 - testrig/config.go | 1 - 10 files changed, 19 insertions(+), 65 deletions(-) diff --git a/docs/configuration/media.md b/docs/configuration/media.md index 2bbdff420..d02acc480 100644 --- a/docs/configuration/media.md +++ b/docs/configuration/media.md @@ -25,9 +25,9 @@ media-video-max-size: 41943040 media-description-min-chars: 0 # Int. Maximum amount of characters permitted in an image or video description. -# Examples: [500, 1000, 1500] -# Default: 500 -media-description-max-chars: 500 +# Examples: [1000, 1500, 3000] +# Default: 1500 +media-description-max-chars: 1500 # Int. Max size in bytes of emojis uploaded to this instance via the admin API. # The default is the same as the Mastodon size limit for emojis (50kb), which allows diff --git a/docs/configuration/statuses.md b/docs/configuration/statuses.md index e0348dd5a..acf82293f 100644 --- a/docs/configuration/statuses.md +++ b/docs/configuration/statuses.md @@ -9,18 +9,15 @@ # Config pertaining to the creation of statuses/posts, and permitted limits. -# Int. Maximum amount of characters permitted for a new status. +# Int. Maximum amount of characters permitted for a new status, +# including the content warning (if set). +# # Note that going way higher than the default might break federation. +# # Examples: [140, 500, 5000] # Default: 5000 statuses-max-chars: 5000 -# Int. Maximum amount of characters allowed in the CW/subject header of a status. -# Note that going way higher than the default might break federation. -# Examples: [100, 200] -# Default: 100 -statuses-cw-max-chars: 100 - # Int. Maximum amount of options to permit when creating a new poll. # Note that going way higher than the default might break federation. # Examples: [4, 6, 10] diff --git a/example/config.yaml b/example/config.yaml index bbdd8adbf..4b0b42f5b 100644 --- a/example/config.yaml +++ b/example/config.yaml @@ -429,9 +429,9 @@ media-video-max-size: 41943040 media-description-min-chars: 0 # Int. Maximum amount of characters permitted in an image or video description. -# Examples: [500, 1000, 1500] -# Default: 500 -media-description-max-chars: 500 +# Examples: [1000, 1500, 3000] +# Default: 1500 +media-description-max-chars: 1500 # Int. Max size in bytes of emojis uploaded to this instance via the admin API. # The default is the same as the Mastodon size limit for emojis (50kb), which allows @@ -551,18 +551,15 @@ storage-s3-bucket: "" # Config pertaining to the creation of statuses/posts, and permitted limits. -# Int. Maximum amount of characters permitted for a new status. +# Int. Maximum amount of characters permitted for a new status, +# including the content warning (if set). +# # Note that going way higher than the default might break federation. +# # Examples: [140, 500, 5000] # Default: 5000 statuses-max-chars: 5000 -# Int. Maximum amount of characters allowed in the CW/subject header of a status. -# Note that going way higher than the default might break federation. -# Examples: [100, 200] -# Default: 100 -statuses-cw-max-chars: 100 - # Int. Maximum amount of options to permit when creating a new poll. # Note that going way higher than the default might break federation. # Examples: [4, 6, 10] diff --git a/internal/api/client/statuses/statuscreate.go b/internal/api/client/statuses/statuscreate.go index cc9b78384..929adaa6f 100644 --- a/internal/api/client/statuses/statuscreate.go +++ b/internal/api/client/statuses/statuscreate.go @@ -137,15 +137,11 @@ func validateNormalizeCreateStatus(form *apimodel.AdvancedStatusCreateForm) erro } maxChars := config.GetStatusesMaxChars() - maxMediaFiles := config.GetStatusesMediaMaxFiles() - maxCwChars := config.GetStatusesCWMaxChars() - - if form.Status != "" { - if length := len([]rune(form.Status)); length > maxChars { - return fmt.Errorf("status too long, %d characters provided but limit is %d", length, maxChars) - } + if length := len([]rune(form.Status)) + len([]rune(form.SpoilerText)); length > maxChars { + return fmt.Errorf("status too long, %d characters provided (including spoiler/content warning) but limit is %d", length, maxChars) } + maxMediaFiles := config.GetStatusesMediaMaxFiles() if len(form.MediaIDs) > maxMediaFiles { return fmt.Errorf("too many media files attached to status, %d attached but limit is %d", len(form.MediaIDs), maxMediaFiles) } @@ -156,12 +152,6 @@ func validateNormalizeCreateStatus(form *apimodel.AdvancedStatusCreateForm) erro } } - if form.SpoilerText != "" { - if length := len([]rune(form.SpoilerText)); length > maxCwChars { - return fmt.Errorf("content-warning/spoilertext too long, %d characters provided but limit is %d", length, maxCwChars) - } - } - if form.Language != "" { language, err := validate.Language(form.Language) if err != nil { diff --git a/internal/config/config.go b/internal/config/config.go index 68c065852..a4cd83227 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -111,8 +111,7 @@ type Configuration struct { StorageS3BucketName string `name:"storage-s3-bucket" usage:"Place blobs in this bucket"` StorageS3Proxy bool `name:"storage-s3-proxy" usage:"Proxy S3 contents through GoToSocial instead of redirecting to a presigned URL"` - StatusesMaxChars int `name:"statuses-max-chars" usage:"Max permitted characters for posted statuses"` - StatusesCWMaxChars int `name:"statuses-cw-max-chars" usage:"Max permitted characters for content/spoiler warnings on statuses"` + StatusesMaxChars int `name:"statuses-max-chars" usage:"Max permitted characters for posted statuses, including content warning"` StatusesPollMaxOptions int `name:"statuses-poll-max-options" usage:"Max amount of options permitted on a poll"` StatusesPollOptionMaxChars int `name:"statuses-poll-option-max-chars" usage:"Max amount of characters for a poll option"` StatusesMediaMaxFiles int `name:"statuses-media-max-files" usage:"Maximum number of media files/attachments per status"` diff --git a/internal/config/defaults.go b/internal/config/defaults.go index 3996b133f..a8343400b 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -74,7 +74,7 @@ MediaImageMaxSize: 10 * bytesize.MiB, MediaVideoMaxSize: 40 * bytesize.MiB, MediaDescriptionMinChars: 0, - MediaDescriptionMaxChars: 500, + MediaDescriptionMaxChars: 1500, MediaRemoteCacheDays: 7, MediaEmojiLocalMaxSize: 50 * bytesize.KiB, MediaEmojiRemoteMaxSize: 100 * bytesize.KiB, @@ -87,7 +87,6 @@ StorageS3Proxy: false, StatusesMaxChars: 5000, - StatusesCWMaxChars: 100, StatusesPollMaxOptions: 6, StatusesPollOptionMaxChars: 50, StatusesMediaMaxFiles: 6, diff --git a/internal/config/flags.go b/internal/config/flags.go index 350f56635..ae8a3ba36 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -113,7 +113,6 @@ func (s *ConfigState) AddServerFlags(cmd *cobra.Command) { // Statuses cmd.Flags().Int(StatusesMaxCharsFlag(), cfg.StatusesMaxChars, fieldtag("StatusesMaxChars", "usage")) - cmd.Flags().Int(StatusesCWMaxCharsFlag(), cfg.StatusesCWMaxChars, fieldtag("StatusesCWMaxChars", "usage")) cmd.Flags().Int(StatusesPollMaxOptionsFlag(), cfg.StatusesPollMaxOptions, fieldtag("StatusesPollMaxOptions", "usage")) cmd.Flags().Int(StatusesPollOptionMaxCharsFlag(), cfg.StatusesPollOptionMaxChars, fieldtag("StatusesPollOptionMaxChars", "usage")) cmd.Flags().Int(StatusesMediaMaxFilesFlag(), cfg.StatusesMediaMaxFiles, fieldtag("StatusesMediaMaxFiles", "usage")) diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go index 72b2a7fd9..0379a541b 100644 --- a/internal/config/helpers.gen.go +++ b/internal/config/helpers.gen.go @@ -1525,31 +1525,6 @@ func GetStatusesMaxChars() int { return global.GetStatusesMaxChars() } // SetStatusesMaxChars safely sets the value for global configuration 'StatusesMaxChars' field func SetStatusesMaxChars(v int) { global.SetStatusesMaxChars(v) } -// GetStatusesCWMaxChars safely fetches the Configuration value for state's 'StatusesCWMaxChars' field -func (st *ConfigState) GetStatusesCWMaxChars() (v int) { - st.mutex.RLock() - v = st.config.StatusesCWMaxChars - st.mutex.RUnlock() - return -} - -// SetStatusesCWMaxChars safely sets the Configuration value for state's 'StatusesCWMaxChars' field -func (st *ConfigState) SetStatusesCWMaxChars(v int) { - st.mutex.Lock() - defer st.mutex.Unlock() - st.config.StatusesCWMaxChars = v - st.reloadToViper() -} - -// StatusesCWMaxCharsFlag returns the flag name for the 'StatusesCWMaxChars' field -func StatusesCWMaxCharsFlag() string { return "statuses-cw-max-chars" } - -// GetStatusesCWMaxChars safely fetches the value for global configuration 'StatusesCWMaxChars' field -func GetStatusesCWMaxChars() int { return global.GetStatusesCWMaxChars() } - -// SetStatusesCWMaxChars safely sets the value for global configuration 'StatusesCWMaxChars' field -func SetStatusesCWMaxChars(v int) { global.SetStatusesCWMaxChars(v) } - // GetStatusesPollMaxOptions safely fetches the Configuration value for state's 'StatusesPollMaxOptions' field func (st *ConfigState) GetStatusesPollMaxOptions() (v int) { st.mutex.RLock() diff --git a/test/envparsing.sh b/test/envparsing.sh index aa8af4dba..c67d855f5 100755 --- a/test/envparsing.sh +++ b/test/envparsing.sh @@ -142,7 +142,6 @@ EXPECT=$(cat << "EOF" "smtp-port": 4269, "smtp-username": "sex-haver", "software-version": "", - "statuses-cw-max-chars": 420, "statuses-max-chars": 69, "statuses-media-max-files": 1, "statuses-poll-max-options": 1, diff --git a/testrig/config.go b/testrig/config.go index 04970aca6..a8d148cac 100644 --- a/testrig/config.go +++ b/testrig/config.go @@ -101,7 +101,6 @@ func InitTestConfig() { StorageLocalBasePath: "", StatusesMaxChars: 5000, - StatusesCWMaxChars: 100, StatusesPollMaxOptions: 6, StatusesPollOptionMaxChars: 50, StatusesMediaMaxFiles: 6,