feat(user-secret): 密钥设置支持 LLM 渠道与代理供应商切换
- 用户密钥新增 channel 列(V180):LLM 行存渠道 longtaitou/t8star,代理行存供应商 qingguo/jikip;存量与新建默认均回填 t8star/jikip(默认仍走贞贞与极客,手动可切) - 外观专利/货源查询按任务归属用户的密钥渠道路由 LLM 主机(渠道经 SecretUsageContext 下到工作线程,不逐层改签名);切到龙抬头时模型映射 gemini-3.1-flash-lite 并补 enable_thinking + thinking_budget=medium(对齐贞贞现网口径),检测链路刻意不思考 - 代理检测按供应商解析:青果 code 为字符串、隧道端点支持 域名:端口、 NO_AVAILABLE_CHANNEL 归为可重试;青果只验提取成功(账密只在客户端本地) - 密钥设置页:每个模块加渠道分段选择、代理卡加供应商选择与青果 Authkey/Authpwd (只存本机,不上报),切换渠道未重填密钥时拦住保存;换号继承带渠道与供应商 - 后管密钥管理三列显示渠道/供应商标签
This commit is contained in:
@@ -11,6 +11,8 @@ export type ApiSecretCheckStatus = 'unknown' | 'passed' | 'failed' | 'error'
|
||||
export interface UserApiSecretItem {
|
||||
moduleKey: string
|
||||
moduleLabel: string
|
||||
/** 货源:LLM 行为渠道(longtaitou/t8star),代理行为供应商(qingguo/jikip);未配置时服务端下发默认值。 */
|
||||
channel?: string | null
|
||||
masked: string
|
||||
/** 完整明文值:仅代理模块被后台代填并锁定时下发,供客户端写入本地配置;其余情况为空。 */
|
||||
full?: string | null
|
||||
@@ -65,6 +67,8 @@ export interface UserProxyPlan {
|
||||
export interface UserApiSecretMigrateItem {
|
||||
moduleKey: string
|
||||
value: string
|
||||
/** 货源(老客户端不上报,服务端按「贞贞/极客」回填存量口径)。 */
|
||||
channel?: string
|
||||
}
|
||||
|
||||
export function fetchMyApiSecrets() {
|
||||
@@ -73,11 +77,11 @@ export function fetchMyApiSecrets() {
|
||||
)
|
||||
}
|
||||
|
||||
export function putMyApiSecret(moduleKey: string, value: string) {
|
||||
export function putMyApiSecret(moduleKey: string, value: string, channel?: string) {
|
||||
return unwrapJavaResponse(
|
||||
put<JavaApiResponse<UserApiSecretItem>, { value: string }>(
|
||||
put<JavaApiResponse<UserApiSecretItem>, { value: string; channel?: string }>(
|
||||
buildJavaUrl(API_ENDPOINTS.userSecret.save.replace('{moduleKey}', encodeURIComponent(moduleKey))),
|
||||
{ value },
|
||||
channel ? { value, channel } : { value },
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -90,11 +94,11 @@ export function deleteMyApiSecret(moduleKey: string) {
|
||||
|
||||
/** value 非空时检测输入值(不落库);为空时检测服务端已存密钥并把结果落库。 */
|
||||
/** 检测连通性:服务端最多「首查 + 传输层失败重试一次」,最坏约 31s,故单独放宽超时。 */
|
||||
export function checkMyApiSecret(moduleKey: string, value?: string) {
|
||||
export function checkMyApiSecret(moduleKey: string, value?: string, channel?: string) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<UserApiSecretCheckResult>, { value?: string }>(
|
||||
post<JavaApiResponse<UserApiSecretCheckResult>, { value?: string; channel?: string }>(
|
||||
buildJavaUrl(API_ENDPOINTS.userSecret.check.replace('{moduleKey}', encodeURIComponent(moduleKey))),
|
||||
{ value },
|
||||
channel ? { value, channel } : { value },
|
||||
{ timeout: 60000 },
|
||||
),
|
||||
)
|
||||
|
||||
@@ -65,6 +65,12 @@ export interface VariantTaskQueryData {
|
||||
export interface DesktopConfig {
|
||||
proxy_url?: string;
|
||||
proxy_mode?: number | string;
|
||||
/** 代理供应商:qingguo(青果,默认)/ jikip(极客);老配置没有该键时按链接域名识别。 */
|
||||
proxy_provider?: string;
|
||||
/** 青果隧道端点的代理账号(Authkey);极客不需要。 */
|
||||
proxy_account?: string;
|
||||
/** 青果隧道端点的代理密码(Authpwd);极客不需要。 */
|
||||
proxy_password?: string;
|
||||
aliprice_usename?: string;
|
||||
aliprice_pwd?: string;
|
||||
[key: string]: unknown;
|
||||
@@ -73,13 +79,24 @@ export interface DesktopConfig {
|
||||
export interface DesktopConfigUpdate {
|
||||
proxy_url?: string;
|
||||
proxy_mode?: ProxyMode;
|
||||
/** 代理供应商:qingguo(青果,默认)/ jikip(极客)。 */
|
||||
proxy_provider?: string;
|
||||
/** 青果隧道代理账号/密码(Authkey/Authpwd);空串表示清除。 */
|
||||
proxy_account?: string;
|
||||
proxy_password?: string;
|
||||
current_uid?: string;
|
||||
/** 全局 proxy_url 的归属 uid(CR-04:只有 owner 匹配才允许回退)。 */
|
||||
proxy_uid?: string;
|
||||
/** 显式共享白名单:整机共享或指定 uid 列表(CR-04)。 */
|
||||
proxy_shared?: boolean;
|
||||
proxy_shared_uids?: string[];
|
||||
proxy_users?: Record<string, { proxy_url?: string; proxy_mode?: number }>;
|
||||
proxy_users?: Record<string, {
|
||||
proxy_url?: string;
|
||||
proxy_mode?: number;
|
||||
proxy_provider?: string;
|
||||
proxy_account?: string;
|
||||
proxy_password?: string;
|
||||
}>;
|
||||
/** 本机继承快照的作用域标记(CR-12:同一 app.json 才能继承)。 */
|
||||
api_secret_os_scope?: string;
|
||||
/** 登出时留给本机下个账号的密钥快照(结构由 shared/utils/api-secret-store 定义)。 */
|
||||
|
||||
@@ -2,8 +2,14 @@
|
||||
<div class="secret-settings-body">
|
||||
<section v-for="module in modules" :key="module.moduleKey" class="secret-card">
|
||||
<div class="secret-card-head">
|
||||
<div>
|
||||
<div class="secret-card-title">{{ module.moduleLabel }}</div>
|
||||
<div class="secret-card-heading">
|
||||
<div class="secret-card-title">
|
||||
{{ module.moduleLabel }}
|
||||
<span class="source-tag">{{ llmChannelLabel(moduleChannels[module.moduleKey]) }}</span>
|
||||
<span class="status-pill" :class="statusPillClassOf(module.moduleKey)">
|
||||
{{ statusPillTextOf(module.moduleKey) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="secret-card-desc">{{ descriptionOf(module.moduleKey) }}</div>
|
||||
</div>
|
||||
<button
|
||||
@@ -17,15 +23,40 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<input
|
||||
v-model="moduleStates[module.moduleKey].input"
|
||||
class="secret-input"
|
||||
type="password"
|
||||
:placeholder="placeholderOf(module.moduleKey)"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
:disabled="busy"
|
||||
/>
|
||||
<div class="source-picker" role="radiogroup" :aria-label="`${module.moduleLabel}渠道`">
|
||||
<button
|
||||
v-for="option in LLM_CHANNEL_OPTIONS"
|
||||
:key="option.key"
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="moduleChannels[module.moduleKey] === option.key"
|
||||
class="source-option"
|
||||
:class="{ 'source-option--active': moduleChannels[module.moduleKey] === option.key }"
|
||||
:disabled="busy"
|
||||
@click="selectChannel(module.moduleKey, option.key)"
|
||||
>
|
||||
<span class="source-option-label">{{ option.label }}</span>
|
||||
<span class="source-option-hint">{{ option.hint }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="secret-field">
|
||||
<label class="field-label" :for="`secret-input-${module.moduleKey}`">接口密钥</label>
|
||||
<input
|
||||
:id="`secret-input-${module.moduleKey}`"
|
||||
v-model="moduleStates[module.moduleKey].input"
|
||||
class="secret-input"
|
||||
type="password"
|
||||
:placeholder="placeholderOf(module.moduleKey)"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
:disabled="busy"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="channelSwitchNeedsValue(module.moduleKey)" class="inline-warn">
|
||||
已切换到「{{ llmChannelLabel(moduleChannels[module.moduleKey]) }}」,请填写该渠道的密钥后再保存(两家渠道的密钥不通用)。
|
||||
</div>
|
||||
|
||||
<div class="secret-actions">
|
||||
<button
|
||||
@@ -44,9 +75,10 @@
|
||||
|
||||
<section v-if="showProxy" class="secret-card">
|
||||
<div class="secret-card-head">
|
||||
<div>
|
||||
<div class="secret-card-heading">
|
||||
<div class="secret-card-title">
|
||||
代理设置
|
||||
<span class="source-tag">{{ proxyProviderLabel(proxyProvider) }}</span>
|
||||
<span v-if="proxyLocked" class="lock-tag">后台锁定</span>
|
||||
</div>
|
||||
<div class="secret-card-desc">
|
||||
@@ -57,6 +89,23 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="source-picker" role="radiogroup" aria-label="代理供应商">
|
||||
<button
|
||||
v-for="option in PROXY_PROVIDER_OPTIONS"
|
||||
:key="option.key"
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="proxyProvider === option.key"
|
||||
class="source-option"
|
||||
:class="{ 'source-option--active': proxyProvider === option.key }"
|
||||
:disabled="!proxyReady || busy || proxyLocked"
|
||||
@click="selectProxyProvider(option.key)"
|
||||
>
|
||||
<span class="source-option-label">{{ option.label }}</span>
|
||||
<span class="source-option-hint">{{ option.hint }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="proxy-field">
|
||||
<label class="field-label" for="proxy-url">代理地址</label>
|
||||
<input
|
||||
@@ -64,7 +113,7 @@
|
||||
v-model="proxyUrl"
|
||||
class="secret-input"
|
||||
type="text"
|
||||
placeholder="如 http://user:pass@host:port 或代理提取链接"
|
||||
:placeholder="proxyPlaceholder"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
:disabled="!proxyReady || busy || proxyLocked"
|
||||
@@ -72,6 +121,35 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="proxyReady && proxyProvider === 'qingguo'" class="retention-block">
|
||||
<div class="field-label">隧道代理账号(青果 Authkey / Authpwd)</div>
|
||||
<div class="proxy-plan-row">
|
||||
<input
|
||||
v-model="proxyAccount"
|
||||
class="secret-input"
|
||||
type="text"
|
||||
placeholder="Authkey,如 40F79A90"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
:disabled="busy || proxyLocked"
|
||||
@input="proxyDirty = true"
|
||||
/>
|
||||
<input
|
||||
v-model="proxyPassword"
|
||||
class="secret-input"
|
||||
type="password"
|
||||
placeholder="Authpwd"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
:disabled="busy || proxyLocked"
|
||||
@input="proxyDirty = true"
|
||||
/>
|
||||
</div>
|
||||
<div class="proxy-plan-hint">
|
||||
青果通道提取返回的是隧道端点(如 tunpool-xxx.qg.net:16359),连接时要用这对账密做认证;只存在本机,不上报服务端。
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="retention-block">
|
||||
<div class="field-label">代理模式</div>
|
||||
<div class="retention-options">
|
||||
@@ -93,7 +171,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="proxySupported" class="retention-block">
|
||||
<div v-if="proxySupported && proxyProvider === 'jikip'" class="retention-block">
|
||||
<div class="field-label">jikip 套餐信息(用于余量查询与预警)</div>
|
||||
<div class="proxy-plan-row">
|
||||
<input
|
||||
@@ -138,6 +216,9 @@
|
||||
填写后,下方余量按你自己的 jikip 套餐查询;留空则显示平台默认套餐。套餐 ID / 用户 ID 在 jikip 后台「我的套餐」和「账户信息」查看。
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="proxySupported && proxyProvider === 'qingguo'" class="proxy-plan-hint">
|
||||
青果的账户余量与通道用量请到青果后台查看;本客户端目前只做青果提取链接的连通性检测。
|
||||
</div>
|
||||
|
||||
<div class="secret-actions">
|
||||
<button
|
||||
@@ -157,6 +238,7 @@
|
||||
<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>
|
||||
@@ -184,6 +266,19 @@ import {
|
||||
type ServerProxySnapshot,
|
||||
type UserApiSecretCheckResult,
|
||||
} from '@/shared/utils/api-secret-store'
|
||||
import {
|
||||
DEFAULT_LLM_CHANNEL,
|
||||
DEFAULT_PROXY_PROVIDER,
|
||||
LLM_CHANNEL_OPTIONS,
|
||||
PROXY_PROVIDER_OPTIONS,
|
||||
detectProxyProviderFromUrl,
|
||||
llmChannelLabel,
|
||||
normalizeLlmChannel,
|
||||
normalizeProxyProvider,
|
||||
proxyProviderLabel,
|
||||
type LlmChannelKey,
|
||||
type ProxyProviderKey,
|
||||
} from '@/shared/utils/api-secret-channel'
|
||||
import { getPywebviewApi, type ProxyMode, type DesktopConfigUpdate } from '@/shared/bridges/pywebview'
|
||||
import { deleteMyApiSecret, putMyApiSecret, fetchProxyPlan, saveProxyPlan, clearProxyPlan } from '@/shared/api/types/modules/user-secret'
|
||||
import { PROXY_PLAN_CHANGED_EVENT } from '@/shared/utils/proxy-balance-alert'
|
||||
@@ -209,9 +304,15 @@ type ModuleState = {
|
||||
|
||||
const modules = ref(listApiSecretModules())
|
||||
const moduleStates = reactive<Record<string, ModuleState>>({})
|
||||
/** 每个模块当前选择的渠道:默认龙抬头,加载后以服务端已存值为准。 */
|
||||
const moduleChannels = reactive<Record<string, LlmChannelKey>>({})
|
||||
/** 用户手动切过渠道、但还没为这个渠道填写密钥:保存前必须拦住(两家密钥不通用)。 */
|
||||
const channelDirty = reactive<Record<string, boolean>>({})
|
||||
// 首次渲染即需可读:按模块清单预初始化状态(后续 refreshSnapshots 兜底补齐)
|
||||
for (const module of modules.value) {
|
||||
moduleStates[module.moduleKey] = { input: '', checking: false, result: null, error: '', lastCheckSource: '' }
|
||||
moduleChannels[module.moduleKey] = DEFAULT_LLM_CHANNEL
|
||||
channelDirty[module.moduleKey] = false
|
||||
}
|
||||
const snapshots = ref<Record<string, ApiSecretSnapshot>>({})
|
||||
const busy = ref(false)
|
||||
@@ -222,6 +323,10 @@ const proxyLocked = computed(() => Boolean(serverProxy.value?.locked && serverPr
|
||||
|
||||
const proxyUrl = ref('')
|
||||
const proxyMode = ref<ProxyMode>(1)
|
||||
const proxyProvider = ref<ProxyProviderKey>(DEFAULT_PROXY_PROVIDER)
|
||||
/** 青果隧道端点的代理账密(Authkey/Authpwd):只存本机 app.json,不上报服务端。 */
|
||||
const proxyAccount = ref('')
|
||||
const proxyPassword = ref('')
|
||||
const proxyLoading = ref(false)
|
||||
const proxyLoadFailed = ref(false)
|
||||
const proxyReady = ref(false)
|
||||
@@ -238,6 +343,12 @@ const proxyPlanConfigured = ref(false)
|
||||
const proxyPlanLoading = ref(false)
|
||||
const proxyPlanSaving = ref(false)
|
||||
|
||||
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(() => {
|
||||
if (proxyChecking.value) return '正在检测...'
|
||||
if (proxyCheckResult.value) {
|
||||
@@ -258,6 +369,15 @@ const proxyResultClass = computed(() => {
|
||||
}
|
||||
})
|
||||
|
||||
/** 切换代理供应商:只改本地选择,保存时与地址一起写入(检测也会按新供应商解析响应)。 */
|
||||
function selectProxyProvider(provider: ProxyProviderKey) {
|
||||
if (proxyProvider.value === provider) return
|
||||
proxyProvider.value = provider
|
||||
proxyDirty.value = true
|
||||
proxyCheckResult.value = null
|
||||
proxyCheckError.value = ''
|
||||
}
|
||||
|
||||
/** 检测代理连通性:地址有改动时检测输入值(不落库),否则检测/落库已存值并刷新状态展示。 */
|
||||
async function runProxyCheck() {
|
||||
if (proxyChecking.value) return
|
||||
@@ -267,7 +387,8 @@ async function runProxyCheck() {
|
||||
proxyCheckError.value = ''
|
||||
proxyCheckResult.value = null
|
||||
try {
|
||||
proxyCheckResult.value = await checkApiSecret('proxy', dirty ? inputValue : undefined)
|
||||
// 供应商一起提交:检测要按对应供应商解析提取响应(青果/极客返回体不同)
|
||||
proxyCheckResult.value = await checkApiSecret('proxy', dirty ? inputValue : undefined, proxyProvider.value)
|
||||
const result = proxyCheckResult.value
|
||||
if (result.checkStatus === 'failed') {
|
||||
ElMessage.warning(
|
||||
@@ -310,15 +431,34 @@ function ensureModuleState(moduleKey: string) {
|
||||
if (!moduleStates[moduleKey]) {
|
||||
moduleStates[moduleKey] = { input: '', checking: false, result: null, error: '', lastCheckSource: '' }
|
||||
}
|
||||
if (!moduleChannels[moduleKey]) {
|
||||
moduleChannels[moduleKey] = DEFAULT_LLM_CHANNEL
|
||||
}
|
||||
return moduleStates[moduleKey]
|
||||
}
|
||||
|
||||
/** 用户切换渠道:只改选择,保存时随密钥一起提交;已有密钥但没重新填写时给出提示。 */
|
||||
function selectChannel(moduleKey: string, channel: LlmChannelKey) {
|
||||
if (moduleChannels[moduleKey] === channel) return
|
||||
moduleChannels[moduleKey] = channel
|
||||
channelDirty[moduleKey] = true
|
||||
}
|
||||
|
||||
/** 切到新渠道但没填新密钥(且已有旧渠道密钥):保存前必须拦住。 */
|
||||
function channelSwitchNeedsValue(moduleKey: string) {
|
||||
return Boolean(channelDirty[moduleKey]) && !ensureModuleState(moduleKey).input.trim() && snapshotOf(moduleKey).exists
|
||||
}
|
||||
|
||||
function refreshSnapshots() {
|
||||
modules.value = listApiSecretModules()
|
||||
const next: Record<string, ApiSecretSnapshot> = {}
|
||||
for (const module of modules.value) {
|
||||
next[module.moduleKey] = getStoredApiSecretSnapshot(module.moduleKey as ApiSecretModuleKey)
|
||||
ensureModuleState(module.moduleKey)
|
||||
// 只在用户没主动切换过时跟服务端对齐,避免把手动选择回退掉
|
||||
if (!channelDirty[module.moduleKey]) {
|
||||
moduleChannels[module.moduleKey] = normalizeLlmChannel(next[module.moduleKey].channel)
|
||||
}
|
||||
}
|
||||
snapshots.value = next
|
||||
serverProxy.value = getServerProxySnapshot()
|
||||
@@ -337,7 +477,9 @@ function placeholderOf(moduleKey: string) {
|
||||
if (snapshot.exists) {
|
||||
return `已保存(${snapshot.masked || '****'}),输入新值可覆盖`
|
||||
}
|
||||
return '请输入 LLM 接口密钥'
|
||||
return moduleChannels[moduleKey] === 'longtaitou'
|
||||
? '请输入龙抬头接口密钥(sk-...)'
|
||||
: '请输入贞贞接口密钥(sk-...)'
|
||||
}
|
||||
|
||||
const CHECK_STATUS_TEXT: Record<ApiSecretCheckStatus, string> = {
|
||||
@@ -347,6 +489,26 @@ const CHECK_STATUS_TEXT: Record<ApiSecretCheckStatus, string> = {
|
||||
unknown: '已保存,未检测',
|
||||
}
|
||||
|
||||
function statusPillTextOf(moduleKey: string) {
|
||||
const state = ensureModuleState(moduleKey)
|
||||
if (state.checking) return '检测中'
|
||||
const status = state.result?.checkStatus || snapshotOf(moduleKey).checkStatus
|
||||
if (status === 'passed') return '可用'
|
||||
if (status === 'failed') return '不可用'
|
||||
if (status === 'error') return '待确认'
|
||||
return snapshotOf(moduleKey).exists ? '未检测' : '未配置'
|
||||
}
|
||||
|
||||
function statusPillClassOf(moduleKey: string) {
|
||||
const state = ensureModuleState(moduleKey)
|
||||
const status = state.result?.checkStatus || snapshotOf(moduleKey).checkStatus
|
||||
return {
|
||||
'status-pill--ok': status === 'passed',
|
||||
'status-pill--fail': status === 'failed',
|
||||
'status-pill--warn': status === 'error',
|
||||
}
|
||||
}
|
||||
|
||||
function formatTime(millis: number | null) {
|
||||
if (!millis) return ''
|
||||
const date = new Date(millis)
|
||||
@@ -400,7 +562,8 @@ async function runCheck(moduleKey: ApiSecretModuleKey) {
|
||||
state.lastCheckSource = inputValue ? 'input' : 'saved'
|
||||
try {
|
||||
// 不传 override 时服务端检测的是当前登录用户在密钥配置里保存的密钥(按 uid 绑定)
|
||||
const result = await checkApiSecret(moduleKey, inputValue || undefined)
|
||||
// 渠道一起提交:检测必须走所选渠道,否则「连通」是别的渠道的结论
|
||||
const result = await checkApiSecret(moduleKey, inputValue || undefined, moduleChannels[moduleKey])
|
||||
state.result = result
|
||||
if (result.checkStatus === 'failed') {
|
||||
ElMessage.warning(result.checkMessage || '密钥无效')
|
||||
@@ -427,6 +590,7 @@ async function clearModule(moduleKey: ApiSecretModuleKey) {
|
||||
state.input = ''
|
||||
state.result = null
|
||||
state.error = ''
|
||||
channelDirty[moduleKey] = false
|
||||
refreshSnapshots()
|
||||
ElMessage.success('已清空密钥')
|
||||
} catch (error) {
|
||||
@@ -451,22 +615,42 @@ function readUserProxy(config: Record<string, unknown> | null | undefined) {
|
||||
const own = (users[uid] ?? {}) as Record<string, unknown>
|
||||
const ownUrl = typeof own.proxy_url === 'string' ? own.proxy_url.trim() : ''
|
||||
if (ownUrl) {
|
||||
return { url: ownUrl, mode: Number(own.proxy_mode) === 2 ? 2 : 1 }
|
||||
return {
|
||||
url: ownUrl,
|
||||
mode: Number(own.proxy_mode) === 2 ? 2 : 1,
|
||||
provider: normalizeProxyProvider(own.proxy_provider ?? detectProxyProviderFromUrl(ownUrl)),
|
||||
account: typeof own.proxy_account === 'string' ? own.proxy_account : '',
|
||||
password: typeof own.proxy_password === 'string' ? own.proxy_password : '',
|
||||
}
|
||||
}
|
||||
}
|
||||
const url = typeof config?.proxy_url === 'string' ? config.proxy_url : ''
|
||||
return {
|
||||
url: typeof config?.proxy_url === 'string' ? config.proxy_url : '',
|
||||
url,
|
||||
mode: Number(config?.proxy_mode) === 2 ? 2 : 1,
|
||||
provider: normalizeProxyProvider(config?.proxy_provider ?? detectProxyProviderFromUrl(url)),
|
||||
account: typeof config?.proxy_account === 'string' ? config.proxy_account : '',
|
||||
password: typeof config?.proxy_password === 'string' ? config.proxy_password : '',
|
||||
}
|
||||
}
|
||||
|
||||
function userProxyPatch(nextProxyUrl: string, nextProxyMode: ProxyMode) {
|
||||
function userProxyPatch(
|
||||
nextProxyUrl: string,
|
||||
nextProxyMode: ProxyMode,
|
||||
provider: ProxyProviderKey,
|
||||
account: string,
|
||||
password: string,
|
||||
) {
|
||||
// 极客不需要这对账密:切过去时一并清空,避免残留串到别的供应商
|
||||
const credentials = provider === 'qingguo'
|
||||
? { proxy_account: account.trim(), proxy_password: password }
|
||||
: { proxy_account: '', proxy_password: '' }
|
||||
const uid = proxyUserId()
|
||||
if (uid === '0') {
|
||||
return { proxy_url: nextProxyUrl, proxy_mode: nextProxyMode }
|
||||
return { proxy_url: nextProxyUrl, proxy_mode: nextProxyMode, proxy_provider: provider, ...credentials }
|
||||
}
|
||||
const users: Record<string, unknown> = {}
|
||||
users[uid] = { proxy_url: nextProxyUrl, proxy_mode: nextProxyMode }
|
||||
users[uid] = { proxy_url: nextProxyUrl, proxy_mode: nextProxyMode, proxy_provider: provider, ...credentials }
|
||||
return { proxy_users: users }
|
||||
}
|
||||
|
||||
@@ -477,7 +661,7 @@ async function loadProxyConfig() {
|
||||
proxyDirty.value = false
|
||||
|
||||
const api = getPywebviewApi()
|
||||
proxySupported.value = Boolean(api?.read_config && api.save_config)
|
||||
proxySupported.value = Boolean(api?.read_config && api?.save_config)
|
||||
if (!api?.read_config || !api.save_config) {
|
||||
proxyUrl.value = ''
|
||||
proxyMode.value = 1
|
||||
@@ -490,6 +674,12 @@ async function loadProxyConfig() {
|
||||
const own = readUserProxy(config as Record<string, unknown>)
|
||||
proxyUrl.value = own.url
|
||||
proxyMode.value = (own.mode === 2 ? 2 : 1) as ProxyMode
|
||||
proxyAccount.value = own.account
|
||||
proxyPassword.value = own.password
|
||||
// 本地配置是权威(客户端任务链读的就是它);本地没写过时才用服务端里记的供应商
|
||||
proxyProvider.value = own.url
|
||||
? own.provider
|
||||
: normalizeProxyProvider(serverProxy.value?.channel ?? own.provider)
|
||||
proxyReady.value = true
|
||||
} catch (error) {
|
||||
proxyLoadFailed.value = true
|
||||
@@ -504,7 +694,8 @@ async function syncProxyToServer(url: string) {
|
||||
if (proxyUserId() === '0') return
|
||||
try {
|
||||
if (url) {
|
||||
await putMyApiSecret('proxy', url)
|
||||
// 供应商随地址一起上报:服务端检测要按供应商解析提取响应
|
||||
await putMyApiSecret('proxy', url, proxyProvider.value)
|
||||
} else {
|
||||
await deleteMyApiSecret('proxy')
|
||||
}
|
||||
@@ -515,6 +706,10 @@ async function syncProxyToServer(url: string) {
|
||||
}
|
||||
|
||||
async function loadProxyPlan() {
|
||||
if (proxyProvider.value !== 'jikip') {
|
||||
proxyPlanConfigured.value = false
|
||||
return
|
||||
}
|
||||
proxyPlanLoading.value = true
|
||||
try {
|
||||
const result = await fetchProxyPlan().catch((error) => {
|
||||
@@ -574,6 +769,11 @@ async function clearProxyPlanInfo() {
|
||||
}
|
||||
|
||||
async function loadBalance() {
|
||||
// 余量接口目前只有极客口径(jikip find-balance);青果不在客户端查询
|
||||
if (proxyProvider.value !== 'jikip') {
|
||||
balance.value = null
|
||||
return
|
||||
}
|
||||
balanceLoading.value = true
|
||||
try {
|
||||
const result = await fetchProxyBalanceSafely()
|
||||
@@ -597,6 +797,14 @@ async function loadBalance() {
|
||||
*/
|
||||
async function saveAll(options: { requireAll?: boolean } = {}): Promise<boolean> {
|
||||
if (busy.value || proxyLoading.value) return false
|
||||
// 切了渠道却只留着旧渠道的密钥:两家密钥不通用,必须让用户补填,否则保存后必然不可用
|
||||
const needRefill = modules.value.filter((module) => channelSwitchNeedsValue(module.moduleKey))
|
||||
if (needRefill.length) {
|
||||
ElMessage.warning(
|
||||
`已切换渠道,请填写该渠道的密钥:${needRefill.map((module) => module.moduleLabel).join('、')}`,
|
||||
)
|
||||
return false
|
||||
}
|
||||
const pendingModules = modules.value.filter((module) => ensureModuleState(module.moduleKey).input.trim())
|
||||
if (options.requireAll) {
|
||||
const missing = modules.value.filter(
|
||||
@@ -614,13 +822,14 @@ async function saveAll(options: { requireAll?: boolean } = {}): Promise<boolean>
|
||||
for (const module of pendingModules) {
|
||||
const moduleKey = module.moduleKey as ApiSecretModuleKey
|
||||
const state = ensureModuleState(module.moduleKey)
|
||||
await saveApiSecret(moduleKey, state.input.trim())
|
||||
await saveApiSecret(moduleKey, state.input.trim(), moduleChannels[module.moduleKey])
|
||||
state.input = ''
|
||||
// 输入值已保存:本地那次「检测输入值」的结果不再代表当前配置,清掉后展示统一走服务端快照
|
||||
// (保存前检测过的同一个值,服务端会沿用那次结果,快照里直接是「检测通过」)
|
||||
state.result = null
|
||||
state.lastCheckSource = ''
|
||||
state.error = ''
|
||||
channelDirty[module.moduleKey] = false
|
||||
}
|
||||
secretsSaved = true
|
||||
refreshSnapshots()
|
||||
@@ -629,13 +838,17 @@ async function saveAll(options: { requireAll?: boolean } = {}): Promise<boolean>
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.save_config) throw new Error('当前客户端未提供代理配置保存能力')
|
||||
const nextProxyUrl = proxyUrl.value.trim()
|
||||
await api.save_config(userProxyPatch(nextProxyUrl, proxyMode.value) as DesktopConfigUpdate)
|
||||
await api.save_config(
|
||||
userProxyPatch(nextProxyUrl, proxyMode.value, proxyProvider.value, proxyAccount.value, proxyPassword.value) as DesktopConfigUpdate,
|
||||
)
|
||||
proxyUrl.value = nextProxyUrl
|
||||
proxyDirty.value = false
|
||||
// 同上:地址已保存,本地「未保存」的检测文案不再适用
|
||||
proxyCheckResult.value = null
|
||||
proxyCheckError.value = ''
|
||||
await syncProxyToServer(nextProxyUrl)
|
||||
void loadProxyPlan()
|
||||
void loadBalance()
|
||||
}
|
||||
|
||||
// 保存后不再自动检测:检测一律由用户手动点击「检测」触发
|
||||
|
||||
@@ -22,6 +22,123 @@
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.secret-card-heading {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* 货源分段选择:两个选项并排,选中项描边高亮;不用原生 radio 是为了让「默认项」一眼可见 */
|
||||
.source-picker {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
||||
gap: 8px;
|
||||
margin: 10px 0 14px;
|
||||
}
|
||||
|
||||
.source-option {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 2px;
|
||||
padding: 9px 12px;
|
||||
border: 1px solid #3b4652;
|
||||
border-radius: 10px;
|
||||
background: #1b2026;
|
||||
color: #c8d3de;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
transition: border-color .15s ease, background .15s ease;
|
||||
}
|
||||
|
||||
.source-option:hover:not(:disabled) {
|
||||
border-color: #4c647d;
|
||||
}
|
||||
|
||||
.source-option--active {
|
||||
border-color: #5b96d6;
|
||||
background: #1f2a36;
|
||||
color: #eaf2fb;
|
||||
}
|
||||
|
||||
.source-option:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: .6;
|
||||
}
|
||||
|
||||
.source-option-label {
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.source-option-hint {
|
||||
color: #7f8a96;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.source-option--active .source-option-hint {
|
||||
color: #93a5b8;
|
||||
}
|
||||
|
||||
.secret-field .field-label {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.inline-warn {
|
||||
margin-top: 8px;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid #6b5a2e;
|
||||
border-radius: 8px;
|
||||
background: #2e2a1c;
|
||||
color: #e6c76a;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.status-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
margin-left: 6px;
|
||||
padding: 1px 8px;
|
||||
border: 1px solid #3b4652;
|
||||
border-radius: 999px;
|
||||
background: #1b2026;
|
||||
color: #909ba8;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.status-pill--ok {
|
||||
border-color: #2f5c44;
|
||||
background: #1b2a22;
|
||||
color: #7fd6a4;
|
||||
}
|
||||
|
||||
.status-pill--fail {
|
||||
border-color: #6b2f2f;
|
||||
background: #2a1c1c;
|
||||
color: #ff9b9b;
|
||||
}
|
||||
|
||||
.status-pill--warn {
|
||||
border-color: #6b5a2e;
|
||||
background: #2e2a1c;
|
||||
color: #e6c76a;
|
||||
}
|
||||
|
||||
.source-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
margin-left: 6px;
|
||||
padding: 1px 8px;
|
||||
border: 1px solid #3b4652;
|
||||
border-radius: 999px;
|
||||
background: #1b2026;
|
||||
color: #9fb3c8;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.secret-card-title {
|
||||
color: #eef4fb;
|
||||
font-size: 15px;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* 密钥「货源」选项:LLM 渠道(龙抬头/贞贞)与代理供应商(青果/极客)。
|
||||
*
|
||||
* 与后端 `LlmChannel` / `ProxyProvider` 枚举一一对应;用户密钥行上统一叫 `channel`:
|
||||
* LLM 模块存渠道 key,代理模块存供应商 key。
|
||||
*
|
||||
* 默认值口径(2026-10-30 用户拍板):新建默认贞贞 / 极客,龙抬头与青果手动切换;
|
||||
* 存量由服务端迁移回填为贞贞 / 极客,前端只按服务端下发的值回显,不自行改写。
|
||||
*/
|
||||
export type LlmChannelKey = 'longtaitou' | 't8star'
|
||||
export type ProxyProviderKey = 'qingguo' | 'jikip'
|
||||
|
||||
export interface SourceOption<T extends string> {
|
||||
key: T
|
||||
label: string
|
||||
hint: string
|
||||
}
|
||||
|
||||
export const LLM_CHANNEL_OPTIONS: Array<SourceOption<LlmChannelKey>> = [
|
||||
{ key: 'longtaitou', label: '龙抬头', hint: 'longtaitou.token6688.com' },
|
||||
{ key: 't8star', label: '贞贞', hint: 'ai.t8star.org(默认)' },
|
||||
]
|
||||
|
||||
export const PROXY_PROVIDER_OPTIONS: Array<SourceOption<ProxyProviderKey>> = [
|
||||
{ key: 'qingguo', label: '青果', hint: 'overseas.proxy.qg.net' },
|
||||
{ key: 'jikip', label: '极客', hint: 'api.jikip.com(默认)' },
|
||||
]
|
||||
|
||||
export const DEFAULT_LLM_CHANNEL: LlmChannelKey = 't8star'
|
||||
export const DEFAULT_PROXY_PROVIDER: ProxyProviderKey = 'jikip'
|
||||
|
||||
export function isLlmChannelKey(value: unknown): value is LlmChannelKey {
|
||||
return value === 'longtaitou' || value === 't8star'
|
||||
}
|
||||
|
||||
export function isProxyProviderKey(value: unknown): value is ProxyProviderKey {
|
||||
return value === 'qingguo' || value === 'jikip'
|
||||
}
|
||||
|
||||
/** 回显用:服务端值 → 选项;未知/为空按模块默认值。 */
|
||||
export function normalizeLlmChannel(value: unknown): LlmChannelKey {
|
||||
return isLlmChannelKey(value) ? value : DEFAULT_LLM_CHANNEL
|
||||
}
|
||||
|
||||
/** 按提取链接域名识别供应商:老配置只存了链接、没存供应商时兜底(识别不出返回 null)。 */
|
||||
export function detectProxyProviderFromUrl(url: unknown): ProxyProviderKey | null {
|
||||
const text = typeof url === 'string' ? url.trim().toLowerCase() : ''
|
||||
if (!text) return null
|
||||
if (text.includes('jikip.cn') || text.includes('jikip.com')) return 'jikip'
|
||||
if (text.includes('qg.net')) return 'qingguo'
|
||||
return null
|
||||
}
|
||||
|
||||
export function normalizeProxyProvider(value: unknown): ProxyProviderKey {
|
||||
return isProxyProviderKey(value) ? value : DEFAULT_PROXY_PROVIDER
|
||||
}
|
||||
|
||||
export function llmChannelLabel(value: unknown): string {
|
||||
const key = normalizeLlmChannel(value)
|
||||
return LLM_CHANNEL_OPTIONS.find((option) => option.key === key)?.label || key
|
||||
}
|
||||
|
||||
export function proxyProviderLabel(value: unknown): string {
|
||||
const key = normalizeProxyProvider(value)
|
||||
return PROXY_PROVIDER_OPTIONS.find((option) => option.key === key)?.label || key
|
||||
}
|
||||
@@ -44,12 +44,14 @@ export interface ApiSecretInheritanceHost {
|
||||
moduleKeys(): Set<string>
|
||||
readSecret(moduleKey: string): string
|
||||
writeSecret(moduleKey: string, value: string): void
|
||||
/** 该模块密钥所属货源(longtaitou/t8star);旧实现可不提供,缺省按「存量=贞贞」处理。 */
|
||||
readSecretChannel?(moduleKey: string): string
|
||||
readConfig(): Promise<Record<string, unknown> | null>
|
||||
saveConfig(patch: Record<string, unknown>): Promise<unknown>
|
||||
readLocalProxy(
|
||||
config: Record<string, unknown> | null | undefined,
|
||||
uid: string,
|
||||
): { url: string; mode: SecretProxyMode }
|
||||
): { url: string; mode: SecretProxyMode; provider?: string }
|
||||
}
|
||||
|
||||
export interface InheritanceOutcome {
|
||||
@@ -66,8 +68,15 @@ export type InheritedSecretStash = {
|
||||
savedAt: number
|
||||
osUserScope: string
|
||||
secrets: Record<string, string>
|
||||
/**
|
||||
* 每个模块密钥的货源(longtaitou/t8star)。旧快照没有这个字段:那时的密钥都是贞贞发出来的,
|
||||
* 缺省交给服务端按「存量=贞贞」回填,不能按新建默认(龙抬头)落库。
|
||||
*/
|
||||
secretChannels: Record<string, string>
|
||||
proxyUrl: string
|
||||
proxyMode: SecretProxyMode
|
||||
/** 代理供应商(qingguo/jikip);旧快照缺省 → 服务端按链接域名识别。 */
|
||||
proxyProvider: string
|
||||
}
|
||||
|
||||
export type InheritanceStashRead =
|
||||
@@ -145,6 +154,16 @@ export function readInheritedSecretStash(
|
||||
}
|
||||
const proxyUrl = text(proxyRaw)
|
||||
if (!Object.keys(secrets).length && !proxyUrl) return { state: 'invalid' }
|
||||
// 货源字段是可选的(旧快照没有):结构不符只丢掉该字段,不整份判 invalid
|
||||
const channelRecord = asRecord(record.secretChannels)
|
||||
const secretChannels: Record<string, string> = {}
|
||||
if (channelRecord) {
|
||||
for (const [moduleKey, channel] of Object.entries(channelRecord)) {
|
||||
if (allowed.has(moduleKey) && typeof channel === 'string' && channel.trim()) {
|
||||
secretChannels[moduleKey] = channel.trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
state: 'valid',
|
||||
stash: {
|
||||
@@ -154,8 +173,10 @@ export function readInheritedSecretStash(
|
||||
savedAt,
|
||||
osUserScope,
|
||||
secrets,
|
||||
secretChannels,
|
||||
proxyUrl,
|
||||
proxyMode: Number(record.proxyMode) === 2 ? 2 : 1,
|
||||
proxyProvider: text(record.proxyProvider),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -181,9 +202,14 @@ export async function captureSecretsForInheritance(host: ApiSecretInheritanceHos
|
||||
if (uid === '0') return
|
||||
const epoch = host.currentEpoch()
|
||||
const secrets: Record<string, string> = {}
|
||||
const secretChannels: Record<string, string> = {}
|
||||
for (const moduleKey of host.moduleKeys()) {
|
||||
const value = host.readSecret(moduleKey).trim()
|
||||
if (value) secrets[moduleKey] = value
|
||||
if (value) {
|
||||
secrets[moduleKey] = value
|
||||
const channel = host.readSecretChannel?.(moduleKey) || ''
|
||||
if (channel) secretChannels[moduleKey] = channel
|
||||
}
|
||||
}
|
||||
const config = await withTimeout(host.readConfig(), BRIDGE_TIMEOUT_MS).catch((error) => {
|
||||
console.warn('[api-secret] 登出时读取本机配置失败,继承快照将不含代理:', error)
|
||||
@@ -201,8 +227,10 @@ export async function captureSecretsForInheritance(host: ApiSecretInheritanceHos
|
||||
savedAt: Date.now(),
|
||||
osUserScope,
|
||||
secrets,
|
||||
secretChannels,
|
||||
proxyUrl: proxy.url,
|
||||
proxyMode: proxy.mode,
|
||||
proxyProvider: proxy.provider || '',
|
||||
}
|
||||
: null
|
||||
await withTimeout(host.saveConfig({ [OS_SCOPE_KEY]: osUserScope, [INHERIT_STASH_KEY]: stash }), BRIDGE_TIMEOUT_MS)
|
||||
@@ -241,9 +269,12 @@ export async function applyInheritedSecrets(
|
||||
if (uid === '0') return { count: 0, notice: null, cleared: false }
|
||||
const epoch = host.currentEpoch()
|
||||
const serverHas = new Set(serverItems.filter((item) => item?.exists).map((item) => item.moduleKey))
|
||||
const pending: Array<{ moduleKey: string; value: string }> = []
|
||||
const pending: Array<{ moduleKey: string; value: string; channel?: string }> = []
|
||||
for (const [moduleKey, value] of Object.entries(stash.secrets)) {
|
||||
if (!serverHas.has(moduleKey)) pending.push({ moduleKey, value })
|
||||
if (serverHas.has(moduleKey)) continue
|
||||
// 渠道随密钥一起继承:快照没有渠道(旧版本)时留空,由服务端按「存量=贞贞」回填
|
||||
const channel = stash.secretChannels?.[moduleKey]
|
||||
pending.push(channel ? { moduleKey, value, channel } : { moduleKey, value })
|
||||
}
|
||||
// 本机已有代理时以本机为准:它会被代理补报逻辑上报给当前账号,
|
||||
// 这里再塞上一个账号的代理会让「服务端查商标」和「客户端跑任务」走两条不同的出口。
|
||||
@@ -254,7 +285,11 @@ export async function applyInheritedSecrets(
|
||||
&& !serverProxyItem?.exists
|
||||
&& !serverProxyItem?.locked
|
||||
&& !ownProxy
|
||||
if (inheritProxy) pending.push({ moduleKey: 'proxy', value: stash.proxyUrl })
|
||||
if (inheritProxy) {
|
||||
pending.push(stash.proxyProvider
|
||||
? { moduleKey: 'proxy', value: stash.proxyUrl, channel: stash.proxyProvider }
|
||||
: { moduleKey: 'proxy', value: stash.proxyUrl })
|
||||
}
|
||||
if (!pending.length) {
|
||||
await clearInheritedSecrets(host)
|
||||
return { count: 0, notice: null, cleared: true }
|
||||
@@ -272,7 +307,13 @@ export async function applyInheritedSecrets(
|
||||
}
|
||||
const patch: Record<string, unknown> = { [INHERIT_STASH_KEY]: null }
|
||||
if (inheritProxy) {
|
||||
patch.proxy_users = { [uid]: { proxy_url: stash.proxyUrl, proxy_mode: stash.proxyMode } }
|
||||
patch.proxy_users = {
|
||||
[uid]: {
|
||||
proxy_url: stash.proxyUrl,
|
||||
proxy_mode: stash.proxyMode,
|
||||
...(stash.proxyProvider ? { proxy_provider: stash.proxyProvider } : {}),
|
||||
},
|
||||
}
|
||||
}
|
||||
await host.saveConfig(patch).catch((error) => {
|
||||
console.warn('[api-secret] 继承配置已写入服务端,但写回本机配置失败:', error)
|
||||
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
type PendingApiSecretInheritance,
|
||||
} from './api-secret-inheritance.ts'
|
||||
import { withTimeout } from './promise-timeout.ts'
|
||||
import { detectProxyProviderFromUrl } from './api-secret-channel.ts'
|
||||
import type { DesktopConfigUpdate } from '../bridges/pywebview.ts'
|
||||
|
||||
export type { ApiSecretModuleKey, ApiSecretCheckStatus }
|
||||
@@ -55,6 +56,8 @@ export interface ApiSecretSnapshot {
|
||||
value: string
|
||||
/** 服务端脱敏值(权威展示,如 sk-a****1234)。 */
|
||||
masked: string
|
||||
/** 货源:LLM 行为渠道(longtaitou/t8star),代理为供应商(qingguo/jikip);空串=服务端未标注。 */
|
||||
channel: string
|
||||
exists: boolean
|
||||
/** 是否由后台代填并锁定:锁定时客户端不可修改或清空(当前仅代理模块)。 */
|
||||
locked: boolean
|
||||
@@ -174,6 +177,7 @@ function emptyEntry(): ApiSecretCacheEntry {
|
||||
schema: 2,
|
||||
value: '',
|
||||
masked: '',
|
||||
channel: '',
|
||||
exists: false,
|
||||
locked: false,
|
||||
checkStatus: 'unknown',
|
||||
@@ -208,6 +212,7 @@ function readMirror(moduleKey: string): ApiSecretCacheEntry | null {
|
||||
schema: 2,
|
||||
value: typeof parsed.value === 'string' ? parsed.value : '',
|
||||
masked: typeof parsed.masked === 'string' ? parsed.masked : '',
|
||||
channel: typeof parsed.channel === 'string' ? parsed.channel : '',
|
||||
exists: Boolean(parsed.exists),
|
||||
locked: Boolean(parsed.locked),
|
||||
checkStatus: normalizeCheckStatus(parsed.checkStatus),
|
||||
@@ -331,6 +336,8 @@ function applyServerItem(moduleKey: string, item: UserApiSecretItem) {
|
||||
// 明文仅来自本地输入/迁移,服务端不下发
|
||||
value: current.value,
|
||||
masked: item.masked || '',
|
||||
// 货源以服务端为准;服务端未下发(老版本后端)时保留本地值
|
||||
channel: item.channel || current.channel,
|
||||
exists: Boolean(item.exists),
|
||||
locked: Boolean(item.locked),
|
||||
checkStatus: normalizeCheckStatus(item.checkStatus),
|
||||
@@ -691,30 +698,39 @@ function isSharedProxy(config: Record<string, unknown> | null | undefined, uid:
|
||||
function readLocalProxyEntry(
|
||||
config: Record<string, unknown> | null | undefined,
|
||||
uid = currentUid(),
|
||||
): { url: string; mode: 1 | 2 } {
|
||||
if (!config) return { url: '', mode: 1 }
|
||||
): { url: string; mode: 1 | 2; provider: string } {
|
||||
if (!config) return { url: '', mode: 1, provider: '' }
|
||||
const globalUrl = typeof config.proxy_url === 'string' ? config.proxy_url.trim() : ''
|
||||
const globalMode: 1 | 2 = Number(config.proxy_mode) === 2 ? 2 : 1
|
||||
// 供应商:显式配置优先,其次按域名识别;都没有返回空串(下游按链接再识别,别硬塞默认值)
|
||||
const providerOf = (raw: unknown, url: string) => {
|
||||
const explicit = typeof raw === 'string' ? raw.trim().toLowerCase() : ''
|
||||
return explicit || detectProxyProviderFromUrl(url) || ''
|
||||
}
|
||||
if (uid !== '0') {
|
||||
const users = (config.proxy_users ?? {}) as Record<string, unknown>
|
||||
const own = (users[uid] ?? {}) as Record<string, unknown>
|
||||
const ownUrl = typeof own.proxy_url === 'string' ? own.proxy_url.trim() : ''
|
||||
if (ownUrl) {
|
||||
return { url: ownUrl, mode: Number(own.proxy_mode) === 2 ? 2 : 1 }
|
||||
return {
|
||||
url: ownUrl,
|
||||
mode: Number(own.proxy_mode) === 2 ? 2 : 1,
|
||||
provider: providerOf(own.proxy_provider, ownUrl),
|
||||
}
|
||||
}
|
||||
}
|
||||
const owner = typeof config.proxy_uid === 'string' ? config.proxy_uid.trim() : ''
|
||||
const shared = isSharedProxy(config, uid)
|
||||
if (!globalUrl) return { url: '', mode: 1 }
|
||||
if (!globalUrl) return { url: '', mode: 1, provider: '' }
|
||||
if (uid === '0') {
|
||||
// 未登录没有"账号归属"可言:只认匿名全局(无归属/归属 0)或显式共享
|
||||
return !owner || owner === '0' || shared
|
||||
? { url: globalUrl, mode: globalMode }
|
||||
: { url: '', mode: 1 }
|
||||
? { url: globalUrl, mode: globalMode, provider: providerOf(config.proxy_provider, globalUrl) }
|
||||
: { url: '', mode: 1, provider: '' }
|
||||
}
|
||||
return owner === uid || shared
|
||||
? { url: globalUrl, mode: globalMode }
|
||||
: { url: '', mode: 1 }
|
||||
? { url: globalUrl, mode: globalMode, provider: providerOf(config.proxy_provider, globalUrl) }
|
||||
: { url: '', mode: 1, provider: '' }
|
||||
}
|
||||
|
||||
function readLocalProxyUrl(
|
||||
@@ -729,6 +745,7 @@ function toServerProxy(proxy: UserApiSecretItem | null | undefined): ServerProxy
|
||||
return {
|
||||
value: '',
|
||||
masked: proxy.masked || '',
|
||||
channel: proxy.channel || '',
|
||||
exists: Boolean(proxy.exists),
|
||||
locked: Boolean(proxy.locked),
|
||||
full: typeof proxy.full === 'string' ? proxy.full.trim() : '',
|
||||
@@ -782,6 +799,8 @@ const inheritanceHost: ApiSecretInheritanceHost = {
|
||||
isDesktopStorage: isNativeDesktopStorage,
|
||||
moduleKeys: () => new Set<string>([...DEFAULT_REQUIRED_MODULES, ...requiredModules]),
|
||||
readSecret: (moduleKey) => readEntry(moduleKey).value,
|
||||
// 渠道随密钥一起继承:否则下一个账号会把龙抬头的密钥按「存量=贞贞」落库
|
||||
readSecretChannel: (moduleKey) => readEntry(moduleKey).channel,
|
||||
// 只有 applyInheritedSecrets 在 migrate 的 await 之后重新比过 uid/epoch 才会调到这里
|
||||
writeSecret: (moduleKey, value) => {
|
||||
const entry = readEntry(moduleKey)
|
||||
@@ -912,12 +931,16 @@ export function takeApiSecretInheritanceNotice(): ApiSecretInheritanceNotice | n
|
||||
}
|
||||
|
||||
/** 保存密钥到服务端;成功后刷新本地缓存(失败不写本地,避免本地有值服务端没有的假象)。 */
|
||||
export async function saveApiSecret(moduleKey: ApiSecretModuleKey, value: string): Promise<ApiSecretSnapshot> {
|
||||
export async function saveApiSecret(
|
||||
moduleKey: ApiSecretModuleKey,
|
||||
value: string,
|
||||
channel?: string,
|
||||
): Promise<ApiSecretSnapshot> {
|
||||
const trimmed = value.trim()
|
||||
if (!trimmed) {
|
||||
throw new Error('密钥不能为空')
|
||||
}
|
||||
const item = await putMyApiSecret(moduleKey, trimmed)
|
||||
const item = await putMyApiSecret(moduleKey, trimmed, channel)
|
||||
applyServerItem(moduleKey, item)
|
||||
updateEntry(moduleKey, { value: trimmed, exists: true })
|
||||
bundleLoaded = true
|
||||
@@ -935,9 +958,10 @@ export async function clearApiSecret(moduleKey: ApiSecretModuleKey): Promise<voi
|
||||
export async function checkApiSecret(
|
||||
moduleKey: ApiSecretModuleKey,
|
||||
value?: string,
|
||||
channel?: string,
|
||||
): Promise<UserApiSecretCheckResult> {
|
||||
const override = value?.trim()
|
||||
const result = await checkMyApiSecret(moduleKey, override || undefined)
|
||||
const result = await checkMyApiSecret(moduleKey, override || undefined, channel)
|
||||
if (!override) {
|
||||
updateEntry(moduleKey, {
|
||||
checkStatus: normalizeCheckStatus(result.checkStatus),
|
||||
|
||||
Reference in New Issue
Block a user