diff --git a/frontend-vue/src/shared/components/ApiSecretSettingsPanel.vue b/frontend-vue/src/shared/components/ApiSecretSettingsPanel.vue index a47fb36a6..cbc4eb9b8 100644 --- a/frontend-vue/src/shared/components/ApiSecretSettingsPanel.vue +++ b/frontend-vue/src/shared/components/ApiSecretSettingsPanel.vue @@ -84,7 +84,9 @@
{{ proxyLocked ? '代理由管理员统一配置并锁定,客户端不可修改或清空;如需变更请联系管理员。' - : '供客户端任务连接代理服务,支持静态代理地址或代理服务商的提取链接。' }} + : (proxyProvider === 'qingguo' + ? '青果用 Authkey / Authpwd 直连隧道代理,无需填写提取链接。' + : '供客户端任务连接代理服务,支持静态代理地址或代理服务商的提取链接。') }}
@@ -106,7 +108,7 @@ -
+
- 青果通道提取返回的是隧道端点(如 tunpool-xxx.qg.net:16359),连接时要用这对账密做认证;只存在本机,不上报服务端。 -
-
- -
-
代理模式
-
- + 青果用 Authkey / Authpwd 直连隧道代理,无需提取链接;账密只存在本机,不上报服务端。
-
jikip 套餐信息(余量查询 / 白名单添加)
+
jikip 套餐信息(余量查询) +
- 填写后,下方余量按你自己的 jikip 套餐查询;套餐 key 仅用于白名单添加,保存后只显示掩码,留空保存则保留已存值。套餐 ID / 用户 ID / key 在 jikip 后台「我的套餐」「账户信息」「套餐列表」查看。 + 填写后,下方余量按你自己的 jikip 套餐查询;套餐 key 保存后只显示掩码,留空保存则保留已存值。套餐 ID / 用户 ID / key 在 jikip 后台「我的套餐」「账户信息」「套餐列表」查看。
青果的账户余量与通道用量请到青果后台查看;本客户端目前只做青果提取链接的连通性检测。
-
-
白名单(把本机出口 IP 加到{{ whitelistProviderLabel }})
-
- - -
-
- - - {{ whitelistStatusText }} - -
-
{{ whitelistHint }}
-
-
{{ proxyStatusText }} @@ -331,7 +279,6 @@ import { putMyApiSecret, } from '@/shared/api/types/modules/user-secret' 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 { createModuleView, type ModuleState } from '@/shared/utils/api-secret-module-view' @@ -380,9 +327,6 @@ const proxyChecking = ref(false) const proxyCheckResult = ref(null) const proxyCheckError = ref('') -/** 套餐保存/清除后要清的白名单提示:套餐与白名单互相引用,用可变槽位解初始化顺序。 */ -const resetWhitelistSink: { fn: () => void } = { fn: () => {} } - const { balance, balanceLoading, balanceText, loadBalance } = useProxyBalance({ proxyProvider }) const { proxyPlanId, @@ -397,42 +341,9 @@ const { loadProxyPlan, saveProxyPlanInfo, clearProxyPlanInfo, -} = useProxyPlan({ proxyProvider, resetWhitelistStatus: () => resetWhitelistSink.fn(), loadBalance }) +} = useProxyPlan({ proxyProvider, resetWhitelistStatus: () => {}, loadBalance }) -const whitelist = useProxyWhitelist({ - 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 proxyPlaceholder = 'https://api.jikip.com/ip-get?num=1&minute=3&key=... 或 http://user:pass@host:port' const proxyStatusText = computed(() => { if (proxyChecking.value) return '正在检测...' @@ -458,11 +369,11 @@ const proxyResultClass = computed(() => { function selectProxyProvider(provider: ProxyProviderKey) { if (proxyProvider.value === provider) return proxyProvider.value = provider + // 青果只支持账号密码直连,模式随供应商锁死;切回极客再让用户自选 + if (provider === 'qingguo') proxyMode.value = 2 proxyDirty.value = true proxyCheckResult.value = null 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) { if (!moduleStates[moduleKey]) { moduleStates[moduleKey] = { input: '', checking: false, result: null, error: '', lastCheckSource: '' } @@ -621,6 +527,8 @@ async function loadProxyConfig() { proxyProvider.value = own.url ? own.provider : normalizeProxyProvider(serverProxy.value?.channel ?? own.provider) + // 青果只走账密认证,历史配置若停在白名单也强制拉回账号密码 + if (proxyProvider.value === 'qingguo') proxyMode.value = 2 proxyReady.value = true } catch (error) { proxyLoadFailed.value = true @@ -695,11 +603,14 @@ async function saveAll(options: { requireAll?: boolean } = {}): Promise if (props.showProxy && proxyReady.value && proxyDirty.value && !proxyLocked.value) { const api = getPywebviewApi() 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( - 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 // 同上:地址已保存,本地「未保存」的检测文案不再适用 proxyCheckResult.value = null @@ -727,21 +638,8 @@ async function reload() { refreshSnapshots() } -watch(whitelistVisible, (visible) => { - if (visible && !whitelistIp.value.trim()) { - fetchCurrentIp() - } -}) - -watch(proxyMode, () => { - whitelistResult.value = null - whitelistError.value = '' -}) - watch(proxyProvider, (provider) => { - whitelistResult.value = null - whitelistError.value = '' - // 切到极客时补拉套餐信息(含套餐 key 是否已配置),否则白名单按钮的可用态是旧的 + // 切到极客时补拉套餐信息(含套餐 key 是否已配置) if (provider === 'jikip' && proxySupported.value) { void loadProxyPlan() } diff --git a/frontend-vue/src/shared/composables/useProxyWhitelist.ts b/frontend-vue/src/shared/composables/useProxyWhitelist.ts deleted file mode 100644 index 03b18ccef..000000000 --- a/frontend-vue/src/shared/composables/useProxyWhitelist.ts +++ /dev/null @@ -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 - proxyProvider: Ref - proxyMode: Ref - proxyDirty: Ref - proxyUrl: Ref - proxyLocked: ComputedRef - proxyPlanConfigured: Ref - proxyPlanKeyConfigured: Ref - syncProxyToServer: (url: string) => Promise -} - -/** 代理供应商白名单:当前出口 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(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, - } -}