mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-30 02:14:43 +08:00
fix(proxy): improve URL building and Gemini request handling
- Refactor URL construction with version path deduplication (/v1, /v1beta) - Preserve query parameters for Gemini API requests - Support GOOGLE_GEMINI_API_KEY field name (with fallback) - Change default proxy port from 5000 to 15721 - Fix test: use Option type for is_proxy_target field
This commit is contained in:
@@ -93,10 +93,10 @@ pub async fn handle_count_tokens(
|
||||
Ok(builder.body(body).unwrap())
|
||||
}
|
||||
|
||||
/// 处理 Gemini API 请求(透传)
|
||||
/// 处理 Gemini API 请求(透传,包括查询参数)
|
||||
pub async fn handle_gemini(
|
||||
State(state): State<ProxyState>,
|
||||
axum::extract::Path(path): axum::extract::Path<String>,
|
||||
uri: axum::http::Uri,
|
||||
headers: axum::http::HeaderMap,
|
||||
Json(body): Json<Value>,
|
||||
) -> Result<axum::response::Response, ProxyError> {
|
||||
@@ -108,9 +108,16 @@ pub async fn handle_gemini(
|
||||
state.status.clone(),
|
||||
);
|
||||
|
||||
let endpoint = format!("/{path}");
|
||||
// 提取完整的路径和查询参数
|
||||
let endpoint = uri
|
||||
.path_and_query()
|
||||
.map(|pq| pq.as_str())
|
||||
.unwrap_or(uri.path());
|
||||
|
||||
log::debug!("Gemini request endpoint (with query): {endpoint}");
|
||||
|
||||
let response = forwarder
|
||||
.forward_with_retry(&AppType::Gemini, &endpoint, body, headers)
|
||||
.forward_with_retry(&AppType::Gemini, endpoint, body, headers)
|
||||
.await?;
|
||||
|
||||
// 透传响应
|
||||
|
||||
Reference in New Issue
Block a user