@@ -36,6 +36,8 @@ type Config struct {
|
||||
MaxRequestBytes int64 `json:"max_request_bytes"`
|
||||
MaxPackageBytes int64 `json:"max_package_bytes"`
|
||||
Database DatabaseConfig `json:"database"`
|
||||
Mail MailConfig `json:"mail"`
|
||||
Branding BrandingConfig `json:"branding"`
|
||||
UploadGuard UploadGuardConfig `json:"upload_guard"`
|
||||
SourceCheckSeconds int `json:"source_check_seconds"`
|
||||
}
|
||||
@@ -44,6 +46,11 @@ type DatabaseConfig struct {
|
||||
Provider string `json:"provider"`
|
||||
SQLitePath string `json:"sqlite_path"`
|
||||
MySQLDSN string `json:"mysql_dsn"`
|
||||
MySQLHost string `json:"mysql_host"`
|
||||
MySQLPort int `json:"mysql_port"`
|
||||
MySQLDatabase string `json:"mysql_database"`
|
||||
MySQLUser string `json:"mysql_user"`
|
||||
MySQLPassword string `json:"mysql_password"`
|
||||
FailoverEnabled bool `json:"failover_enabled"`
|
||||
HotSyncEnabled bool `json:"hot_sync_enabled"`
|
||||
HealthIntervalSec int `json:"health_interval_sec"`
|
||||
@@ -52,6 +59,25 @@ type DatabaseConfig struct {
|
||||
ConnMaxLifetimeSeconds int `json:"conn_max_lifetime_seconds"`
|
||||
}
|
||||
|
||||
type MailConfig struct {
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Secure string `json:"secure"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
FromAddress string `json:"from_address"`
|
||||
FromName string `json:"from_name"`
|
||||
DeveloperAddress string `json:"developer_address"`
|
||||
TimeoutSeconds int `json:"timeout_seconds"`
|
||||
}
|
||||
|
||||
type BrandingConfig struct {
|
||||
SiteIconURL string `json:"site_icon_url"`
|
||||
DeveloperAvatarURL string `json:"developer_avatar_url"`
|
||||
DeveloperName string `json:"developer_name"`
|
||||
FeedbackEmail string `json:"feedback_email"`
|
||||
}
|
||||
|
||||
type UploadGuardConfig struct {
|
||||
MaxZipFiles int `json:"max_zip_files"`
|
||||
MaxDecompressedBytes int64 `json:"max_decompressed_bytes"`
|
||||
@@ -120,6 +146,8 @@ func defaults(root string) *Config {
|
||||
Database: DatabaseConfig{
|
||||
Provider: "sqlite",
|
||||
SQLitePath: filepath.Join(root, "storage", "unified.sqlite"),
|
||||
MySQLHost: "127.0.0.1",
|
||||
MySQLPort: 3306,
|
||||
FailoverEnabled: true,
|
||||
HotSyncEnabled: true,
|
||||
HealthIntervalSec: 30,
|
||||
@@ -127,6 +155,19 @@ func defaults(root string) *Config {
|
||||
MaxIdleConns: 4,
|
||||
ConnMaxLifetimeSeconds: 300,
|
||||
},
|
||||
Mail: MailConfig{
|
||||
Port: 465,
|
||||
Secure: "ssl",
|
||||
FromName: "YMhut Box Feedback",
|
||||
DeveloperAddress: "support@ymhut.cn",
|
||||
TimeoutSeconds: 20,
|
||||
},
|
||||
Branding: BrandingConfig{
|
||||
SiteIconURL: "https://img.ymhut.cn/file/1782108850041_icon.webp",
|
||||
DeveloperAvatarURL: "https://img.ymhut.cn/file/1782108780690_b_3db45f3787f19192c8de8e06bc0987ef.webp",
|
||||
DeveloperName: "YMhut",
|
||||
FeedbackEmail: "support@ymhut.cn",
|
||||
},
|
||||
UploadGuard: UploadGuardConfig{
|
||||
MaxZipFiles: 80,
|
||||
MaxDecompressedBytes: 30 * 1024 * 1024,
|
||||
@@ -184,6 +225,66 @@ func applyEnv(cfg *Config) {
|
||||
if value := os.Getenv("YMHUT_MYSQL_DSN"); value != "" {
|
||||
cfg.Database.MySQLDSN = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MYSQL_HOST"); value != "" {
|
||||
cfg.Database.MySQLHost = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MYSQL_PORT"); value != "" {
|
||||
if parsed, err := strconv.Atoi(value); err == nil {
|
||||
cfg.Database.MySQLPort = parsed
|
||||
}
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MYSQL_DATABASE"); value != "" {
|
||||
cfg.Database.MySQLDatabase = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MYSQL_USER"); value != "" {
|
||||
cfg.Database.MySQLUser = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MYSQL_PASSWORD"); value != "" {
|
||||
cfg.Database.MySQLPassword = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MAIL_HOST"); value != "" {
|
||||
cfg.Mail.Host = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MAIL_PORT"); value != "" {
|
||||
if parsed, err := strconv.Atoi(value); err == nil {
|
||||
cfg.Mail.Port = parsed
|
||||
}
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MAIL_SECURE"); value != "" {
|
||||
cfg.Mail.Secure = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MAIL_USERNAME"); value != "" {
|
||||
cfg.Mail.Username = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MAIL_PASSWORD"); value != "" {
|
||||
cfg.Mail.Password = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MAIL_FROM_ADDRESS"); value != "" {
|
||||
cfg.Mail.FromAddress = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MAIL_FROM_NAME"); value != "" {
|
||||
cfg.Mail.FromName = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MAIL_DEVELOPER_ADDRESS"); value != "" {
|
||||
cfg.Mail.DeveloperAddress = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_MAIL_TIMEOUT_SECONDS"); value != "" {
|
||||
if parsed, err := strconv.Atoi(value); err == nil {
|
||||
cfg.Mail.TimeoutSeconds = parsed
|
||||
}
|
||||
}
|
||||
if value := os.Getenv("YMHUT_BRAND_ICON_URL"); value != "" {
|
||||
cfg.Branding.SiteIconURL = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_BRAND_DEVELOPER_AVATAR_URL"); value != "" {
|
||||
cfg.Branding.DeveloperAvatarURL = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_BRAND_DEVELOPER_NAME"); value != "" {
|
||||
cfg.Branding.DeveloperName = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_BRAND_FEEDBACK_EMAIL"); value != "" {
|
||||
cfg.Branding.FeedbackEmail = value
|
||||
}
|
||||
if value := os.Getenv("YMHUT_CLIENT_SIGNATURE_KEY"); value != "" {
|
||||
cfg.ClientSignatureKey = value
|
||||
}
|
||||
@@ -267,10 +368,30 @@ func normalize(root string, cfg *Config) {
|
||||
if cfg.Database.Provider == "" {
|
||||
cfg.Database.Provider = "sqlite"
|
||||
}
|
||||
cfg.Database.Provider = strings.ToLower(strings.TrimSpace(cfg.Database.Provider))
|
||||
if cfg.Database.SQLitePath == "" {
|
||||
cfg.Database.SQLitePath = filepath.Join(cfg.StorageDir, "unified.sqlite")
|
||||
}
|
||||
cfg.Database.SQLitePath = absPath(cfg.BaseDir, cfg.Database.SQLitePath)
|
||||
if cfg.Database.MySQLHost == "" {
|
||||
cfg.Database.MySQLHost = "127.0.0.1"
|
||||
}
|
||||
if cfg.Database.MySQLPort <= 0 {
|
||||
cfg.Database.MySQLPort = 3306
|
||||
}
|
||||
if cfg.Database.Provider == "mysql" && cfg.Database.MySQLDSN == "" && cfg.Database.MySQLDatabase != "" && cfg.Database.MySQLUser != "" {
|
||||
if dsn, err := BuildMySQLDSN(MySQLInput{
|
||||
Host: cfg.Database.MySQLHost,
|
||||
Port: cfg.Database.MySQLPort,
|
||||
Database: cfg.Database.MySQLDatabase,
|
||||
Username: cfg.Database.MySQLUser,
|
||||
Password: cfg.Database.MySQLPassword,
|
||||
Charset: "utf8mb4",
|
||||
ParseTime: true,
|
||||
}); err == nil {
|
||||
cfg.Database.MySQLDSN = dsn
|
||||
}
|
||||
}
|
||||
if cfg.Database.HealthIntervalSec <= 0 {
|
||||
cfg.Database.HealthIntervalSec = 30
|
||||
}
|
||||
@@ -316,6 +437,37 @@ func normalize(root string, cfg *Config) {
|
||||
if cfg.SourceCheckSeconds <= 0 {
|
||||
cfg.SourceCheckSeconds = 300
|
||||
}
|
||||
if cfg.Mail.Port <= 0 {
|
||||
cfg.Mail.Port = 465
|
||||
}
|
||||
cfg.Mail.Secure = strings.ToLower(strings.TrimSpace(cfg.Mail.Secure))
|
||||
if cfg.Mail.Secure == "" {
|
||||
cfg.Mail.Secure = "ssl"
|
||||
}
|
||||
if cfg.Mail.FromName == "" {
|
||||
cfg.Mail.FromName = "YMhut Box Feedback"
|
||||
}
|
||||
if cfg.Mail.FromAddress == "" {
|
||||
cfg.Mail.FromAddress = cfg.Mail.Username
|
||||
}
|
||||
if cfg.Mail.TimeoutSeconds <= 0 {
|
||||
cfg.Mail.TimeoutSeconds = 20
|
||||
}
|
||||
if cfg.Branding.SiteIconURL == "" {
|
||||
cfg.Branding.SiteIconURL = "https://img.ymhut.cn/file/1782108850041_icon.webp"
|
||||
}
|
||||
if cfg.Branding.DeveloperAvatarURL == "" {
|
||||
cfg.Branding.DeveloperAvatarURL = "https://img.ymhut.cn/file/1782108780690_b_3db45f3787f19192c8de8e06bc0987ef.webp"
|
||||
}
|
||||
if cfg.Branding.DeveloperName == "" {
|
||||
cfg.Branding.DeveloperName = "YMhut"
|
||||
}
|
||||
if cfg.Branding.FeedbackEmail == "" {
|
||||
cfg.Branding.FeedbackEmail = "support@ymhut.cn"
|
||||
}
|
||||
if cfg.Mail.DeveloperAddress == "" {
|
||||
cfg.Mail.DeveloperAddress = cfg.Branding.FeedbackEmail
|
||||
}
|
||||
}
|
||||
|
||||
func ResolveBaseDir() (string, error) {
|
||||
|
||||
Reference in New Issue
Block a user