diff options
-rw-r--r-- | api/admin.go | 4 | ||||
-rw-r--r-- | api/file.go | 4 | ||||
-rw-r--r-- | api/license.go | 9 | ||||
-rw-r--r-- | api/user.go | 4 | ||||
-rw-r--r-- | config/config.json | 3 | ||||
-rw-r--r-- | i18n/en.json | 4 | ||||
-rw-r--r-- | model/config.go | 10 | ||||
-rw-r--r-- | model/file.go | 4 | ||||
-rw-r--r-- | webapp/components/admin_console/storage_settings.jsx | 22 |
9 files changed, 48 insertions, 16 deletions
diff --git a/api/admin.go b/api/admin.go index 8f66f60c1..c2dfa37d0 100644 --- a/api/admin.go +++ b/api/admin.go @@ -437,13 +437,13 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { return } - if r.ContentLength > model.MAX_FILE_SIZE { + if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize { c.Err = model.NewLocAppError("uploadBrandImage", "api.admin.upload_brand_image.too_large.app_error", nil, "") c.Err.StatusCode = http.StatusRequestEntityTooLarge return } - if err := r.ParseMultipartForm(model.MAX_FILE_SIZE); err != nil { + if err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize); err != nil { c.Err = model.NewLocAppError("uploadBrandImage", "api.admin.upload_brand_image.parse.app_error", nil, "") return } diff --git a/api/file.go b/api/file.go index f4d1e0005..e29bb072a 100644 --- a/api/file.go +++ b/api/file.go @@ -77,13 +77,13 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) { return } - if r.ContentLength > model.MAX_FILE_SIZE { + if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize { c.Err = model.NewLocAppError("uploadFile", "api.file.upload_file.too_large.app_error", nil, "") c.Err.StatusCode = http.StatusRequestEntityTooLarge return } - err := r.ParseMultipartForm(model.MAX_FILE_SIZE) + err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/api/license.go b/api/license.go index 1dbb2b281..f9ecce486 100644 --- a/api/license.go +++ b/api/license.go @@ -5,12 +5,13 @@ package api import ( "bytes" - l4g "github.com/alecthomas/log4go" - "github.com/mattermost/platform/model" - "github.com/mattermost/platform/utils" "io" "net/http" "strings" + + l4g "github.com/alecthomas/log4go" + "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" ) const ( @@ -48,7 +49,7 @@ func LoadLicense() { func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("attempt") - err := r.ParseMultipartForm(model.MAX_FILE_SIZE) + err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/api/user.go b/api/user.go index ac99bd21b..628e978e9 100644 --- a/api/user.go +++ b/api/user.go @@ -1178,13 +1178,13 @@ func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { return } - if r.ContentLength > model.MAX_FILE_SIZE { + if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize { c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.too_large.app_error", nil, "") c.Err.StatusCode = http.StatusRequestEntityTooLarge return } - if err := r.ParseMultipartForm(model.MAX_FILE_SIZE); err != nil { + if err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize); err != nil { c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.parse.app_error", nil, "") return } diff --git a/config/config.json b/config/config.json index 9f5e8f9c8..27706a6b1 100644 --- a/config/config.json +++ b/config/config.json @@ -55,6 +55,7 @@ "FileLocation": "" }, "FileSettings": { + "MaxFileSize": 52428800, "DriverName": "local", "Directory": "./data/", "EnablePublicLink": false, @@ -160,4 +161,4 @@ "DefaultClientLocale": "en", "AvailableLocales": "en,es,fr,ja,pt-BR" } -}
\ No newline at end of file +} diff --git a/i18n/en.json b/i18n/en.json index d73196cf6..cb2384650 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -2392,6 +2392,10 @@ "translation": "Invalid maximum idle connection for SQL settings. Must be a positive number." }, { + "id": "model.config.is_valid.max_file_size.app_error", + "translation": "Invalid max file size for file settings. Must be a zero or positive number." + }, + { "id": "model.config.is_valid.sql_max_conn.app_error", "translation": "Invalid maximum open connection for SQL settings. Must be a positive number." }, diff --git a/model/config.go b/model/config.go index ecfd18710..08b00b90f 100644 --- a/model/config.go +++ b/model/config.go @@ -92,6 +92,7 @@ type LogSettings struct { } type FileSettings struct { + MaxFileSize *int64 DriverName string Directory string EnablePublicLink bool @@ -263,6 +264,11 @@ func (o *Config) SetDefaults() { o.SqlSettings.AtRestEncryptKey = NewRandomString(32) } + if o.FileSettings.MaxFileSize == nil { + o.FileSettings.MaxFileSize = new(int64) + *o.FileSettings.MaxFileSize = 52428800 // 50 MB + } + if len(o.FileSettings.PublicLinkSalt) == 0 { o.FileSettings.PublicLinkSalt = NewRandomString(32) } @@ -569,6 +575,10 @@ func (o *Config) IsValid() *AppError { return NewLocAppError("Config.IsValid", "model.config.is_valid.sql_max_conn.app_error", nil, "") } + if *o.FileSettings.MaxFileSize <= 0 { + return NewLocAppError("Config.IsValid", "model.config.is_valid.max_file_size.app_error", nil, "") + } + if !(o.FileSettings.DriverName == IMAGE_DRIVER_LOCAL || o.FileSettings.DriverName == IMAGE_DRIVER_S3) { return NewLocAppError("Config.IsValid", "model.config.is_valid.file_driver.app_error", nil, "") } diff --git a/model/file.go b/model/file.go index b7806b3b4..fa98a3b3a 100644 --- a/model/file.go +++ b/model/file.go @@ -8,10 +8,6 @@ import ( "io" ) -const ( - MAX_FILE_SIZE = 50000000 // 50 MB -) - var ( IMAGE_EXTENSIONS = [5]string{".jpg", ".jpeg", ".gif", ".bmp", ".png"} IMAGE_MIME_TYPES = map[string]string{".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".bmp": "image/bmp", ".png": "image/png", ".tiff": "image/tiff"} diff --git a/webapp/components/admin_console/storage_settings.jsx b/webapp/components/admin_console/storage_settings.jsx index 339876b18..7cfa9cf3b 100644 --- a/webapp/components/admin_console/storage_settings.jsx +++ b/webapp/components/admin_console/storage_settings.jsx @@ -23,6 +23,7 @@ export default class StorageSettings extends AdminSettings { this.renderSettings = this.renderSettings.bind(this); this.state = Object.assign(this.state, { + maxFileSize: props.config.FileSettings.MaxFileSize, driverName: props.config.FileSettings.DriverName, directory: props.config.FileSettings.Directory, amazonS3AccessKeyId: props.config.FileSettings.AmazonS3AccessKeyId, @@ -33,6 +34,7 @@ export default class StorageSettings extends AdminSettings { } getConfigFromState(config) { + config.FileSettings.MaxFileSize = this.parseInt(this.state.maxFileSize); config.FileSettings.DriverName = this.state.driverName; config.FileSettings.Directory = this.state.directory; config.FileSettings.AmazonS3AccessKeyId = this.state.amazonS3AccessKeyId; @@ -64,6 +66,24 @@ export default class StorageSettings extends AdminSettings { /> } > + <TextSetting + id='maxFileSize' + label={ + <FormattedMessage + id='admin.image.maxFileSizeTitle' + defaultMessage='Max File Size:' + /> + } + placeholder={Utils.localizeMessage('admin.image.maxFileSizeExample', 'Ex "52428800"')} + helpText={ + <FormattedMessage + id='admin.image.maxFileSizeDescription' + defaultMessage='Max File Size in bytes. If blank, will be set to 52428800 (50MB).' + /> + } + value={this.state.maxFileSize} + onChange={this.handleChange} + /> <DropdownSetting id='driverName' values={[ @@ -177,4 +197,4 @@ export default class StorageSettings extends AdminSettings { </SettingsGroup> ); } -}
\ No newline at end of file +} |