统一文件上传方式为直接上传,更新环境变量示例
This commit is contained in:
@@ -21,7 +21,6 @@ type Config struct {
|
||||
JWT JWTConfig `mapstructure:"jwt"`
|
||||
Casbin CasbinConfig `mapstructure:"casbin"`
|
||||
Log LogConfig `mapstructure:"log"`
|
||||
Upload UploadConfig `mapstructure:"upload"`
|
||||
Email EmailConfig `mapstructure:"email"`
|
||||
Security SecurityConfig `mapstructure:"security"`
|
||||
}
|
||||
@@ -99,14 +98,6 @@ type LogConfig struct {
|
||||
Compress bool `mapstructure:"compress"`
|
||||
}
|
||||
|
||||
// UploadConfig 文件上传配置
|
||||
type UploadConfig struct {
|
||||
MaxSize int64 `mapstructure:"max_size"`
|
||||
AllowedTypes []string `mapstructure:"allowed_types"`
|
||||
TextureMaxSize int64 `mapstructure:"texture_max_size"`
|
||||
AvatarMaxSize int64 `mapstructure:"avatar_max_size"`
|
||||
}
|
||||
|
||||
// EmailConfig 邮件配置
|
||||
type EmailConfig struct {
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
@@ -203,12 +194,6 @@ func setDefaults() {
|
||||
viper.SetDefault("log.max_age", 28)
|
||||
viper.SetDefault("log.compress", true)
|
||||
|
||||
// 文件上传默认配置
|
||||
viper.SetDefault("upload.max_size", 10485760)
|
||||
viper.SetDefault("upload.texture_max_size", 2097152)
|
||||
viper.SetDefault("upload.avatar_max_size", 1048576)
|
||||
viper.SetDefault("upload.allowed_types", []string{"image/png", "image/jpeg"})
|
||||
|
||||
// 邮件默认配置
|
||||
viper.SetDefault("email.enabled", false)
|
||||
viper.SetDefault("email.smtp_port", 587)
|
||||
@@ -370,25 +355,6 @@ func overrideFromEnv(config *Config) {
|
||||
}
|
||||
}
|
||||
|
||||
// 处理文件上传配置
|
||||
if maxSize := os.Getenv("UPLOAD_MAX_SIZE"); maxSize != "" {
|
||||
if val, err := strconv.ParseInt(maxSize, 10, 64); err == nil {
|
||||
config.Upload.MaxSize = val
|
||||
}
|
||||
}
|
||||
|
||||
if textureMaxSize := os.Getenv("UPLOAD_TEXTURE_MAX_SIZE"); textureMaxSize != "" {
|
||||
if val, err := strconv.ParseInt(textureMaxSize, 10, 64); err == nil {
|
||||
config.Upload.TextureMaxSize = val
|
||||
}
|
||||
}
|
||||
|
||||
if avatarMaxSize := os.Getenv("UPLOAD_AVATAR_MAX_SIZE"); avatarMaxSize != "" {
|
||||
if val, err := strconv.ParseInt(avatarMaxSize, 10, 64); err == nil {
|
||||
config.Upload.AvatarMaxSize = val
|
||||
}
|
||||
}
|
||||
|
||||
// 处理邮件配置
|
||||
if emailEnabled := os.Getenv("EMAIL_ENABLED"); emailEnabled != "" {
|
||||
config.Email.Enabled = emailEnabled == "true" || emailEnabled == "True" || emailEnabled == "TRUE" || emailEnabled == "1"
|
||||
|
||||
Reference in New Issue
Block a user