[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
This commit is contained in:
tobi 2024-02-23 19:28:09 +01:00 committed by GitHub
parent 1d51e3c8d6
commit 4b0eefbcc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 19 additions and 65 deletions

View file

@ -25,9 +25,9 @@ media-video-max-size: 41943040
media-description-min-chars: 0 media-description-min-chars: 0
# Int. Maximum amount of characters permitted in an image or video description. # Int. Maximum amount of characters permitted in an image or video description.
# Examples: [500, 1000, 1500] # Examples: [1000, 1500, 3000]
# Default: 500 # Default: 1500
media-description-max-chars: 500 media-description-max-chars: 1500
# Int. Max size in bytes of emojis uploaded to this instance via the admin API. # 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 # The default is the same as the Mastodon size limit for emojis (50kb), which allows

View file

@ -9,18 +9,15 @@
# Config pertaining to the creation of statuses/posts, and permitted limits. # 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. # Note that going way higher than the default might break federation.
#
# Examples: [140, 500, 5000] # Examples: [140, 500, 5000]
# Default: 5000 # Default: 5000
statuses-max-chars: 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. # Int. Maximum amount of options to permit when creating a new poll.
# Note that going way higher than the default might break federation. # Note that going way higher than the default might break federation.
# Examples: [4, 6, 10] # Examples: [4, 6, 10]

View file

@ -429,9 +429,9 @@ media-video-max-size: 41943040
media-description-min-chars: 0 media-description-min-chars: 0
# Int. Maximum amount of characters permitted in an image or video description. # Int. Maximum amount of characters permitted in an image or video description.
# Examples: [500, 1000, 1500] # Examples: [1000, 1500, 3000]
# Default: 500 # Default: 1500
media-description-max-chars: 500 media-description-max-chars: 1500
# Int. Max size in bytes of emojis uploaded to this instance via the admin API. # 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 # 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. # 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. # Note that going way higher than the default might break federation.
#
# Examples: [140, 500, 5000] # Examples: [140, 500, 5000]
# Default: 5000 # Default: 5000
statuses-max-chars: 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. # Int. Maximum amount of options to permit when creating a new poll.
# Note that going way higher than the default might break federation. # Note that going way higher than the default might break federation.
# Examples: [4, 6, 10] # Examples: [4, 6, 10]

View file

@ -137,15 +137,11 @@ func validateNormalizeCreateStatus(form *apimodel.AdvancedStatusCreateForm) erro
} }
maxChars := config.GetStatusesMaxChars() maxChars := config.GetStatusesMaxChars()
maxMediaFiles := config.GetStatusesMediaMaxFiles() if length := len([]rune(form.Status)) + len([]rune(form.SpoilerText)); length > maxChars {
maxCwChars := config.GetStatusesCWMaxChars() return fmt.Errorf("status too long, %d characters provided (including spoiler/content warning) but limit is %d", length, maxChars)
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)
}
} }
maxMediaFiles := config.GetStatusesMediaMaxFiles()
if len(form.MediaIDs) > maxMediaFiles { 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) 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 != "" { if form.Language != "" {
language, err := validate.Language(form.Language) language, err := validate.Language(form.Language)
if err != nil { if err != nil {

View file

@ -111,8 +111,7 @@ type Configuration struct {
StorageS3BucketName string `name:"storage-s3-bucket" usage:"Place blobs in this bucket"` 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"` 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"` StatusesMaxChars int `name:"statuses-max-chars" usage:"Max permitted characters for posted statuses, including content warning"`
StatusesCWMaxChars int `name:"statuses-cw-max-chars" usage:"Max permitted characters for content/spoiler warnings on statuses"`
StatusesPollMaxOptions int `name:"statuses-poll-max-options" usage:"Max amount of options permitted on a poll"` 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"` 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"` StatusesMediaMaxFiles int `name:"statuses-media-max-files" usage:"Maximum number of media files/attachments per status"`

View file

@ -74,7 +74,7 @@ var Defaults = Configuration{
MediaImageMaxSize: 10 * bytesize.MiB, MediaImageMaxSize: 10 * bytesize.MiB,
MediaVideoMaxSize: 40 * bytesize.MiB, MediaVideoMaxSize: 40 * bytesize.MiB,
MediaDescriptionMinChars: 0, MediaDescriptionMinChars: 0,
MediaDescriptionMaxChars: 500, MediaDescriptionMaxChars: 1500,
MediaRemoteCacheDays: 7, MediaRemoteCacheDays: 7,
MediaEmojiLocalMaxSize: 50 * bytesize.KiB, MediaEmojiLocalMaxSize: 50 * bytesize.KiB,
MediaEmojiRemoteMaxSize: 100 * bytesize.KiB, MediaEmojiRemoteMaxSize: 100 * bytesize.KiB,
@ -87,7 +87,6 @@ var Defaults = Configuration{
StorageS3Proxy: false, StorageS3Proxy: false,
StatusesMaxChars: 5000, StatusesMaxChars: 5000,
StatusesCWMaxChars: 100,
StatusesPollMaxOptions: 6, StatusesPollMaxOptions: 6,
StatusesPollOptionMaxChars: 50, StatusesPollOptionMaxChars: 50,
StatusesMediaMaxFiles: 6, StatusesMediaMaxFiles: 6,

View file

@ -113,7 +113,6 @@ func (s *ConfigState) AddServerFlags(cmd *cobra.Command) {
// Statuses // Statuses
cmd.Flags().Int(StatusesMaxCharsFlag(), cfg.StatusesMaxChars, fieldtag("StatusesMaxChars", "usage")) 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(StatusesPollMaxOptionsFlag(), cfg.StatusesPollMaxOptions, fieldtag("StatusesPollMaxOptions", "usage"))
cmd.Flags().Int(StatusesPollOptionMaxCharsFlag(), cfg.StatusesPollOptionMaxChars, fieldtag("StatusesPollOptionMaxChars", "usage")) cmd.Flags().Int(StatusesPollOptionMaxCharsFlag(), cfg.StatusesPollOptionMaxChars, fieldtag("StatusesPollOptionMaxChars", "usage"))
cmd.Flags().Int(StatusesMediaMaxFilesFlag(), cfg.StatusesMediaMaxFiles, fieldtag("StatusesMediaMaxFiles", "usage")) cmd.Flags().Int(StatusesMediaMaxFilesFlag(), cfg.StatusesMediaMaxFiles, fieldtag("StatusesMediaMaxFiles", "usage"))

View file

@ -1525,31 +1525,6 @@ func GetStatusesMaxChars() int { return global.GetStatusesMaxChars() }
// SetStatusesMaxChars safely sets the value for global configuration 'StatusesMaxChars' field // SetStatusesMaxChars safely sets the value for global configuration 'StatusesMaxChars' field
func SetStatusesMaxChars(v int) { global.SetStatusesMaxChars(v) } 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 // GetStatusesPollMaxOptions safely fetches the Configuration value for state's 'StatusesPollMaxOptions' field
func (st *ConfigState) GetStatusesPollMaxOptions() (v int) { func (st *ConfigState) GetStatusesPollMaxOptions() (v int) {
st.mutex.RLock() st.mutex.RLock()

View file

@ -142,7 +142,6 @@ EXPECT=$(cat << "EOF"
"smtp-port": 4269, "smtp-port": 4269,
"smtp-username": "sex-haver", "smtp-username": "sex-haver",
"software-version": "", "software-version": "",
"statuses-cw-max-chars": 420,
"statuses-max-chars": 69, "statuses-max-chars": 69,
"statuses-media-max-files": 1, "statuses-media-max-files": 1,
"statuses-poll-max-options": 1, "statuses-poll-max-options": 1,

View file

@ -101,7 +101,6 @@ var testDefaults = config.Configuration{
StorageLocalBasePath: "", StorageLocalBasePath: "",
StatusesMaxChars: 5000, StatusesMaxChars: 5000,
StatusesCWMaxChars: 100,
StatusesPollMaxOptions: 6, StatusesPollMaxOptions: 6,
StatusesPollOptionMaxChars: 50, StatusesPollOptionMaxChars: 50,
StatusesMediaMaxFiles: 6, StatusesMediaMaxFiles: 6,