feat(user-secret): 代理设置只留账密,移除白名单与获取当前 IP 入口
青果改走 Authkey/Authpwd 直连隧道(不再要提取链接、模式锁账号密码), 极客同样去掉白名单区块与模式选择;useProxyWhitelist 随之删除。 后端 /client-ip 与白名单接口保留,供后续诊断用。
This commit is contained in:
@@ -84,7 +84,9 @@
|
|||||||
<div class="secret-card-desc">
|
<div class="secret-card-desc">
|
||||||
{{ proxyLocked
|
{{ proxyLocked
|
||||||
? '代理由管理员统一配置并锁定,客户端不可修改或清空;如需变更请联系管理员。'
|
? '代理由管理员统一配置并锁定,客户端不可修改或清空;如需变更请联系管理员。'
|
||||||
: '供客户端任务连接代理服务,支持静态代理地址或代理服务商的提取链接。' }}
|
: (proxyProvider === 'qingguo'
|
||||||
|
? '青果用 Authkey / Authpwd 直连隧道代理,无需填写提取链接。'
|
||||||
|
: '供客户端任务连接代理服务,支持静态代理地址或代理服务商的提取链接。') }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -106,7 +108,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="proxy-field">
|
<div v-if="proxyProvider !== 'qingguo'" class="proxy-field">
|
||||||
<label class="field-label" for="proxy-url">代理地址</label>
|
<label class="field-label" for="proxy-url">代理地址</label>
|
||||||
<input
|
<input
|
||||||
id="proxy-url"
|
id="proxy-url"
|
||||||
@@ -146,33 +148,13 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="proxy-plan-hint">
|
<div class="proxy-plan-hint">
|
||||||
青果通道提取返回的是隧道端点(如 tunpool-xxx.qg.net:16359),连接时要用这对账密做认证;只存在本机,不上报服务端。
|
青果用 Authkey / Authpwd 直连隧道代理,无需提取链接;账密只存在本机,不上报服务端。
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="retention-block">
|
|
||||||
<div class="field-label">代理模式</div>
|
|
||||||
<div class="retention-options">
|
|
||||||
<label
|
|
||||||
v-for="option in proxyModeOptions"
|
|
||||||
:key="option.value"
|
|
||||||
class="retention-option"
|
|
||||||
:class="{ 'retention-option--disabled': !proxyReady || busy || proxyLocked }"
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
v-model="proxyMode"
|
|
||||||
type="radio"
|
|
||||||
:value="option.value"
|
|
||||||
:disabled="!proxyReady || busy || proxyLocked"
|
|
||||||
@change="proxyDirty = true"
|
|
||||||
/>
|
|
||||||
<span>{{ option.label }}</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="proxySupported && proxyProvider === 'jikip'" class="retention-block">
|
<div v-if="proxySupported && proxyProvider === 'jikip'" class="retention-block">
|
||||||
<div class="field-label">jikip 套餐信息(余量查询 / 白名单添加)</div>
|
<div class="field-label">jikip 套餐信息(余量查询)
|
||||||
|
</div>
|
||||||
<div class="proxy-plan-row">
|
<div class="proxy-plan-row">
|
||||||
<input
|
<input
|
||||||
v-model="proxyPlanId"
|
v-model="proxyPlanId"
|
||||||
@@ -224,59 +206,25 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="proxy-plan-hint">
|
<div class="proxy-plan-hint">
|
||||||
填写后,下方余量按你自己的 jikip 套餐查询;套餐 key 仅用于白名单添加,保存后只显示掩码,留空保存则保留已存值。套餐 ID / 用户 ID / key 在 jikip 后台「我的套餐」「账户信息」「套餐列表」查看。
|
填写后,下方余量按你自己的 jikip 套餐查询;套餐 key 保存后只显示掩码,留空保存则保留已存值。套餐 ID / 用户 ID / key 在 jikip 后台「我的套餐」「账户信息」「套餐列表」查看。
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="proxySupported && proxyProvider === 'qingguo'" class="proxy-plan-hint">
|
<div v-else-if="proxySupported && proxyProvider === 'qingguo'" class="proxy-plan-hint">
|
||||||
青果的账户余量与通道用量请到青果后台查看;本客户端目前只做青果提取链接的连通性检测。
|
青果的账户余量与通道用量请到青果后台查看;本客户端目前只做青果提取链接的连通性检测。
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="whitelistVisible" class="retention-block">
|
|
||||||
<div class="field-label">白名单(把本机出口 IP 加到{{ whitelistProviderLabel }})</div>
|
|
||||||
<div class="proxy-plan-row">
|
|
||||||
<input
|
|
||||||
v-model="whitelistIp"
|
|
||||||
class="secret-input"
|
|
||||||
type="text"
|
|
||||||
placeholder="当前出口 IP,如 36.251.68.43"
|
|
||||||
autocomplete="off"
|
|
||||||
spellcheck="false"
|
|
||||||
:disabled="whitelistAdding"
|
|
||||||
@input="resetWhitelistStatus"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="check-btn"
|
|
||||||
:disabled="whitelistFetching || whitelistAdding"
|
|
||||||
@click="fetchCurrentIp"
|
|
||||||
>
|
|
||||||
{{ whitelistFetching ? '获取中...' : '获取当前 IP' }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="secret-actions">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="check-btn"
|
|
||||||
:disabled="!whitelistReady || whitelistAdding"
|
|
||||||
@click="addToWhitelist"
|
|
||||||
>
|
|
||||||
{{ whitelistAdding ? '加入中...' : '加入白名单' }}
|
|
||||||
</button>
|
|
||||||
<span v-if="whitelistStatusText" class="check-result" :class="whitelistResultClass">
|
|
||||||
{{ whitelistStatusText }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="proxy-plan-hint">{{ whitelistHint }}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="secret-actions">
|
<div class="secret-actions">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="check-btn"
|
class="check-btn"
|
||||||
:disabled="!proxyReady || busy || proxyChecking"
|
:disabled="!proxyReady || busy || proxyChecking || proxyProvider === 'qingguo'"
|
||||||
@click="runProxyCheck"
|
@click="runProxyCheck"
|
||||||
>
|
>
|
||||||
{{ proxyChecking ? '检测中...' : (proxyUrl.trim() && proxyDirty ? '检测输入地址(未保存)' : '检测配置代理') }}
|
{{ proxyChecking
|
||||||
|
? '检测中...'
|
||||||
|
: (proxyProvider === 'qingguo'
|
||||||
|
? '青果账密直连,无需检测'
|
||||||
|
: (proxyUrl.trim() && proxyDirty ? '检测输入地址(未保存)' : '检测配置代理')) }}
|
||||||
</button>
|
</button>
|
||||||
<span class="check-result" :class="proxyResultClass">
|
<span class="check-result" :class="proxyResultClass">
|
||||||
{{ proxyStatusText }}
|
{{ proxyStatusText }}
|
||||||
@@ -331,7 +279,6 @@ import {
|
|||||||
putMyApiSecret,
|
putMyApiSecret,
|
||||||
} from '@/shared/api/types/modules/user-secret'
|
} from '@/shared/api/types/modules/user-secret'
|
||||||
import { proxyUserId, readUserProxy, userProxyPatch } from '@/shared/utils/api-secret-proxy-config'
|
import { proxyUserId, readUserProxy, userProxyPatch } from '@/shared/utils/api-secret-proxy-config'
|
||||||
import { useProxyWhitelist } from '@/shared/composables/useProxyWhitelist'
|
|
||||||
import { useProxyBalance, useProxyPlan } from '@/shared/composables/useProxyPlan'
|
import { useProxyBalance, useProxyPlan } from '@/shared/composables/useProxyPlan'
|
||||||
import { createModuleView, type ModuleState } from '@/shared/utils/api-secret-module-view'
|
import { createModuleView, type ModuleState } from '@/shared/utils/api-secret-module-view'
|
||||||
|
|
||||||
@@ -380,9 +327,6 @@ const proxyChecking = ref(false)
|
|||||||
const proxyCheckResult = ref<UserApiSecretCheckResult | null>(null)
|
const proxyCheckResult = ref<UserApiSecretCheckResult | null>(null)
|
||||||
const proxyCheckError = ref('')
|
const proxyCheckError = ref('')
|
||||||
|
|
||||||
/** 套餐保存/清除后要清的白名单提示:套餐与白名单互相引用,用可变槽位解初始化顺序。 */
|
|
||||||
const resetWhitelistSink: { fn: () => void } = { fn: () => {} }
|
|
||||||
|
|
||||||
const { balance, balanceLoading, balanceText, loadBalance } = useProxyBalance({ proxyProvider })
|
const { balance, balanceLoading, balanceText, loadBalance } = useProxyBalance({ proxyProvider })
|
||||||
const {
|
const {
|
||||||
proxyPlanId,
|
proxyPlanId,
|
||||||
@@ -397,42 +341,9 @@ const {
|
|||||||
loadProxyPlan,
|
loadProxyPlan,
|
||||||
saveProxyPlanInfo,
|
saveProxyPlanInfo,
|
||||||
clearProxyPlanInfo,
|
clearProxyPlanInfo,
|
||||||
} = useProxyPlan({ proxyProvider, resetWhitelistStatus: () => resetWhitelistSink.fn(), loadBalance })
|
} = useProxyPlan({ proxyProvider, resetWhitelistStatus: () => {}, loadBalance })
|
||||||
|
|
||||||
const whitelist = useProxyWhitelist({
|
const proxyPlaceholder = 'https://api.jikip.com/ip-get?num=1&minute=3&key=... 或 http://user:pass@host:port'
|
||||||
proxyReady,
|
|
||||||
proxyProvider,
|
|
||||||
proxyMode,
|
|
||||||
proxyDirty,
|
|
||||||
proxyUrl,
|
|
||||||
proxyLocked,
|
|
||||||
proxyPlanConfigured,
|
|
||||||
proxyPlanKeyConfigured,
|
|
||||||
syncProxyToServer,
|
|
||||||
})
|
|
||||||
const {
|
|
||||||
whitelistIp,
|
|
||||||
whitelistFetching,
|
|
||||||
whitelistAdding,
|
|
||||||
whitelistResult,
|
|
||||||
whitelistError,
|
|
||||||
whitelistVisible,
|
|
||||||
whitelistProviderLabel,
|
|
||||||
whitelistReady,
|
|
||||||
whitelistHint,
|
|
||||||
whitelistStatusText,
|
|
||||||
whitelistResultClass,
|
|
||||||
fetchCurrentIp,
|
|
||||||
resetWhitelistStatus,
|
|
||||||
addToWhitelist,
|
|
||||||
} = whitelist
|
|
||||||
resetWhitelistSink.fn = resetWhitelistStatus
|
|
||||||
|
|
||||||
const proxyPlaceholder = computed(() =>
|
|
||||||
proxyProvider.value === 'qingguo'
|
|
||||||
? 'https://overseas.proxy.qg.net/get?key=...&num=1&format=json'
|
|
||||||
: 'https://api.jikip.com/ip-get?num=1&minute=3&key=... 或 http://user:pass@host:port',
|
|
||||||
)
|
|
||||||
|
|
||||||
const proxyStatusText = computed(() => {
|
const proxyStatusText = computed(() => {
|
||||||
if (proxyChecking.value) return '正在检测...'
|
if (proxyChecking.value) return '正在检测...'
|
||||||
@@ -458,11 +369,11 @@ const proxyResultClass = computed(() => {
|
|||||||
function selectProxyProvider(provider: ProxyProviderKey) {
|
function selectProxyProvider(provider: ProxyProviderKey) {
|
||||||
if (proxyProvider.value === provider) return
|
if (proxyProvider.value === provider) return
|
||||||
proxyProvider.value = provider
|
proxyProvider.value = provider
|
||||||
|
// 青果只支持账号密码直连,模式随供应商锁死;切回极客再让用户自选
|
||||||
|
if (provider === 'qingguo') proxyMode.value = 2
|
||||||
proxyDirty.value = true
|
proxyDirty.value = true
|
||||||
proxyCheckResult.value = null
|
proxyCheckResult.value = null
|
||||||
proxyCheckError.value = ''
|
proxyCheckError.value = ''
|
||||||
whitelistResult.value = null
|
|
||||||
whitelistError.value = ''
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -495,11 +406,6 @@ async function runProxyCheck() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const proxyModeOptions: Array<{ value: ProxyMode; label: string }> = [
|
|
||||||
{ value: 1, label: '白名单' },
|
|
||||||
{ value: 2, label: '账号密码' },
|
|
||||||
]
|
|
||||||
|
|
||||||
function ensureModuleState(moduleKey: string) {
|
function ensureModuleState(moduleKey: string) {
|
||||||
if (!moduleStates[moduleKey]) {
|
if (!moduleStates[moduleKey]) {
|
||||||
moduleStates[moduleKey] = { input: '', checking: false, result: null, error: '', lastCheckSource: '' }
|
moduleStates[moduleKey] = { input: '', checking: false, result: null, error: '', lastCheckSource: '' }
|
||||||
@@ -621,6 +527,8 @@ async function loadProxyConfig() {
|
|||||||
proxyProvider.value = own.url
|
proxyProvider.value = own.url
|
||||||
? own.provider
|
? own.provider
|
||||||
: normalizeProxyProvider(serverProxy.value?.channel ?? own.provider)
|
: normalizeProxyProvider(serverProxy.value?.channel ?? own.provider)
|
||||||
|
// 青果只走账密认证,历史配置若停在白名单也强制拉回账号密码
|
||||||
|
if (proxyProvider.value === 'qingguo') proxyMode.value = 2
|
||||||
proxyReady.value = true
|
proxyReady.value = true
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
proxyLoadFailed.value = true
|
proxyLoadFailed.value = true
|
||||||
@@ -695,11 +603,14 @@ async function saveAll(options: { requireAll?: boolean } = {}): Promise<boolean>
|
|||||||
if (props.showProxy && proxyReady.value && proxyDirty.value && !proxyLocked.value) {
|
if (props.showProxy && proxyReady.value && proxyDirty.value && !proxyLocked.value) {
|
||||||
const api = getPywebviewApi()
|
const api = getPywebviewApi()
|
||||||
if (!api?.save_config) throw new Error('当前客户端未提供代理配置保存能力')
|
if (!api?.save_config) throw new Error('当前客户端未提供代理配置保存能力')
|
||||||
const nextProxyUrl = proxyUrl.value.trim()
|
// 青果走账密直连隧道,不保存提取链接;切回极客时输入框里的旧值仍在
|
||||||
|
const tunnelMode = proxyProvider.value === 'qingguo'
|
||||||
|
const nextProxyUrl = tunnelMode ? '' : proxyUrl.value.trim()
|
||||||
|
const nextProxyMode = tunnelMode ? 2 : proxyMode.value
|
||||||
await api.save_config(
|
await api.save_config(
|
||||||
userProxyPatch(nextProxyUrl, proxyMode.value, proxyProvider.value, proxyAccount.value, proxyPassword.value) as DesktopConfigUpdate,
|
userProxyPatch(nextProxyUrl, nextProxyMode, proxyProvider.value, proxyAccount.value, proxyPassword.value) as DesktopConfigUpdate,
|
||||||
)
|
)
|
||||||
proxyUrl.value = nextProxyUrl
|
if (!tunnelMode) proxyUrl.value = nextProxyUrl
|
||||||
proxyDirty.value = false
|
proxyDirty.value = false
|
||||||
// 同上:地址已保存,本地「未保存」的检测文案不再适用
|
// 同上:地址已保存,本地「未保存」的检测文案不再适用
|
||||||
proxyCheckResult.value = null
|
proxyCheckResult.value = null
|
||||||
@@ -727,21 +638,8 @@ async function reload() {
|
|||||||
refreshSnapshots()
|
refreshSnapshots()
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(whitelistVisible, (visible) => {
|
|
||||||
if (visible && !whitelistIp.value.trim()) {
|
|
||||||
fetchCurrentIp()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
watch(proxyMode, () => {
|
|
||||||
whitelistResult.value = null
|
|
||||||
whitelistError.value = ''
|
|
||||||
})
|
|
||||||
|
|
||||||
watch(proxyProvider, (provider) => {
|
watch(proxyProvider, (provider) => {
|
||||||
whitelistResult.value = null
|
// 切到极客时补拉套餐信息(含套餐 key 是否已配置)
|
||||||
whitelistError.value = ''
|
|
||||||
// 切到极客时补拉套餐信息(含套餐 key 是否已配置),否则白名单按钮的可用态是旧的
|
|
||||||
if (provider === 'jikip' && proxySupported.value) {
|
if (provider === 'jikip' && proxySupported.value) {
|
||||||
void loadProxyPlan()
|
void loadProxyPlan()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,163 +0,0 @@
|
|||||||
import { computed, ref, type ComputedRef, type Ref } from 'vue'
|
|
||||||
import { ElMessage } from 'element-plus'
|
|
||||||
import {
|
|
||||||
addProxyWhitelist,
|
|
||||||
fetchClientIp,
|
|
||||||
type UserProxyWhitelistResult,
|
|
||||||
} from '@/shared/api/types/modules/user-secret'
|
|
||||||
import { resolvePublicIp } from '@/shared/utils/public-ip'
|
|
||||||
import type { ProxyMode } from '@/shared/bridges/pywebview'
|
|
||||||
import type { ProxyProviderKey } from '@/shared/utils/api-secret-channel'
|
|
||||||
|
|
||||||
export interface ProxyWhitelistDeps {
|
|
||||||
proxyReady: Ref<boolean>
|
|
||||||
proxyProvider: Ref<ProxyProviderKey>
|
|
||||||
proxyMode: Ref<ProxyMode>
|
|
||||||
proxyDirty: Ref<boolean>
|
|
||||||
proxyUrl: Ref<string>
|
|
||||||
proxyLocked: ComputedRef<boolean>
|
|
||||||
proxyPlanConfigured: Ref<boolean>
|
|
||||||
proxyPlanKeyConfigured: Ref<boolean>
|
|
||||||
syncProxyToServer: (url: string) => Promise<boolean>
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 代理供应商白名单:当前出口 IP、代加动作与可用态判定。 */
|
|
||||||
export function useProxyWhitelist(deps: ProxyWhitelistDeps) {
|
|
||||||
const {
|
|
||||||
proxyReady,
|
|
||||||
proxyProvider,
|
|
||||||
proxyMode,
|
|
||||||
proxyDirty,
|
|
||||||
proxyUrl,
|
|
||||||
proxyLocked,
|
|
||||||
proxyPlanConfigured,
|
|
||||||
proxyPlanKeyConfigured,
|
|
||||||
syncProxyToServer,
|
|
||||||
} = deps
|
|
||||||
|
|
||||||
const whitelistIp = ref('')
|
|
||||||
const whitelistFetching = ref(false)
|
|
||||||
const whitelistAdding = ref(false)
|
|
||||||
const whitelistResult = ref<UserProxyWhitelistResult | null>(null)
|
|
||||||
const whitelistError = ref('')
|
|
||||||
|
|
||||||
/** 白名单区:青果的 API 鉴权白名单始终相关;极客只有白名单授权(本地代理模式 1)才需要。 */
|
|
||||||
const whitelistVisible = computed(() =>
|
|
||||||
proxyReady.value
|
|
||||||
&& (proxyProvider.value === 'qingguo' || (proxyProvider.value === 'jikip' && proxyMode.value === 1)),
|
|
||||||
)
|
|
||||||
|
|
||||||
const whitelistProviderLabel = computed(() => (proxyProvider.value === 'qingguo' ? '青果' : '极客'))
|
|
||||||
|
|
||||||
const whitelistReady = computed(() => {
|
|
||||||
if (!whitelistVisible.value || !whitelistIp.value.trim() || proxyDirty.value) return false
|
|
||||||
if (!proxyUrl.value.trim()) return false
|
|
||||||
if (proxyProvider.value === 'jikip') {
|
|
||||||
return proxyPlanConfigured.value && proxyPlanKeyConfigured.value
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
|
|
||||||
const whitelistHint = computed(() => {
|
|
||||||
if (proxyDirty.value) {
|
|
||||||
return '代理设置有未保存的修改:先保存代理设置,再加入白名单(服务端按已保存的配置代加)。'
|
|
||||||
}
|
|
||||||
if (!proxyUrl.value.trim()) {
|
|
||||||
return '先在上方填写并保存代理提取链接,再加入白名单(服务端按已保存的配置代加)。'
|
|
||||||
}
|
|
||||||
if (proxyProvider.value === 'qingguo') {
|
|
||||||
return '青果用已保存的代理提取链接里的 Key 代加白名单,立即生效;刚改过提取链接时先保存代理设置。'
|
|
||||||
}
|
|
||||||
if (!proxyPlanKeyConfigured.value) {
|
|
||||||
return '先在下方「极客套餐信息」填写套餐 ID 和套餐 key(极客「套餐列表」里查看),再点加入白名单。'
|
|
||||||
}
|
|
||||||
return '极客白名单 1-2 分钟内生效;换网络或公网 IP 变化后需要重新加入。'
|
|
||||||
})
|
|
||||||
|
|
||||||
const whitelistStatusText = computed(() => whitelistError.value || whitelistResult.value?.message || '')
|
|
||||||
|
|
||||||
const whitelistResultClass = computed(() => ({
|
|
||||||
'check-result--ok': Boolean(whitelistResult.value) && !whitelistError.value,
|
|
||||||
'check-result--fail': Boolean(whitelistError.value),
|
|
||||||
}))
|
|
||||||
|
|
||||||
/** 自动填当前出口 IP;失败只提示可手填,不写任何猜测值。 */
|
|
||||||
function fetchCurrentIp() {
|
|
||||||
if (whitelistFetching.value) return
|
|
||||||
whitelistFetching.value = true
|
|
||||||
whitelistError.value = ''
|
|
||||||
whitelistResult.value = null
|
|
||||||
// 服务端回显优先:无影一类受限网络里第三方回显不可达,页面本身却能正常调自家接口
|
|
||||||
resolvePublicIp(async () => (await fetchClientIp()).ip)
|
|
||||||
.then((ip) => {
|
|
||||||
whitelistIp.value = ip
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
whitelistError.value = error instanceof Error ? error.message : '获取当前 IP 失败,请手动填写'
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
whitelistFetching.value = false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetWhitelistStatus() {
|
|
||||||
whitelistResult.value = null
|
|
||||||
whitelistError.value = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 加入白名单:服务端按已存代理配置选供应商;极客用套餐 ID+key,青果用链接里的 key。 */
|
|
||||||
function addToWhitelist() {
|
|
||||||
if (whitelistAdding.value) return
|
|
||||||
const ip = whitelistIp.value.trim()
|
|
||||||
if (!ip) {
|
|
||||||
ElMessage.warning('请先获取或填写当前出口 IP')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (proxyProvider.value === 'jikip' && !proxyPlanKeyConfigured.value) {
|
|
||||||
ElMessage.warning('请先在极客套餐信息里填写套餐 key')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
whitelistAdding.value = true
|
|
||||||
whitelistError.value = ''
|
|
||||||
whitelistResult.value = null
|
|
||||||
// 老版本只把代理存在本机:代加前先把当前链接+供应商同步到服务端,否则服务端没有 Key 可代加
|
|
||||||
const ensureServerConfig = proxyUrl.value.trim() && !proxyLocked.value
|
|
||||||
? syncProxyToServer(proxyUrl.value.trim())
|
|
||||||
: Promise.resolve(false)
|
|
||||||
ensureServerConfig
|
|
||||||
.then((synced) => {
|
|
||||||
// 上报失败时不能拿服务端旧链接里的 Key 代加;toast 已由 syncProxyToServer 给出
|
|
||||||
if (proxyUrl.value.trim() && !proxyLocked.value && !synced) return null
|
|
||||||
return addProxyWhitelist(ip)
|
|
||||||
})
|
|
||||||
.then((result) => {
|
|
||||||
if (!result) return
|
|
||||||
whitelistResult.value = result
|
|
||||||
ElMessage.success(result.message || '已加入白名单')
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
whitelistError.value = error instanceof Error ? error.message : '加入白名单失败'
|
|
||||||
ElMessage.error(whitelistError.value)
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
whitelistAdding.value = false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
whitelistIp,
|
|
||||||
whitelistFetching,
|
|
||||||
whitelistAdding,
|
|
||||||
whitelistResult,
|
|
||||||
whitelistError,
|
|
||||||
whitelistVisible,
|
|
||||||
whitelistProviderLabel,
|
|
||||||
whitelistReady,
|
|
||||||
whitelistHint,
|
|
||||||
whitelistStatusText,
|
|
||||||
whitelistResultClass,
|
|
||||||
fetchCurrentIp,
|
|
||||||
resetWhitelistStatus,
|
|
||||||
addToWhitelist,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user