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:
yml2213
2026-10-24 19:26:16 +08:00
parent 288109de2f
commit bc366fd6b9
12 changed files with 889 additions and 33 deletions
+14 -1
View File
@@ -3,6 +3,7 @@ package app
import (
"context"
"os"
"strings"
"sync"
"time"
@@ -125,6 +126,13 @@ func New(lease *config.InstanceLease, instanceErr error) *App {
return &App{instanceLease: lease, instanceErr: instanceErr}
}
func (a *App) effectiveProxyURL(cfg types.Config) string {
if cfg.ProxyEnabled {
return strings.TrimSpace(cfg.ProxyURL)
}
return ""
}
// Startup Wails 应用启动时调用。
func (a *App) Startup(ctx context.Context) {
a.ctx = ctx
@@ -171,9 +179,14 @@ func (a *App) Startup(ctx context.Context) {
act = activity.Default()
logger.LogEvent("活动", "warn", "配置中的活动 %q 未识别,已回退到默认活动 %s", a.cfg.Activity, act.DisplayName)
}
a.client = client.New(act, a.cfg.TimeAPIURL, a.getTrace())
proxyURL := a.effectiveProxyURL(a.cfg)
a.client = client.New(act, a.cfg.TimeAPIURL, a.getTrace(), proxyURL)
if proxyURL != "" {
logger.LogEvent("代理", "info", "已启用代理: %s", proxyURL)
}
a.font = imgpkg.LoadFont(a.paths.FontFiles)
a.scheduler = seckill.New(a.client, a.paths, a.font, a.cfg.Concurrency, a.cfg.Attempts, a.cfg.RetryStages, a.cfg.SeckillMode)
a.scheduler.UpdateProxySettings(a.cfg.ProxyEnabled, a.cfg.ProxyURL, a.cfg.ProxyAPI, a.cfg.AutoFetchProxyOnSchedule)
a.scheduler.SetStateChangeCallback(func(state string) {
runtime.EventsEmit(a.ctx, seckillStateEvent, state)
})