feat(auth): 添加异步密码哈希和验证函数
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
refactor(relay): 复用HTTP客户端和请求体序列化结果 feat(kernel): 添加获取单个审批记录的方法 fix(store): 改进SaaS连接错误分类和降级处理 docs: 更新审计文档和系统架构文档 refactor(prompt): 优化SQL查询参数化绑定 refactor(migration): 使用静态SQL和COALESCE更新配置项 feat(commands): 添加审批执行状态追踪和事件通知 chore: 更新启动脚本以支持Admin后台 fix(auth-guard): 优化授权状态管理和错误处理 refactor(db): 使用异步密码哈希函数 refactor(totp): 使用异步密码验证函数 style: 清理无用文件和注释 docs: 更新功能全景和审计文档 refactor(service): 优化HTTP客户端重用和请求处理 fix(connection): 改进SaaS不可用时的降级处理 refactor(handlers): 使用异步密码验证函数 chore: 更新依赖和工具链配置
This commit is contained in:
@@ -43,12 +43,13 @@ pub async fn chat_completions(
|
||||
}
|
||||
|
||||
// --- 输入验证 ---
|
||||
// 请求体大小限制 (1 MB)
|
||||
// 请求体大小限制 (1 MB) — 直接序列化一次,后续复用
|
||||
const MAX_BODY_BYTES: usize = 1024 * 1024;
|
||||
let estimated_size = serde_json::to_string(&req).map(|s| s.len()).unwrap_or(0);
|
||||
if estimated_size > MAX_BODY_BYTES {
|
||||
let request_body = serde_json::to_string(&req)
|
||||
.map_err(|e| SaasError::InvalidInput(format!("请求体序列化失败: {}", e)))?;
|
||||
if request_body.len() > MAX_BODY_BYTES {
|
||||
return Err(SaasError::InvalidInput(
|
||||
format!("请求体超过大小限制 ({} bytes > {} bytes)", estimated_size, MAX_BODY_BYTES)
|
||||
format!("请求体超过大小限制 ({} bytes > {} bytes)", request_body.len(), MAX_BODY_BYTES)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -147,7 +148,7 @@ pub async fn chat_completions(
|
||||
return Err(SaasError::Forbidden(format!("Provider {} 已禁用", provider.name)));
|
||||
}
|
||||
|
||||
let request_body = serde_json::to_string(&req)?;
|
||||
// request_body 已在前面序列化并验证大小,直接复用
|
||||
|
||||
// 创建中转任务(提取配置后立即释放读锁)
|
||||
let (max_attempts, retry_delay_ms, enc_key) = {
|
||||
|
||||
Reference in New Issue
Block a user