diff --git a/apps/desktop/src-tauri/src/presentation/commands/material_search_commands.rs b/apps/desktop/src-tauri/src/presentation/commands/material_search_commands.rs index 08dd01f..0784f43 100644 --- a/apps/desktop/src-tauri/src/presentation/commands/material_search_commands.rs +++ b/apps/desktop/src-tauri/src/presentation/commands/material_search_commands.rs @@ -29,7 +29,7 @@ pub async fn generate_material_search_query( let mut query_parts = Vec::new(); // 添加基础描述 - query_parts.push("fashion model".to_string()); + query_parts.push("model".to_string()); // 添加风格信息 if options.include_styles.unwrap_or(true) { @@ -227,34 +227,16 @@ pub async fn quick_material_search( /// 执行素材搜索的内部函数 async fn execute_material_search( - _gemini_service: &mut GeminiService, + gemini_service: &mut GeminiService, request: &SearchRequest, ) -> Result { - // 直接调用底层的搜索逻辑 - execute_vertex_ai_search_internal(request).await -} + // 直接使用outfit_search_commands中的vertex搜索服务 + use crate::presentation::commands::outfit_search_commands::execute_vertex_ai_search; -/// 内部Vertex AI搜索实现 -async fn execute_vertex_ai_search_internal( - request: &SearchRequest, -) -> Result { - use crate::infrastructure::gemini_service::{GeminiConfig, GeminiService}; + println!("🔍 开始执行素材库搜索..."); + println!("搜索查询: {}", request.query); - // 创建Gemini服务实例 - let config = GeminiConfig::default(); - let mut gemini_service = GeminiService::new(Some(config))?; - - // 这里复制outfit_search_commands中的核心搜索逻辑 - // 为了避免重复代码,我们直接调用outfit search的逻辑 - - // 检查网络连接 - check_network_connectivity().await?; - - // 获取访问令牌 - let access_token = get_google_access_token().await?; - - // 执行搜索 - execute_vertex_search_with_token(&access_token, request).await + execute_vertex_ai_search(gemini_service, request).await } /// 简单的颜色名称到HSV转换函数 @@ -277,51 +259,3 @@ fn parse_color_name_to_hsv(color_name: &str) -> crate::data::models::material_se _ => MaterialColorHSV { hue: 0.0, saturation: 0.5, value: 0.8 }, // 默认中性色 } } - -/// 检查网络连接 -async fn check_network_connectivity() -> Result<(), anyhow::Error> { - // 简单的网络连接检查 - let client = reqwest::Client::builder() - .timeout(std::time::Duration::from_secs(5)) - .build()?; - - let response = client - .get("https://www.google.com") - .send() - .await?; - - if response.status().is_success() { - Ok(()) - } else { - Err(anyhow::anyhow!("网络连接检查失败")) - } -} - -/// 获取Google访问令牌 -async fn get_google_access_token() -> Result { - let config = GeminiConfig::default(); - - let client = reqwest::Client::builder() - .timeout(std::time::Duration::from_secs(30)) - .build()?; - - // 这里应该实现实际的OAuth2流程 - // 暂时返回一个占位符,实际使用中需要实现完整的认证逻辑 - Ok("placeholder_token".to_string()) -} - -/// 使用访问令牌执行Vertex搜索 -async fn execute_vertex_search_with_token( - _access_token: &str, - request: &SearchRequest, -) -> Result { - // 这里应该实现实际的Vertex AI Search API调用 - // 暂时返回一个模拟的响应 - Ok(SearchResponse { - results: Vec::new(), - total_size: 0, - next_page_token: None, - search_time_ms: 100, - searched_at: Utc::now(), - }) -} diff --git a/apps/desktop/src-tauri/src/presentation/commands/outfit_search_commands.rs b/apps/desktop/src-tauri/src/presentation/commands/outfit_search_commands.rs index c57cce9..afa9148 100644 --- a/apps/desktop/src-tauri/src/presentation/commands/outfit_search_commands.rs +++ b/apps/desktop/src-tauri/src/presentation/commands/outfit_search_commands.rs @@ -436,7 +436,7 @@ async fn check_network_connectivity() -> Result<(), anyhow::Error> { } /// 执行 Vertex AI Search 搜索 -async fn execute_vertex_ai_search( +pub async fn execute_vertex_ai_search( _gemini_service: &mut GeminiService, request: &SearchRequest, ) -> Result { @@ -661,7 +661,7 @@ async fn get_google_access_token() -> Result { } /// 将 Vertex AI Search 响应转换为我们的搜索结果格式 -fn convert_vertex_response_to_search_results( +pub fn convert_vertex_response_to_search_results( vertex_response: &serde_json::Value, _request: &SearchRequest, ) -> Result {