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
+244 -1
View File
@@ -1,8 +1,11 @@
<script setup lang="ts">
import { ref } from 'vue'
import { useSettings, type RetryStage } from '@/composables/useSettings'
import { useToast } from '@/composables/useToast'
import { TestProxy, FetchProxy } from '@wails/go/app/App'
const { settings, loadSettings, saveSettings } = useSettings()
const { showToast } = useToast()
const visible = ref(false)
const formData = ref({
@@ -15,15 +18,81 @@ const formData = ref({
attempts: 2,
retryStages: [] as RetryStage[],
seckillMode: 1,
xiaodianPageSize: 200
xiaodianPageSize: 200,
proxyEnabled: false,
proxyUrl: '',
proxyApi: '',
autoFetchProxyOnSchedule: false
})
const testingProxy = ref(false)
const testProxyResult = ref<{ success?: boolean; text?: string; error?: string } | null>(null)
const fetchingProxy = ref(false)
const handleTestProxy = async () => {
const target = formData.value.proxyUrl.trim()
if (!target) {
testProxyResult.value = { success: false, error: '请先输入代理地址' }
return
}
testingProxy.value = true
testProxyResult.value = null
try {
const res = await TestProxy(target)
if (res.success) {
testProxyResult.value = {
success: true,
text: `连通正常 | 出口 IP: ${res.ip}${res.region ? ' (' + res.region + ')' : ''} | 往返延迟: ${res.latency}ms`
}
} else {
testProxyResult.value = {
success: false,
error: res.error || '测试连接失败'
}
}
} catch (e: any) {
testProxyResult.value = {
success: false,
error: e.message || String(e)
}
} finally {
testingProxy.value = false
}
}
const handleFetchProxy = async () => {
const api = formData.value.proxyApi.trim()
if (!api) {
showToast('提取失败', '请先填写代理提取 API 链接', 'error')
return
}
fetchingProxy.value = true
testProxyResult.value = null
try {
const res = await FetchProxy(api)
if (res.success && res.proxyUrl) {
formData.value.proxyUrl = res.proxyUrl
formData.value.proxyEnabled = true
showToast('提取成功', `已获取代理: ${res.proxyUrl} (${res.region || ''})`, 'success')
// 自动触发一次连通性测速
handleTestProxy()
} else {
showToast('提取失败', res.error || '未能提取到有效代理', 'error')
}
} catch (e: any) {
showToast('提取失败', e.message || String(e), 'error')
} finally {
fetchingProxy.value = false
}
}
const open = async () => {
await loadSettings()
formData.value = {
...settings.value,
retryStages: settings.value.retryStages.map(s => ({ ...s }))
}
testProxyResult.value = null
visible.value = true
}
@@ -77,6 +146,86 @@ defineExpose({ open, close })
<div class="form-hint">用于获取斗鱼服务端时间,一般不需要修改</div>
</div>
<!-- 实例独立代理设置 (防多开 IP 限流/风控) -->
<div class="form-section">
<div class="form-section-title">🌐 实例独立代理设置 (防多开 IP 限流)</div>
<div class="form-group">
<div class="toggle-row">
<div>
<span class="toggle-label">启用代理</span>
<div class="form-hint">开启后本实例所有请求(校准、预热、锁单、支付)均走该代理出口</div>
</div>
<label class="toggle">
<input v-model="formData.proxyEnabled" type="checkbox">
<span class="toggle-slider"></span>
</label>
</div>
</div>
<div v-if="formData.proxyEnabled" class="proxy-config-area">
<!-- 静态/当前代理 -->
<div class="form-group">
<label class="form-label">当前代理地址 (IP:端口 或 隧道)</label>
<div class="input-with-button">
<input
v-model="formData.proxyUrl"
class="form-input"
type="text"
placeholder="例: http://115.230.134.174:40014 或 socks5://127.0.0.1:1080"
>
<button
type="button"
class="btn-action"
:disabled="testingProxy || !formData.proxyUrl"
@click="handleTestProxy"
>
<span v-if="testingProxy">测试中...</span>
<span v-else>⚡ 测试代理</span>
</button>
</div>
<div class="form-hint">支持 http、https、socks5(可带账号密码,格式: http://user:pass@ip:port)</div>
<!-- 测试结果展示 -->
<div v-if="testProxyResult" class="test-result-box" :class="testProxyResult.success ? 'success' : 'error'">
<span v-if="testProxyResult.success">✅ {{ testProxyResult.text }}</span>
<span v-else>❌ {{ testProxyResult.error }}</span>
</div>
</div>
<!-- 代理提取 API -->
<div class="form-group">
<label class="form-label">代理 API 提取链接 (星空/快代理/品赞等动态 IP)</label>
<div class="input-with-button">
<input
v-model="formData.proxyApi"
class="form-input"
type="text"
placeholder="粘贴代理平台的提取 URL,例如 http://api2.xkdaili.com/tools/XApi.ashx?..."
>
<button
type="button"
class="btn-action primary"
:disabled="fetchingProxy || !formData.proxyApi"
@click="handleFetchProxy"
>
<span v-if="fetchingProxy">提取中...</span>
<span v-else>🔄 提取并填入</span>
</button>
</div>
<div class="form-hint">支持返回 JSON 或纯文本格式的代理 API,点击后自动拉取并填入上方地址</div>
</div>
<!-- 定时抢购前自动拉取最新代理 -->
<div class="form-group">
<label class="checkbox-row">
<input v-model="formData.autoFetchProxyOnSchedule" type="checkbox">
<span class="checkbox-text">定时任务触发前 15 秒自动提取最新 IP</span>
</label>
<div class="form-hint">适用于 3~5 分钟短效代理:定时抢购触发前自动刷新 IP,确保开抢时代理不过期且连接最新</div>
</div>
</div>
</div>
<!-- 和平小店参数 -->
<div class="form-section">
<div class="form-section-title">和平小店商品列表</div>
@@ -605,6 +754,100 @@ defineExpose({ open, close })
font-size: 12px;
}
.input-with-button {
display: flex;
gap: 8px;
align-items: center;
}
.input-with-button .form-input {
flex: 1;
}
.btn-action {
height: 36px;
padding: 0 14px;
background: var(--surface-2);
border: 1px solid var(--line);
border-radius: var(--radius-sm);
color: var(--text-strong);
font-size: 12.5px;
cursor: pointer;
white-space: nowrap;
transition: .15s;
display: inline-flex;
align-items: center;
justify-content: center;
}
.btn-action:hover:not(:disabled) {
background: var(--surface-3, rgba(255, 255, 255, 0.08));
border-color: var(--accent);
}
.btn-action.primary {
background: var(--accent);
color: #fff;
border-color: transparent;
}
.btn-action.primary:hover:not(:disabled) {
opacity: 0.9;
}
.btn-action:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.test-result-box {
margin-top: 8px;
padding: 8px 12px;
border-radius: var(--radius-sm);
font-size: 12px;
line-height: 1.4;
}
.test-result-box.success {
background: rgba(34, 197, 94, 0.12);
color: #4ade80;
border: 1px solid rgba(34, 197, 94, 0.3);
}
.test-result-box.error {
background: rgba(239, 68, 68, 0.12);
color: #f87171;
border: 1px solid rgba(239, 68, 68, 0.3);
}
.checkbox-row {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
.checkbox-row input[type="checkbox"] {
width: 16px;
height: 16px;
accent-color: var(--accent);
cursor: pointer;
}
.checkbox-text {
font-size: 13px;
color: var(--text-strong);
font-weight: 500;
}
.proxy-config-area {
margin-top: 14px;
padding: 14px;
background: rgba(255, 255, 255, 0.03);
border: 1px solid var(--line);
border-radius: var(--radius-sm);
}
/* 动画 */
.modal-enter-active {
transition: all .2s ease;