feat(proxy): 支持多实例独立代理与短效API动态提取
- 实例配置独立:支持为每个实例单独配置 http/https/socks5 代理,避免单机多开挤兑触发斗鱼出口 IP 限流 - 动态 API 提取:原生支持星空代理等平台的 API 提取(兼容 JSON/文本格式),提供前端一键提取填入与连通性/延迟测速 - 定时前自动拉取:针对 3 分钟短效代理,支持在开抢前 15 秒自动提取并绑定最新 IP,并在预热前完成热连接与时间复校 - 修复复校竞态:将 resyncBeforeTrigger 从 3s 提升至 8s,确保三轮采样在开抢前顺利落盘,消除时钟漂移 - 验证方式:通过 go test ./... 全量测试与前端 vue-tsc/vite 编译,实测通过星空代理 API 解析测试用例
This commit is contained in:
@@ -43,7 +43,7 @@ func (a *App) SwitchActivity(id string) types.SwitchActivityResult {
|
||||
return types.SwitchActivityResult{Error: "配置保存失败: " + err.Error()}
|
||||
}
|
||||
a.setCfg(cfg)
|
||||
newClient := client.New(act, cfg.TimeAPIURL, a.getTrace())
|
||||
newClient := client.New(act, cfg.TimeAPIURL, a.getTrace(), a.effectiveProxyURL(cfg))
|
||||
a.setClient(newClient)
|
||||
if !a.scheduler.UpdateClient(newClient) {
|
||||
logger.LogEvent("活动", "warn", "抢购任务正在运行,调度器客户端将在下次抢购时生效")
|
||||
@@ -101,7 +101,8 @@ func (a *App) SaveSettings(cfg types.Config) types.SimpleResult {
|
||||
}
|
||||
|
||||
traceChanged := cfg.TraceEnabled != oldCfg.TraceEnabled || cfg.TraceMaxBody != oldCfg.TraceMaxBody
|
||||
clientChanged := traceChanged || cfg.TimeAPIURL != oldCfg.TimeAPIURL || cfg.Activity != oldCfg.Activity
|
||||
proxyChanged := cfg.ProxyEnabled != oldCfg.ProxyEnabled || cfg.ProxyURL != oldCfg.ProxyURL
|
||||
clientChanged := traceChanged || cfg.TimeAPIURL != oldCfg.TimeAPIURL || cfg.Activity != oldCfg.Activity || proxyChanged
|
||||
if traceChanged {
|
||||
a.replaceTrace(cfg)
|
||||
}
|
||||
@@ -110,12 +111,21 @@ func (a *App) SaveSettings(cfg types.Config) types.SimpleResult {
|
||||
a.setCfg(cfg)
|
||||
logger.SetMinLevel(cfg.LogLevel)
|
||||
a.scheduler.UpdateSettings(cfg.Concurrency, cfg.Attempts, cfg.RetryStages, cfg.SeckillMode)
|
||||
a.scheduler.UpdateProxySettings(cfg.ProxyEnabled, cfg.ProxyURL, cfg.ProxyAPI, cfg.AutoFetchProxyOnSchedule)
|
||||
if clientChanged {
|
||||
newClient := client.New(act, cfg.TimeAPIURL, a.getTrace())
|
||||
proxyURL := a.effectiveProxyURL(cfg)
|
||||
newClient := client.New(act, cfg.TimeAPIURL, a.getTrace(), proxyURL)
|
||||
a.setClient(newClient)
|
||||
if !a.scheduler.UpdateClient(newClient) {
|
||||
logger.LogEvent("配置", "warn", "抢购任务正在运行,客户端配置将在下次抢购时完整生效")
|
||||
}
|
||||
if proxyChanged {
|
||||
if proxyURL != "" {
|
||||
logger.LogEvent("代理", "success", "代理已生效: %s", proxyURL)
|
||||
} else {
|
||||
logger.LogEvent("代理", "info", "代理已停用,恢复直连")
|
||||
}
|
||||
}
|
||||
if sample, err := newClient.ServerTimeSample(); err == nil {
|
||||
logger.SetDouyuOffset(sample.Offset)
|
||||
} else {
|
||||
@@ -123,7 +133,7 @@ func (a *App) SaveSettings(cfg types.Config) types.SimpleResult {
|
||||
}
|
||||
}
|
||||
|
||||
logger.LogEvent("配置", "success", "配置已保存并生效: 日志等级=%s 并发=%d 重试=%d 重试阶段=%d 模式=%d trace=%v",
|
||||
cfg.LogLevel, cfg.Concurrency, cfg.Attempts, len(cfg.RetryStages), cfg.SeckillMode, cfg.TraceEnabled)
|
||||
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)
|
||||
return types.SimpleResult{Success: true}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user