feat: Implement database-backed configuration management and the main backend application entry point.
This commit is contained in:
@@ -225,6 +225,7 @@ func handleConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
"group_ids": config.Global.GroupIDs,
|
"group_ids": config.Global.GroupIDs,
|
||||||
"proxy_enabled": config.Global.ProxyEnabled,
|
"proxy_enabled": config.Global.ProxyEnabled,
|
||||||
"default_proxy": config.Global.DefaultProxy,
|
"default_proxy": config.Global.DefaultProxy,
|
||||||
|
"team_reg_proxy": config.Global.TeamRegProxy,
|
||||||
"proxy_test_status": getProxyTestStatus(),
|
"proxy_test_status": getProxyTestStatus(),
|
||||||
"proxy_test_ip": getProxyTestIP(),
|
"proxy_test_ip": getProxyTestIP(),
|
||||||
"site_name": config.Global.SiteName,
|
"site_name": config.Global.SiteName,
|
||||||
@@ -242,6 +243,7 @@ func handleConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
GroupIDs []int `json:"group_ids"`
|
GroupIDs []int `json:"group_ids"`
|
||||||
ProxyEnabled *bool `json:"proxy_enabled"`
|
ProxyEnabled *bool `json:"proxy_enabled"`
|
||||||
DefaultProxy *string `json:"default_proxy"`
|
DefaultProxy *string `json:"default_proxy"`
|
||||||
|
TeamRegProxy *string `json:"team_reg_proxy"`
|
||||||
SiteName *string `json:"site_name"`
|
SiteName *string `json:"site_name"`
|
||||||
}
|
}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||||
@@ -276,6 +278,9 @@ func handleConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
database.Instance.SetConfig("proxy_test_ip", "")
|
database.Instance.SetConfig("proxy_test_ip", "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if req.TeamRegProxy != nil {
|
||||||
|
config.Global.TeamRegProxy = *req.TeamRegProxy
|
||||||
|
}
|
||||||
if req.SiteName != nil {
|
if req.SiteName != nil {
|
||||||
config.Global.SiteName = *req.SiteName
|
config.Global.SiteName = *req.SiteName
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ type Config struct {
|
|||||||
// 代理配置 (可实时更新)
|
// 代理配置 (可实时更新)
|
||||||
ProxyEnabled bool `json:"proxy_enabled"`
|
ProxyEnabled bool `json:"proxy_enabled"`
|
||||||
DefaultProxy string `json:"default_proxy"`
|
DefaultProxy string `json:"default_proxy"`
|
||||||
|
TeamRegProxy string `json:"team_reg_proxy"` // Team 注册使用的代理
|
||||||
|
|
||||||
// 自动化配置
|
// 自动化配置
|
||||||
AutoPauseOnExpired bool `json:"auto_pause_on_expired"`
|
AutoPauseOnExpired bool `json:"auto_pause_on_expired"`
|
||||||
@@ -168,6 +169,9 @@ func InitFromDB() *Config {
|
|||||||
if v, _ := configDB.GetConfig("default_proxy"); v != "" {
|
if v, _ := configDB.GetConfig("default_proxy"); v != "" {
|
||||||
cfg.DefaultProxy = v
|
cfg.DefaultProxy = v
|
||||||
}
|
}
|
||||||
|
if v, _ := configDB.GetConfig("team_reg_proxy"); v != "" {
|
||||||
|
cfg.TeamRegProxy = v
|
||||||
|
}
|
||||||
if v, _ := configDB.GetConfig("mail_services"); v != "" {
|
if v, _ := configDB.GetConfig("mail_services"); v != "" {
|
||||||
var services []MailServiceConfig
|
var services []MailServiceConfig
|
||||||
if err := json.Unmarshal([]byte(v), &services); err == nil {
|
if err := json.Unmarshal([]byte(v), &services); err == nil {
|
||||||
@@ -207,6 +211,7 @@ func SaveToDB() error {
|
|||||||
|
|
||||||
configDB.SetConfig("proxy_enabled", strconv.FormatBool(cfg.ProxyEnabled))
|
configDB.SetConfig("proxy_enabled", strconv.FormatBool(cfg.ProxyEnabled))
|
||||||
configDB.SetConfig("default_proxy", cfg.DefaultProxy)
|
configDB.SetConfig("default_proxy", cfg.DefaultProxy)
|
||||||
|
configDB.SetConfig("team_reg_proxy", cfg.TeamRegProxy)
|
||||||
|
|
||||||
if len(cfg.MailServices) > 0 {
|
if len(cfg.MailServices) > 0 {
|
||||||
data, _ := json.Marshal(cfg.MailServices)
|
data, _ := json.Marshal(cfg.MailServices)
|
||||||
|
|||||||
Reference in New Issue
Block a user