mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
fix: API Key permissions multi-select save and display issue
- Fix updateApiKey to use JSON.stringify for permissions field - Add comma-separated string handling in normalizePermissions - Add frontend parsing for comma-separated permissions format Fixes issue where selecting multiple permissions (e.g. Claude + OpenAI) would be saved as "claude,openai" instead of '["claude","openai"]'
This commit is contained in:
@@ -65,6 +65,13 @@ function normalizePermissions(permissions) {
|
|||||||
if (permissions === 'all') {
|
if (permissions === 'all') {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
// 兼容逗号分隔格式(修复历史错误数据,如 "claude,openai")
|
||||||
|
if (permissions.includes(',')) {
|
||||||
|
return permissions
|
||||||
|
.split(',')
|
||||||
|
.map((p) => p.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
}
|
||||||
// 旧单个字符串转为数组
|
// 旧单个字符串转为数组
|
||||||
return [permissions]
|
return [permissions]
|
||||||
}
|
}
|
||||||
@@ -753,6 +760,9 @@ class ApiKeyService {
|
|||||||
if (field === 'restrictedModels' || field === 'allowedClients' || field === 'tags') {
|
if (field === 'restrictedModels' || field === 'allowedClients' || field === 'tags') {
|
||||||
// 特殊处理数组字段
|
// 特殊处理数组字段
|
||||||
updatedData[field] = JSON.stringify(value || [])
|
updatedData[field] = JSON.stringify(value || [])
|
||||||
|
} else if (field === 'permissions') {
|
||||||
|
// 权限字段:规范化后JSON序列化,与createApiKey保持一致
|
||||||
|
updatedData[field] = JSON.stringify(normalizePermissions(value))
|
||||||
} else if (
|
} else if (
|
||||||
field === 'enableModelRestriction' ||
|
field === 'enableModelRestriction' ||
|
||||||
field === 'enableClientRestriction' ||
|
field === 'enableClientRestriction' ||
|
||||||
|
|||||||
@@ -1246,6 +1246,12 @@ onMounted(async () => {
|
|||||||
} catch {
|
} catch {
|
||||||
perms = VALID_PERMS.includes(perms) ? [perms] : []
|
perms = VALID_PERMS.includes(perms) ? [perms] : []
|
||||||
}
|
}
|
||||||
|
} else if (perms.includes(',')) {
|
||||||
|
// 兼容逗号分隔格式(如 "claude,openai")
|
||||||
|
perms = perms
|
||||||
|
.split(',')
|
||||||
|
.map((p) => p.trim())
|
||||||
|
.filter((p) => VALID_PERMS.includes(p))
|
||||||
} else if (VALID_PERMS.includes(perms)) {
|
} else if (VALID_PERMS.includes(perms)) {
|
||||||
perms = [perms]
|
perms = [perms]
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user