feat: Introduce core application structure, configuration, monitoring, and team management features.
This commit is contained in:
@@ -11,14 +11,20 @@ import (
|
||||
|
||||
// MonitorSettings 监控设置
|
||||
type MonitorSettings struct {
|
||||
Target int `json:"target"`
|
||||
AutoAdd bool `json:"auto_add"`
|
||||
MinInterval int `json:"min_interval"`
|
||||
CheckInterval int `json:"check_interval"` // 自动补号检查间隔(秒)
|
||||
PollingEnabled bool `json:"polling_enabled"`
|
||||
PollingInterval int `json:"polling_interval"`
|
||||
ReplenishUseProxy bool `json:"replenish_use_proxy"` // 补号时使用代理
|
||||
BrowserType string `json:"browser_type"` // 授权浏览器引擎: chromedp 或 rod
|
||||
Target int `json:"target"`
|
||||
AutoAdd bool `json:"auto_add"`
|
||||
AutoRegister bool `json:"auto_register"` // 母号不足时自动注册
|
||||
AutoRegConcurrency int `json:"auto_reg_concurrency"` // 自动注册并发数
|
||||
AutoRegUseProxy bool `json:"auto_reg_use_proxy"` // 自动注册时使用代理
|
||||
MinInterval int `json:"min_interval"`
|
||||
CheckInterval int `json:"check_interval"` // 自动补号检查间隔(秒)
|
||||
PollingEnabled bool `json:"polling_enabled"`
|
||||
PollingInterval int `json:"polling_interval"`
|
||||
ReplenishUseProxy bool `json:"replenish_use_proxy"` // 补号时使用代理
|
||||
BrowserType string `json:"browser_type"` // 授权浏览器引擎: chromedp 或 rod
|
||||
MembersPerTeam int `json:"members_per_team"` // 每 Team 成员数
|
||||
ConcurrentTeams int `json:"concurrent_teams"` // 并发 Team 数
|
||||
S2AConcurrency int `json:"s2a_concurrency"` // 入库并发数
|
||||
}
|
||||
|
||||
// HandleGetMonitorSettings 获取监控设置
|
||||
@@ -34,14 +40,20 @@ func HandleGetMonitorSettings(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
settings := MonitorSettings{
|
||||
Target: 50,
|
||||
AutoAdd: false,
|
||||
MinInterval: 300,
|
||||
CheckInterval: 60,
|
||||
PollingEnabled: false,
|
||||
PollingInterval: 60,
|
||||
ReplenishUseProxy: false,
|
||||
BrowserType: "chromedp", // 默认使用 chromedp
|
||||
Target: 50,
|
||||
AutoAdd: false,
|
||||
AutoRegister: false,
|
||||
AutoRegConcurrency: 2,
|
||||
AutoRegUseProxy: false,
|
||||
MinInterval: 300,
|
||||
CheckInterval: 60,
|
||||
PollingEnabled: false,
|
||||
PollingInterval: 60,
|
||||
ReplenishUseProxy: false,
|
||||
BrowserType: "chromedp", // 默认使用 chromedp
|
||||
MembersPerTeam: 4, // 默认每 Team 4 个成员
|
||||
ConcurrentTeams: 2, // 默认并发 2 个 Team
|
||||
S2AConcurrency: 2, // 默认入库并发 2
|
||||
}
|
||||
|
||||
if val, _ := database.Instance.GetConfig("monitor_target"); val != "" {
|
||||
@@ -52,6 +64,17 @@ func HandleGetMonitorSettings(w http.ResponseWriter, r *http.Request) {
|
||||
if val, _ := database.Instance.GetConfig("monitor_auto_add"); val == "true" {
|
||||
settings.AutoAdd = true
|
||||
}
|
||||
if val, _ := database.Instance.GetConfig("monitor_auto_register"); val == "true" {
|
||||
settings.AutoRegister = true
|
||||
}
|
||||
if val, _ := database.Instance.GetConfig("monitor_auto_reg_concurrency"); val != "" {
|
||||
if v, err := strconv.Atoi(val); err == nil {
|
||||
settings.AutoRegConcurrency = v
|
||||
}
|
||||
}
|
||||
if val, _ := database.Instance.GetConfig("monitor_auto_reg_use_proxy"); val == "true" {
|
||||
settings.AutoRegUseProxy = true
|
||||
}
|
||||
if val, _ := database.Instance.GetConfig("monitor_min_interval"); val != "" {
|
||||
if v, err := strconv.Atoi(val); err == nil {
|
||||
settings.MinInterval = v
|
||||
@@ -76,6 +99,21 @@ func HandleGetMonitorSettings(w http.ResponseWriter, r *http.Request) {
|
||||
if val, _ := database.Instance.GetConfig("monitor_browser_type"); val != "" {
|
||||
settings.BrowserType = val
|
||||
}
|
||||
if val, _ := database.Instance.GetConfig("monitor_members_per_team"); val != "" {
|
||||
if v, err := strconv.Atoi(val); err == nil {
|
||||
settings.MembersPerTeam = v
|
||||
}
|
||||
}
|
||||
if val, _ := database.Instance.GetConfig("monitor_concurrent_teams"); val != "" {
|
||||
if v, err := strconv.Atoi(val); err == nil {
|
||||
settings.ConcurrentTeams = v
|
||||
}
|
||||
}
|
||||
if val, _ := database.Instance.GetConfig("monitor_s2a_concurrency"); val != "" {
|
||||
if v, err := strconv.Atoi(val); err == nil {
|
||||
settings.S2AConcurrency = v
|
||||
}
|
||||
}
|
||||
|
||||
Success(w, settings)
|
||||
}
|
||||
@@ -113,6 +151,22 @@ func HandleSaveMonitorSettings(w http.ResponseWriter, r *http.Request) {
|
||||
if err := database.Instance.SetConfig("monitor_auto_add", strconv.FormatBool(settings.AutoAdd)); err != nil {
|
||||
saveErrors = append(saveErrors, "auto_add: "+err.Error())
|
||||
}
|
||||
if err := database.Instance.SetConfig("monitor_auto_register", strconv.FormatBool(settings.AutoRegister)); err != nil {
|
||||
saveErrors = append(saveErrors, "auto_register: "+err.Error())
|
||||
}
|
||||
// 自动注册并发数 (1-10)
|
||||
autoRegConcurrency := settings.AutoRegConcurrency
|
||||
if autoRegConcurrency < 1 {
|
||||
autoRegConcurrency = 1
|
||||
} else if autoRegConcurrency > 10 {
|
||||
autoRegConcurrency = 10
|
||||
}
|
||||
if err := database.Instance.SetConfig("monitor_auto_reg_concurrency", strconv.Itoa(autoRegConcurrency)); err != nil {
|
||||
saveErrors = append(saveErrors, "auto_reg_concurrency: "+err.Error())
|
||||
}
|
||||
if err := database.Instance.SetConfig("monitor_auto_reg_use_proxy", strconv.FormatBool(settings.AutoRegUseProxy)); err != nil {
|
||||
saveErrors = append(saveErrors, "auto_reg_use_proxy: "+err.Error())
|
||||
}
|
||||
if err := database.Instance.SetConfig("monitor_min_interval", strconv.Itoa(settings.MinInterval)); err != nil {
|
||||
saveErrors = append(saveErrors, "min_interval: "+err.Error())
|
||||
}
|
||||
@@ -141,6 +195,36 @@ func HandleSaveMonitorSettings(w http.ResponseWriter, r *http.Request) {
|
||||
if err := database.Instance.SetConfig("monitor_browser_type", browserType); err != nil {
|
||||
saveErrors = append(saveErrors, "browser_type: "+err.Error())
|
||||
}
|
||||
// 每 Team 成员数 (1-10)
|
||||
membersPerTeam := settings.MembersPerTeam
|
||||
if membersPerTeam < 1 {
|
||||
membersPerTeam = 1
|
||||
} else if membersPerTeam > 10 {
|
||||
membersPerTeam = 10
|
||||
}
|
||||
if err := database.Instance.SetConfig("monitor_members_per_team", strconv.Itoa(membersPerTeam)); err != nil {
|
||||
saveErrors = append(saveErrors, "members_per_team: "+err.Error())
|
||||
}
|
||||
// 并发 Team 数 (1-10)
|
||||
concurrentTeams := settings.ConcurrentTeams
|
||||
if concurrentTeams < 1 {
|
||||
concurrentTeams = 1
|
||||
} else if concurrentTeams > 10 {
|
||||
concurrentTeams = 10
|
||||
}
|
||||
if err := database.Instance.SetConfig("monitor_concurrent_teams", strconv.Itoa(concurrentTeams)); err != nil {
|
||||
saveErrors = append(saveErrors, "concurrent_teams: "+err.Error())
|
||||
}
|
||||
// 入库并发数 (1-4)
|
||||
s2aConcurrency := settings.S2AConcurrency
|
||||
if s2aConcurrency < 1 {
|
||||
s2aConcurrency = 1
|
||||
} else if s2aConcurrency > 4 {
|
||||
s2aConcurrency = 4
|
||||
}
|
||||
if err := database.Instance.SetConfig("monitor_s2a_concurrency", strconv.Itoa(s2aConcurrency)); err != nil {
|
||||
saveErrors = append(saveErrors, "s2a_concurrency: "+err.Error())
|
||||
}
|
||||
|
||||
if len(saveErrors) > 0 {
|
||||
errMsg := "保存监控设置部分失败: " + saveErrors[0]
|
||||
|
||||
Reference in New Issue
Block a user