fix(proxy): 青果检测改真探并按供应商分码,三面收口凭据外漏与「无法判定」

用户报「青果也要加检测」,往下挖出四层假象,一次收口:

- 后端:probeProxy 的青果短路(过去无条件回「提取成功(青果隧道端点,连接鉴权在客户端)」,
  依据的注释已过期——存下来的链接里就带 key/pwd)删掉,改成真打一次提取,按供应商返回码
  分档出独立 check_code:channel_busy / invalid_key / forbidden / rate_limited /
  insufficient_balance / tunnel_unverified。文案出口一律抹 key/pwd。
- 后端:巡检遇 channel_busy 不落库也不推通知。通道被占不是「密钥坏了」而是「此刻问不出
  结论」,而巡检自己那一发真提取就要占掉唯一一条通道——落库等于把用户早上看到的
  「代理异常」写成我们自己造成的。
- 后端:余量口径按供应商分档。青果账号此前会落进「否则查平台套餐」那条,界面显示的是
  别人家的 jikip 余量(串档);青果不提供可鉴权的余量/余额查询(余额接口是控制台
  appid/appkey 签名档),这一档宁可返回「查不了」也不借极客的数。
- 后端:SecretMasking.maskProxy 的脏值回落不再套 mask()——它保后 4 字符,而青果的 pwd=
  恰好挂在末尾,等于把口令尾 4 位交给界面与日志;改成只交「像 host 的那一段」。
- 用户端:去掉「青果账密直连,无需检测」的 disabled 例外,未保存账密现拼链接送检;
  「无法判定」回落改成后端文案原样显示+可重试语义;代理卡不再套 LLM 渠道字典
  (「龙抬头」错标的真根因就在这行)。
- 后管:货源标签拆成两张互不相通的字典,代理列只读 masked 且不回落到原文,删掉
  user-select:all 的全选复制旁路,「修改代理」改成重填 Authkey/Authpwd 的弹窗。

判据:SecretMaskingTest(5)、UserProxyBalanceServiceTest(6)、UserApiSecretServiceTest
(+1 巡检不落库)、UserApiSecretCheckServiceTest(+138 行分码)、ProxyLinkKeyTest、
用户端 node 5 支+mount 10 支、后管 node 9 支+mount 8 支。后端整量 5187/0 失败,
full 闸门四面绿。
This commit is contained in:
2026-11-02 15:18:41 +08:00
parent 7f5437d012
commit 7e64c12dd6
24 changed files with 2062 additions and 204 deletions
@@ -5,7 +5,7 @@
<div class="secret-card-heading">
<div class="secret-card-title">
{{ module.moduleLabel }}
<span class="source-tag">{{ llmChannelLabel(moduleChannels[module.moduleKey]) }}</span>
<span class="source-tag">{{ moduleSourceLabel(module.moduleKey, moduleChannels[module.moduleKey]) }}</span>
<span class="status-pill" :class="statusPillClassOf(module.moduleKey)">
{{ statusPillTextOf(module.moduleKey) }}
</span>
@@ -212,21 +212,18 @@
</div>
</div>
<div v-else-if="proxySupported && proxyProvider === 'qingguo'" class="proxy-plan-hint">
青果的账户余量与通道用量请到青果后台查看;本客户端目前只做青果提取链接的连通性检测。
青果的套餐与通道用量以青果后台为准;这里的「检测」会真打一次提取并经隧道验连——
它会占掉你那一条通道的存活期(约 3 分钟),期间再点会得到「通道被占」,等释放后重点一次即可。
</div>
<div class="secret-actions">
<button
type="button"
class="check-btn"
:disabled="!proxyReady || busy || proxyChecking || proxyProvider === 'qingguo'"
:disabled="!proxyReady || busy || proxyChecking"
@click="runProxyCheck"
>
{{ proxyChecking
? '检测中...'
: (proxyProvider === 'qingguo'
? '青果账密直连,无需检测'
: (proxyUrl.trim() && proxyDirty ? '检测输入地址(未保存)' : '检测配置代理')) }}
{{ proxyCheckLabel }}
</button>
<span class="check-result" :class="proxyResultClass">
{{ proxyStatusText }}
@@ -237,10 +234,9 @@
<span v-if="proxyLoading">正在读取代理配置...</span>
<span v-else-if="proxyLoadFailed">代理配置读取失败,请关闭弹窗后重试</span>
<span v-else-if="!proxySupported">代理设置仅在桌面客户端中可用</span>
<span v-else-if="proxyProvider === 'qingguo'">供应商:青果 · 提取链接示例 https://overseas.proxy.qg.net/get?key=...&format=json</span>
<span v-else-if="balanceLoading">正在查询代理余量...</span>
<span v-else-if="balance">{{ balanceText }}</span>
<span v-else>余额查询暂不可用</span>
<span v-else>{{ balanceUnavailableText }}</span>
</div>
</section>
</div>
@@ -269,8 +265,10 @@ import {
LLM_CHANNEL_OPTIONS,
PROXY_PROVIDER_OPTIONS,
llmChannelLabel,
moduleSourceLabel,
normalizeLlmChannel,
normalizeProxyProvider,
proxyCheckValue,
proxyProviderLabel,
type LlmChannelKey,
type ProxyProviderKey,
@@ -287,7 +285,7 @@ import {
userProxyPatch,
} from '@/shared/utils/api-secret-proxy-config'
import { useProxyBalance, useProxyPlan } from '@/shared/composables/useProxyPlan'
import { createModuleView, type ModuleState } from '@/shared/utils/api-secret-module-view'
import { createModuleView, proxyCheckPresentation, type ModuleState } from '@/shared/utils/api-secret-module-view'
const props = withDefaults(
defineProps<{
@@ -334,7 +332,7 @@ const proxyChecking = ref(false)
const proxyCheckResult = ref<UserApiSecretCheckResult | null>(null)
const proxyCheckError = ref('')
const { balance, balanceLoading, balanceText, loadBalance } = useProxyBalance({ proxyProvider })
const { balance, balanceLoading, balanceText, balanceUnavailableText, loadBalance } = useProxyBalance({ proxyProvider })
const {
proxyPlanId,
proxyPlanUserId,
@@ -352,25 +350,42 @@ const {
const proxyPlaceholder = 'https://api.jikip.com/ip-get?num=1&minute=3&key=... 或 http://user:pass@host:port'
const proxyStatusText = computed(() => {
if (proxyChecking.value) return '正在检测...'
if (proxyCheckResult.value) {
const latency = proxyCheckResult.value.checkLatencyMs != null ? `(${proxyCheckResult.value.checkLatencyMs}ms)` : ''
if (proxyCheckResult.value.checkStatus === 'passed') return `代理连通正常${latency}`
return `${proxyCheckResult.value.checkMessage || '代理检测失败'}`
/**
* 「检测」要送出去的链接:没改动→undefined(服务端用库里那条),改了没保存→当前输入。
* 空串=草稿拼不出链接(青果没填 Authkey/极客把地址清空),这种检测必然失败,按钮与点击都拦住。
*/
const proxyCheckDraft = computed(() => proxyCheckValue({
provider: proxyProvider.value,
url: proxyUrl.value,
dirty: proxyDirty.value,
account: proxyAccount.value,
password: proxyPassword.value,
}))
const proxyDraftUnusable = computed(() => proxyDirty.value && !proxyCheckDraft.value)
/** 按钮文案要说清「检的是哪一条」:未保存的输入值,还是库里已存的配置。 */
const proxyCheckLabel = computed(() => {
if (proxyChecking.value) return '检测中...'
if (proxyDraftUnusable.value) {
return proxyProvider.value === 'qingguo' ? '请先填写青果账密' : '请先填写代理地址'
}
if (proxyCheckError.value) return proxyCheckError.value
return ''
if (proxyCheckDraft.value === undefined) return '检测配置代理'
return proxyProvider.value === 'qingguo' ? '检测输入账密(未保存)' : '检测输入地址(未保存)'
})
const proxyResultClass = computed(() => {
const status = proxyCheckResult.value?.checkStatus
return {
'check-result--ok': status === 'passed',
'check-result--fail': status === 'failed',
'check-result--warn': status === 'error',
}
})
/** 检测结果:文案原样用接口返回值,语气(颜色)只按后端 status 分档,见 proxyCheckPresentation。 */
const proxyCheckView = computed(() => proxyCheckPresentation(
proxyCheckResult.value,
proxyChecking.value,
proxyCheckError.value,
))
const proxyStatusText = computed(() => proxyCheckView.value.text)
const proxyResultClass = computed(() => ({
'check-result--ok': proxyCheckView.value.tone === 'ok',
'check-result--fail': proxyCheckView.value.tone === 'fail',
'check-result--warn': proxyCheckView.value.tone === 'retry',
}))
/** 切换代理供应商:只改本地选择,保存时与地址一起写入(检测也会按新供应商解析响应)。 */
function selectProxyProvider(provider: ProxyProviderKey) {
@@ -384,26 +399,30 @@ function selectProxyProvider(provider: ProxyProviderKey) {
}
/** 检测代理连通性:地址有改动时检测输入值(不落库),否则检测/落库已存值并刷新状态展示。 */
/** 检测代理连通性:改动过就送当前输入(不落库),没改动就送 undefined 让服务端检库里那条。 */
async function runProxyCheck() {
if (proxyChecking.value) return
const inputValue = proxyUrl.value.trim()
const dirty = proxyDirty.value && inputValue
if (proxyDraftUnusable.value) {
// 拼不出链接就别发一次必然失败的请求:空串送上去等于「不送 override」,服务端会去检库里那条旧链接
ElMessage.warning(proxyProvider.value === 'qingguo'
? '青果要先填 Authkey(Authpwd 也必填)才拼得出可检测的链接;填完直接点检测即可,不必先保存'
: '请先填写代理地址,再点检测')
return
}
const draft = proxyCheckDraft.value
const fromDraft = draft !== undefined
proxyChecking.value = true
proxyCheckError.value = ''
proxyCheckResult.value = null
try {
// 供应商一起提交:检测要按对应供应商解析提取响应(青果/极客返回体不同)
proxyCheckResult.value = await checkApiSecret('proxy', dirty ? inputValue : undefined, proxyProvider.value)
proxyCheckResult.value = await checkApiSecret('proxy', draft, proxyProvider.value)
const result = proxyCheckResult.value
if (result.checkStatus === 'failed') {
ElMessage.warning(
result.checkCode === 'insufficient_balance' ? '代理服务商余额不足,请充值或联系管理员' : (result.checkMessage || '代理不可用'),
)
} else if (result.checkStatus === 'error') {
ElMessage.warning(result.checkMessage || '暂时无法判定代理可用性')
if (result.checkStatus === 'passed') {
ElMessage.success(fromDraft ? '输入值连通正常(未保存)' : '代理连通正常')
} else {
ElMessage.success(dirty ? '输入地址连通正常(未保存)' : '代理连通正常')
// 弹窗与行内用同一段文字:都是接口返回的原文,前端不再按错误码另写一套措辞
ElMessage.warning(proxyCheckPresentation(result, false, '').text || '代理检测失败')
}
} catch (error) {
proxyCheckError.value = error instanceof Error ? error.message : '代理检测失败'