Files
crawler-plugin/admin-frontend-vue/src/pages/account/ProxyEntryDialog.vue
T
huangzd1997 7e64c12dd6 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 闸门四面绿。
2026-11-02 15:18:41 +08:00

249 lines
7.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { reactive, ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { saveUserSecretModule } from '@/api/user-secrets'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { actionableErrorText } from '@/components/admin-feedback'
import {
PROXY_MODULE_KEY,
buildProxyEntryPayload,
emptyProxyEntryDraft,
validateProxyEntry,
type ProxyEntryDraft,
} from './user-secret-model.ts'
/**
* 后台代填/改代理(2026-11-02 脱敏后重做的交互)。
*
* 旧交互是 `window.prompt` 预填 `row.proxy.full` 整条提取链接——后端把这条读路套上
* `SecretMasking.maskProxy` 之后 `full` 恒空,预填必然是空的,照旧保存等于把空串顶上去、
* 或让管理员去别处翻原文。现在收**账密**、链接在本机现拼现发:
* - 青果:填 Authkey + Authpwd,`composeQingguoLink` 拼(青果产品页没有可复制的链接);
* - 极客:填极客自己的提取链接(它有可复制的链接)。
* 拼好的链接是一次性写载荷,只进 PUT 请求体:不回显、不回填、不进 tooltip、不给复制/导出旁路;
* 保存成功即清空输入位,重开必然要从头再填(这是脱敏的应然后果,界面直接把它说出来)。
*/
const props = defineProps<{
modelValue: boolean
userId: number | null
username: string
/** 后端已登记的供应商(只是预选中的单选框,不是凭据)。 */
provider?: string | null
locked?: boolean
}>()
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'saved'): void }>()
const draft = reactive<ProxyEntryDraft>(emptyProxyEntryDraft())
const errorText = ref('')
const busy = ref(false)
function resetDraft() {
Object.assign(draft, emptyProxyEntryDraft(props.provider))
errorText.value = ''
}
// 开与关都重刷:关的时候把已经打进内存的账密/链接抹掉,不留到下一次。
watch(() => props.modelValue, resetDraft)
function close() {
emit('update:modelValue', false)
}
async function save() {
if (props.userId == null) return
errorText.value = validateProxyEntry(draft)
if (errorText.value) return
const payload = buildProxyEntryPayload(draft)
if (!payload) {
errorText.value = '代理配置不完整,请重新填写'
return
}
busy.value = true
try {
await saveUserSecretModule(props.userId, PROXY_MODULE_KEY, payload.value, payload.channel)
showAdminFeedback(props.locked ? '已更新锁定代理' : '已代填并锁定代理', 'success')
emit('saved')
close()
} catch (error) {
// 文案以接口返回的 message 为准,前端不解释后端状态码
errorText.value = actionableErrorText(error)
showAdminFeedback(errorText.value, 'error')
} finally {
busy.value = false
Object.assign(draft, { authkey: '', authpwd: '', link: '' })
}
}
</script>
<template>
<div v-if="modelValue" class="modal-mask" @click.self="close">
<div class="modal" role="dialog" aria-modal="true" aria-labelledby="proxy-entry-title">
<h3 id="proxy-entry-title">{{ locked ? '改代理' : '代填代理' }}</h3>
<p class="modal-note">
为「{{ username || '该用户' }}」写入代理。出于凭据保护,后台不再下发已存的提取链接原文,
这里每次都重新填写;保存后界面只显示脱敏后的地址(不含 key/pwd)。
</p>
<div class="form-group">
<label>代理供应商</label>
<div class="radio-row">
<label class="radio-item">
<input v-model="draft.provider" type="radio" value="qingguo" />
<span>青果</span>
</label>
<label class="radio-item">
<input v-model="draft.provider" type="radio" value="jikip" />
<span>极客</span>
</label>
</div>
</div>
<template v-if="draft.provider === 'qingguo'">
<div class="form-group">
<label>Authkey</label>
<input v-model="draft.authkey" type="text" autocomplete="off" placeholder="青果产品页的 Authkey" />
</div>
<div class="form-group">
<label>Authpwd</label>
<input v-model="draft.authpwd" type="password" autocomplete="new-password" placeholder="青果产品页的 Authpwd" />
<span class="field-hint">青果只填 Authkey 会被判鉴权拒绝,两把都要填。</span>
</div>
</template>
<template v-else>
<div class="form-group">
<label>极客提取链接</label>
<input
v-model="draft.link"
type="password"
autocomplete="new-password"
placeholder="https://api.jikip.com/ip-get?..."
/>
<span class="field-hint">极客有可复制的提取链接,整条粘贴进来即可。</span>
</div>
</template>
<p v-if="errorText" class="modal-error">{{ errorText }}</p>
<div class="modal-actions">
<button class="btn" type="button" :disabled="busy" @click="save">
{{ busy ? '保存中…' : '保存' }}
</button>
<button class="btn btn-ghost" type="button" :disabled="busy" @click="close">取消</button>
</div>
</div>
</div>
</template>
<style scoped>
/* 与密钥列表页同一视觉语言(本页不用 el-* 标签:新增 el-* 要同步改按需注册表)。 */
.modal-mask {
position: fixed;
inset: 0;
z-index: 3000;
display: flex;
align-items: center;
justify-content: center;
padding: 40px 20px;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(6px);
}
.modal {
display: flex;
flex-direction: column;
width: min(520px, 100%);
max-height: 84vh;
padding: 22px 24px;
border: 1px solid #c7d7e5;
border-radius: 14px;
background: #ffffff;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
overflow-y: auto;
color: #24384d;
font-family: inherit;
}
.modal h3 {
margin: 0 0 10px;
font-size: 15px;
font-weight: 650;
}
.modal-note {
margin: 0 0 14px;
color: #5b6f83;
font-size: 12.5px;
line-height: 1.65;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 14px;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
.form-group input[type='text'],
.form-group input[type='password'] {
min-width: 0;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
outline: none;
}
.radio-row {
display: flex;
gap: 18px;
}
.radio-item {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 13.5px;
font-weight: 500;
color: #24384d;
}
.field-hint {
color: #7d8fa1;
font-size: 12px;
line-height: 1.6;
}
.modal-error {
margin: 0 0 10px;
color: #b04a5a;
font-size: 12.5px;
line-height: 1.6;
}
.modal-actions {
display: flex;
gap: 10px;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.btn-ghost {
background: #ffffff;
border-color: #c7d7e5;
color: #4f78a5;
}
</style>