mirror of
https://github.com/fawney19/Aether.git
synced 2026-01-09 03:02:26 +08:00
fix: 降低 API Key 最小长度限制至 3 个字符
This commit is contained in:
@@ -349,8 +349,8 @@ const apiKeyError = computed(() => {
|
||||
}
|
||||
|
||||
// 如果输入了值,检查长度
|
||||
if (apiKey.length < 10) {
|
||||
return 'API 密钥至少需要 10 个字符'
|
||||
if (apiKey.length < 3) {
|
||||
return 'API 密钥至少需要 3 个字符'
|
||||
}
|
||||
|
||||
return ''
|
||||
|
||||
@@ -54,7 +54,7 @@ const fieldNameMap: Record<string, string> = {
|
||||
*/
|
||||
const errorTypeMap: Record<string, (error: ValidationError) => string> = {
|
||||
'string_too_short': (error) => {
|
||||
const minLength = error.ctx?.min_length || 10
|
||||
const minLength = error.ctx?.min_length || 3
|
||||
return `长度不能少于 ${minLength} 个字符`
|
||||
},
|
||||
'string_too_long': (error) => {
|
||||
|
||||
@@ -134,7 +134,7 @@ class EndpointAPIKeyCreate(BaseModel):
|
||||
"""为 Endpoint 添加 API Key"""
|
||||
|
||||
endpoint_id: str = Field(..., description="Endpoint ID")
|
||||
api_key: str = Field(..., min_length=10, max_length=500, description="API Key(将自动加密)")
|
||||
api_key: str = Field(..., min_length=3, max_length=500, description="API Key(将自动加密)")
|
||||
name: str = Field(..., min_length=1, max_length=100, description="密钥名称(必填,用于识别)")
|
||||
|
||||
# 成本计算
|
||||
@@ -175,13 +175,9 @@ class EndpointAPIKeyCreate(BaseModel):
|
||||
@classmethod
|
||||
def validate_api_key(cls, v: str) -> str:
|
||||
"""验证 API Key 安全性"""
|
||||
# 移除首尾空白
|
||||
# 移除首尾空白(长度校验由 Field min_length 处理)
|
||||
v = v.strip()
|
||||
|
||||
# 检查最小长度
|
||||
if len(v) < 10:
|
||||
raise ValueError("API Key 长度不能少于 10 个字符")
|
||||
|
||||
# 检查危险字符(SQL 注入防护)
|
||||
dangerous_chars = ["'", '"', ";", "--", "/*", "*/", "<", ">"]
|
||||
for char in dangerous_chars:
|
||||
@@ -219,7 +215,7 @@ class EndpointAPIKeyUpdate(BaseModel):
|
||||
"""更新 Endpoint API Key"""
|
||||
|
||||
api_key: Optional[str] = Field(
|
||||
default=None, min_length=10, max_length=500, description="API Key(将自动加密)"
|
||||
default=None, min_length=3, max_length=500, description="API Key(将自动加密)"
|
||||
)
|
||||
name: Optional[str] = Field(default=None, min_length=1, max_length=100, description="密钥名称")
|
||||
rate_multiplier: Optional[float] = Field(default=None, ge=0.01, description="成本倍率")
|
||||
|
||||
Reference in New Issue
Block a user