feat(remote): 增加远端控制台与日志汇总导出
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"douyu_go/internal/config"
|
||||
"douyu_go/internal/constants"
|
||||
"douyu_go/internal/logger"
|
||||
"douyu_go/internal/remote"
|
||||
"douyu_go/internal/types"
|
||||
)
|
||||
|
||||
@@ -117,6 +118,9 @@ func (a *App) SaveSettings(cfg types.Config) types.ErrorResult {
|
||||
if cfg.LogLevel == "" {
|
||||
cfg.LogLevel = "info"
|
||||
}
|
||||
cfg.RemoteURL = strings.TrimSpace(cfg.RemoteURL)
|
||||
cfg.RemoteToken = strings.TrimSpace(cfg.RemoteToken)
|
||||
cfg.RemoteMachineName = strings.TrimSpace(cfg.RemoteMachineName)
|
||||
if proxyURL := a.effectiveProxyURL(cfg); proxyURL != "" {
|
||||
if _, err := client.ParseProxyURL(proxyURL); err != nil {
|
||||
logger.LogEvent("代理", "warn", "设置保存失败,代理地址无效: %v", err)
|
||||
@@ -137,6 +141,14 @@ func (a *App) SaveSettings(cfg types.Config) types.ErrorResult {
|
||||
return types.ErrorResult{Error: "AES 签名密钥长度应为 16、24 或 32 字节"}
|
||||
}
|
||||
}
|
||||
if cfg.RemoteEnabled {
|
||||
if strings.TrimSpace(cfg.RemoteURL) == "" {
|
||||
return types.ErrorResult{Error: "远端控制需要填写控制中心地址"}
|
||||
}
|
||||
if err := remote.ValidateServerURL(cfg.RemoteURL); err != nil {
|
||||
return types.ErrorResult{Error: "远端控制地址无效: " + err.Error()}
|
||||
}
|
||||
}
|
||||
|
||||
// 写入文件
|
||||
if err := config.SaveConfig(a.paths.ConfigFile, cfg); err != nil {
|
||||
@@ -161,6 +173,13 @@ func (a *App) SaveSettings(cfg types.Config) types.ErrorResult {
|
||||
logger.SetMinLevel(cfg.LogLevel)
|
||||
a.scheduler.UpdateSettings(cfg.Concurrency, cfg.Attempts, cfg.RetryStages, cfg.SeckillMode)
|
||||
a.scheduler.UpdateProxySettings(cfg)
|
||||
remoteChanged := cfg.RemoteEnabled != oldCfg.RemoteEnabled ||
|
||||
cfg.RemoteURL != oldCfg.RemoteURL ||
|
||||
cfg.RemoteToken != oldCfg.RemoteToken ||
|
||||
cfg.RemoteMachineName != oldCfg.RemoteMachineName
|
||||
if remoteChanged {
|
||||
a.configureRemote(cfg)
|
||||
}
|
||||
if clientChanged {
|
||||
proxyURL := a.effectiveProxyURL(cfg)
|
||||
newClient, clientErr := client.NewWithProxy(act, cfg.TimeAPIURL, a.getTrace(), proxyURL)
|
||||
@@ -186,7 +205,7 @@ func (a *App) SaveSettings(cfg types.Config) types.ErrorResult {
|
||||
}
|
||||
}
|
||||
|
||||
logger.LogEvent("配置", "success", "配置已保存并生效: 日志等级=%s 并发=%d 重试=%d 重试阶段=%d 模式=%d trace=%v 代理=%v",
|
||||
cfg.LogLevel, cfg.Concurrency, cfg.Attempts, len(cfg.RetryStages), cfg.SeckillMode, cfg.TraceEnabled, cfg.ProxyEnabled)
|
||||
logger.LogEvent("配置", "success", "配置已保存并生效: 日志等级=%s 并发=%d 重试=%d 重试阶段=%d 模式=%d trace=%v 代理=%v 远端=%v",
|
||||
cfg.LogLevel, cfg.Concurrency, cfg.Attempts, len(cfg.RetryStages), cfg.SeckillMode, cfg.TraceEnabled, cfg.ProxyEnabled, cfg.RemoteEnabled)
|
||||
return types.ErrorResult{Success: true}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user