feat(密钥管理): 后台可代填并锁定用户代理设置,客户端只读并回填本地配置
代理是选配、不进 items 也不参与门禁,但客户端各任务链读的是本地 app.json 的
proxy_url,用户自填值与后台不一致时排查成本高。改法:
- 后台 PUT/DELETE /api/admin/user-secrets/{userId}/modules/{moduleKey} 代填/解锁,
写入后该行 source=admin;数据权限走 resolveVisibleUserIds,超管不限;
- 客户端 save/clear 命中锁定行时服务端直接拒绝并给出原因(只置灰挡不住直接调接口);
- 密钥包把代理单独放 proxy 字段下发(仍不进 items、不影响 complete 判定),
锁定时带 full 明文,客户端据此幂等地对齐本地配置;解锁 = 删除该行。
只开放代理代填:密钥模块要客户端提交任务时携带本地明文,代填会把用户卡死。
This commit is contained in:
@@ -45,8 +45,15 @@
|
||||
<section v-if="showProxy" class="secret-card">
|
||||
<div class="secret-card-head">
|
||||
<div>
|
||||
<div class="secret-card-title">代理设置</div>
|
||||
<div class="secret-card-desc">供客户端任务连接代理服务,支持静态代理地址或代理服务商的提取链接。</div>
|
||||
<div class="secret-card-title">
|
||||
代理设置
|
||||
<span v-if="proxyLocked" class="lock-tag">后台锁定</span>
|
||||
</div>
|
||||
<div class="secret-card-desc">
|
||||
{{ proxyLocked
|
||||
? '代理由管理员统一配置并锁定,客户端不可修改或清空;如需变更请联系管理员。'
|
||||
: '供客户端任务连接代理服务,支持静态代理地址或代理服务商的提取链接。' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -60,7 +67,7 @@
|
||||
placeholder="如 http://user:pass@host:port 或代理提取链接"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
:disabled="!proxyReady || busy"
|
||||
:disabled="!proxyReady || busy || proxyLocked"
|
||||
@input="proxyDirty = true"
|
||||
/>
|
||||
</div>
|
||||
@@ -72,13 +79,13 @@
|
||||
v-for="option in proxyModeOptions"
|
||||
:key="option.value"
|
||||
class="retention-option"
|
||||
:class="{ 'retention-option--disabled': !proxyReady || busy }"
|
||||
:class="{ 'retention-option--disabled': !proxyReady || busy || proxyLocked }"
|
||||
>
|
||||
<input
|
||||
v-model="proxyMode"
|
||||
type="radio"
|
||||
:value="option.value"
|
||||
:disabled="!proxyReady || busy"
|
||||
:disabled="!proxyReady || busy || proxyLocked"
|
||||
@change="proxyDirty = true"
|
||||
/>
|
||||
<span>{{ option.label }}</span>
|
||||
@@ -119,6 +126,7 @@ import {
|
||||
checkApiSecret,
|
||||
clearApiSecret,
|
||||
fetchProxyBalanceSafely,
|
||||
getServerProxySnapshot,
|
||||
getStoredApiSecretSnapshot,
|
||||
listApiSecretModules,
|
||||
loadApiSecrets,
|
||||
@@ -127,6 +135,7 @@ import {
|
||||
type ApiSecretCheckStatus,
|
||||
type ApiSecretModuleKey,
|
||||
type ApiSecretSnapshot,
|
||||
type ServerProxySnapshot,
|
||||
type UserApiSecretCheckResult,
|
||||
} from '@/shared/utils/api-secret-store'
|
||||
import { getPywebviewApi, type ProxyMode, type DesktopConfigUpdate } from '@/shared/bridges/pywebview'
|
||||
@@ -160,6 +169,10 @@ for (const module of modules.value) {
|
||||
const snapshots = ref<Record<string, ApiSecretSnapshot>>({})
|
||||
const busy = ref(false)
|
||||
|
||||
/** 服务端代理状态:后台代填并锁定时客户端只读。 */
|
||||
const serverProxy = ref<ServerProxySnapshot | null>(getServerProxySnapshot())
|
||||
const proxyLocked = computed(() => Boolean(serverProxy.value?.locked && serverProxy.value?.exists))
|
||||
|
||||
const proxyUrl = ref('')
|
||||
const proxyMode = ref<ProxyMode>(1)
|
||||
const proxyLoading = ref(false)
|
||||
@@ -255,6 +268,7 @@ function refreshSnapshots() {
|
||||
ensureModuleState(module.moduleKey)
|
||||
}
|
||||
snapshots.value = next
|
||||
serverProxy.value = getServerProxySnapshot()
|
||||
}
|
||||
|
||||
function snapshotOf(moduleKey: string): ApiSecretSnapshot {
|
||||
@@ -498,7 +512,7 @@ async function saveAll(options: { requireAll?: boolean } = {}): Promise<boolean>
|
||||
secretsSaved = true
|
||||
refreshSnapshots()
|
||||
|
||||
if (props.showProxy && proxyReady.value && proxyDirty.value) {
|
||||
if (props.showProxy && proxyReady.value && proxyDirty.value && !proxyLocked.value) {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.save_config) throw new Error('当前客户端未提供代理配置保存能力')
|
||||
const nextProxyUrl = proxyUrl.value.trim()
|
||||
@@ -534,11 +548,14 @@ let unsubscribe: (() => void) | null = null
|
||||
onMounted(() => {
|
||||
refreshSnapshots()
|
||||
unsubscribe = subscribeApiSecrets(refreshSnapshots)
|
||||
void reload()
|
||||
if (props.showProxy) {
|
||||
void loadProxyConfig()
|
||||
void loadBalance()
|
||||
}
|
||||
// 先拉服务端密钥包(后台锁定的代理会先对齐到本地配置),再读本地代理,避免展示对齐前的旧值
|
||||
void (async () => {
|
||||
await reload()
|
||||
if (props.showProxy) {
|
||||
void loadProxyConfig()
|
||||
void loadBalance()
|
||||
}
|
||||
})()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
@@ -579,6 +596,20 @@ defineExpose({ saveAll, reload })
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.lock-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
margin-left: 8px;
|
||||
padding: 1px 8px;
|
||||
border: 1px solid #6b5a2e;
|
||||
border-radius: 999px;
|
||||
background: #2e2a1c;
|
||||
color: #e6c76a;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.secret-card-desc {
|
||||
margin-top: 4px;
|
||||
color: #909ba8;
|
||||
|
||||
Reference in New Issue
Block a user