mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 00:53:33 +00:00
fix: 优化验证器代码格式,提升可读性
This commit is contained in:
@@ -131,7 +131,7 @@ class ClaudeCodeValidator {
|
||||
const userAgent = req.headers['user-agent'] || ''
|
||||
const path = req.path || ''
|
||||
|
||||
const claudeCodePattern = /^claude-cli\/\d+\.\d+\.\d+/i;
|
||||
const claudeCodePattern = /^claude-cli\/\d+\.\d+\.\d+/i
|
||||
|
||||
if (!claudeCodePattern.test(userAgent)) {
|
||||
// 不是 Claude Code 的请求,此验证器不处理
|
||||
|
||||
@@ -53,7 +53,8 @@ class CodexCliValidator {
|
||||
// 2. 对于特定路径,进行额外的严格验证
|
||||
// 对于 /openai 和 /azure 路径需要完整验证
|
||||
const strictValidationPaths = ['/openai', '/azure']
|
||||
const needsStrictValidation = req.path && strictValidationPaths.some(path => req.path.startsWith(path))
|
||||
const needsStrictValidation =
|
||||
req.path && strictValidationPaths.some((path) => req.path.startsWith(path))
|
||||
|
||||
if (!needsStrictValidation) {
|
||||
// 其他路径,只要 User-Agent 匹配就认为是 Codex CLI
|
||||
|
||||
@@ -55,7 +55,9 @@ class GeminiCliValidator {
|
||||
// 包含 generateContent 的路径需要验证 User-Agent
|
||||
const geminiCliPattern = /^GeminiCLI\/v?[\d\.]+/i
|
||||
if (!geminiCliPattern.test(userAgent)) {
|
||||
logger.debug(`Gemini CLI validation failed - UA mismatch for generateContent: ${userAgent}`)
|
||||
logger.debug(
|
||||
`Gemini CLI validation failed - UA mismatch for generateContent: ${userAgent}`
|
||||
)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user