mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-01 17:00:21 +08:00
refactor: 移除 API Key 最小长度限制并放宽最大长度至 10000 字符
This commit is contained in:
@@ -47,9 +47,7 @@ export const BUSINESS_CONSTANTS = {
|
||||
PROVIDER_MIN_PRIORITY: 0,
|
||||
PROVIDER_MAX_PRIORITY: 999,
|
||||
|
||||
// API Key 相关
|
||||
API_KEY_MIN_LENGTH: 10,
|
||||
API_KEY_MAX_LENGTH: 500,
|
||||
// API Key 相关(不限制长度)
|
||||
|
||||
// 分页配置
|
||||
DEFAULT_PAGE_SIZE: 20,
|
||||
|
||||
@@ -83,13 +83,7 @@
|
||||
/>
|
||||
</template>
|
||||
<p
|
||||
v-if="apiKeyError"
|
||||
class="text-xs text-destructive mt-1"
|
||||
>
|
||||
{{ apiKeyError }}
|
||||
</p>
|
||||
<p
|
||||
v-else-if="editingKey && form.auth_type === 'api_key'"
|
||||
v-if="editingKey && form.auth_type === 'api_key'"
|
||||
class="text-xs text-muted-foreground mt-1"
|
||||
>
|
||||
留空表示不修改
|
||||
@@ -400,8 +394,6 @@ const canSave = computed(() => {
|
||||
}
|
||||
// 必须至少选择一个 API 格式
|
||||
if (form.value.api_formats.length === 0) return false
|
||||
// API 密钥格式验证(如果有输入)
|
||||
if (form.value.auth_type === 'api_key' && form.value.api_key.trim() && form.value.api_key.trim().length < 3) return false
|
||||
return true
|
||||
})
|
||||
|
||||
@@ -487,26 +479,6 @@ function updateRateMultiplier(format: string, value: string | number) {
|
||||
}
|
||||
|
||||
|
||||
// API 密钥验证错误信息
|
||||
const apiKeyError = computed(() => {
|
||||
const apiKey = form.value.api_key.trim()
|
||||
if (!apiKey) {
|
||||
// 新增模式下必填
|
||||
if (!props.editingKey) {
|
||||
return '' // 空值由 required 属性处理
|
||||
}
|
||||
// 编辑模式下可以为空(表示不修改)
|
||||
return ''
|
||||
}
|
||||
|
||||
// 如果输入了值,检查长度
|
||||
if (apiKey.length < 3) {
|
||||
return 'API 密钥至少需要 3 个字符'
|
||||
}
|
||||
|
||||
return ''
|
||||
})
|
||||
|
||||
// 重置表单
|
||||
function resetForm() {
|
||||
formNonce.value = createFieldNonce()
|
||||
@@ -609,12 +581,6 @@ async function handleSave() {
|
||||
return
|
||||
}
|
||||
|
||||
// 提交前验证
|
||||
if (apiKeyError.value) {
|
||||
showError(apiKeyError.value, '验证失败')
|
||||
return
|
||||
}
|
||||
|
||||
// 验证认证信息
|
||||
if (form.value.auth_type === 'api_key') {
|
||||
// API Key 模式:新增时必填
|
||||
|
||||
@@ -349,7 +349,7 @@ class CreateAPIKeyRequest(BaseModel):
|
||||
"""创建 API Key 请求"""
|
||||
|
||||
endpoint_id: str = Field(..., description="Endpoint ID")
|
||||
api_key: str = Field(..., min_length=1, max_length=500, description="API Key")
|
||||
api_key: str = Field(..., min_length=1, max_length=10000, description="API Key")
|
||||
priority: int | None = Field(100, ge=0, le=1000, description="优先级")
|
||||
is_active: bool | None = Field(True, description="是否启用")
|
||||
rpm_limit: int | None = Field(None, ge=0, description="RPM 限制(NULL=自适应)")
|
||||
@@ -362,10 +362,6 @@ class CreateAPIKeyRequest(BaseModel):
|
||||
# 移除首尾空白
|
||||
v = v.strip()
|
||||
|
||||
# 检查最小长度
|
||||
if len(v) < 3:
|
||||
raise ValueError("API Key 长度不能少于 3 个字符")
|
||||
|
||||
# 检查危险字符(不应包含 SQL 注入字符)
|
||||
dangerous_chars = ["'", '"', ";", "--", "/*", "*/", "<", ">"]
|
||||
for char in dangerous_chars:
|
||||
|
||||
@@ -322,7 +322,7 @@ class EndpointAPIKeyCreate(BaseModel):
|
||||
)
|
||||
|
||||
api_key: str = Field(
|
||||
default="", max_length=500, description="API Key(标准认证时必填,将自动加密)"
|
||||
default="", max_length=10000, description="API Key(标准认证时必填,将自动加密)"
|
||||
)
|
||||
auth_type: Literal["api_key", "vertex_ai", "oauth"] = Field(
|
||||
default="api_key",
|
||||
@@ -484,8 +484,7 @@ class EndpointAPIKeyUpdate(BaseModel):
|
||||
|
||||
api_key: str | None = Field(
|
||||
default=None,
|
||||
min_length=3,
|
||||
max_length=500,
|
||||
max_length=10000,
|
||||
description="API Key(标准认证时使用,将自动加密)",
|
||||
)
|
||||
auth_type: Literal["api_key", "vertex_ai", "oauth"] | None = Field(
|
||||
@@ -576,8 +575,6 @@ class EndpointAPIKeyUpdate(BaseModel):
|
||||
return v
|
||||
|
||||
v = v.strip()
|
||||
if len(v) < 3:
|
||||
raise ValueError("API Key 长度不能少于 3 个字符")
|
||||
|
||||
dangerous_chars = ["'", '"', ";", "--", "/*", "*/", "<", ">"]
|
||||
for char in dangerous_chars:
|
||||
|
||||
Reference in New Issue
Block a user