BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr
feat(settings): add retention_days configuration
lotka0dfce452995
diff --git a/core/api/settings/v1/settings.go b/core/api/settings/v1/settings.goindex a3ee91af..dac875d3 100644--- a/core/api/settings/v1/settings.go+++ b/core/api/settings/v1/settings.go@@ -97,6 +97,8 @@ type SystemConfig struct {// blacklist configBlacklistConfig BlacklistConfig `json:"blacklist_config" dc:"blacklist configuration"`+ // Data retention days+ RetentionDays int `json:"retention_days" dc:"Number of days to keep log backup"`}type BlacklistConfig struct {diff --git a/core/internal/controller/settings/settings.go b/core/internal/controller/settings/settings.goindex 11c23487..6b6c7bb7 100644--- a/core/internal/controller/settings/settings.go+++ b/core/internal/controller/settings/settings.go@@ -164,6 +164,11 @@ func convertEnvToConfig(envMap map[string]string) *v1.SystemConfig {// IP whitelist IP_WHITELIST_ENABLEconfig.IPWhitelistEnabled = envMap["IP_WHITELIST_ENABLE"] == "true"+ // Data retention days+ if retentionDays := envMap["RETENTION_DAYS"]; retentionDays != "" {+ config.RetentionDays = parseInt(retentionDays, 7)+ }+return config}@@ -228,6 +233,11 @@ func validateConfigValue(key, value string) error {if value != "y" && value != "n" && value != "1" && value != "0" {return fmt.Errorf("fail2ban value can only be y/n or 1/0")}+ case "RETENTION_DAYS", "retention_days":+ // retention_days: must be a number+ if _, err := strconv.Atoi(value); err != nil {+ return fmt.Errorf("retention_days must be a number")+ }}// General character check: not allowed dangerous charactersdiff --git a/core/internal/controller/settings/settings_v1_set_system_config_key.go b/core/internal/controller/settings/settings_v1_set_system_config_key.goindex d7c422ae..fb02b614 100644--- a/core/internal/controller/settings/settings_v1_set_system_config_key.go+++ b/core/internal/controller/settings/settings_v1_set_system_config_key.go@@ -3,14 +3,16 @@ package settingsimport ("billionmail-core/internal/consts""context"- "github.com/gogf/gf/os/gtimer""time"+ "github.com/gogf/gf/os/gtimer"+"billionmail-core/api/settings/v1""billionmail-core/internal/service/public"+ "strings"+"github.com/gogf/gf/v2/errors/gerror""github.com/gogf/gf/v2/frame/g"- "strings")func (c *ControllerV1) SetSystemConfigKey(ctx context.Context, req *v1.SetSystemConfigKeyReq) (res *v1.SetSystemConfigKeyRes, err error) {@@ -101,6 +103,7 @@ func convertJsonKeyToEnvKey(jsonKey string, value string, envMap map[string]stri"ipv4_network": "IPV4_NETWORK","fail2ban": "FAIL2BAN_INIT","ip_whitelist_enable": "IP_WHITELIST_ENABLE",+ "retention_days": "RETENTION_DAYS",}// Get the environment variable key name