fix: cargo check --lib error

This commit is contained in:
imeepos 2025-08-08 15:09:25 +08:00
parent d61e2e8f4c
commit 094b73fffd
7 changed files with 52 additions and 22 deletions

View File

@ -331,7 +331,7 @@ impl AppState {
} }
/// 初始化 ComfyUI Infrastructure 服务 /// 初始化 ComfyUI Infrastructure 服务
pub fn initialize_comfyui_service(&self, config: crate::data::models::comfyui::ComfyuiConfig) -> anyhow::Result<()> { pub fn initialize_comfyui_service(&self, config: crate::data::models::comfyui::ComfyUIConfig) -> anyhow::Result<()> {
let service = ComfyuiInfrastructureService::new(config)?; let service = ComfyuiInfrastructureService::new(config)?;
let mut comfyui_service = self.comfyui_infrastructure_service.lock() let mut comfyui_service = self.comfyui_infrastructure_service.lock()
@ -355,7 +355,7 @@ impl AppState {
} }
/// 更新 ComfyUI Infrastructure 服务配置 /// 更新 ComfyUI Infrastructure 服务配置
pub async fn update_comfyui_config(&self, config: crate::data::models::comfyui::ComfyuiConfig) -> anyhow::Result<()> { pub async fn update_comfyui_config(&self, config: crate::data::models::comfyui::ComfyUIConfig) -> anyhow::Result<()> {
// 创建新的服务实例 // 创建新的服务实例
let new_service = ComfyuiInfrastructureService::new(config)?; let new_service = ComfyuiInfrastructureService::new(config)?;

View File

@ -158,7 +158,7 @@ impl ConfigManager {
/// 验证应用配置 /// 验证应用配置
async fn validate_app_config(&self, config: &AppConfig) -> Result<ValidationResult> { async fn validate_app_config(&self, config: &AppConfig) -> Result<ValidationResult> {
use crate::data::models::comfyui::{ValidationResult, ValidationError}; use crate::data::models::comfyui::{ValidationResult, SDKValidationError as ValidationError};
let mut result = ValidationResult::success(); let mut result = ValidationResult::success();

View File

@ -170,7 +170,7 @@ impl ComfyUISettings {
/// 验证配置 /// 验证配置
pub fn validate(&self) -> crate::data::models::comfyui::ValidationResult { pub fn validate(&self) -> crate::data::models::comfyui::ValidationResult {
use crate::data::models::comfyui::{ValidationResult, ValidationError}; use crate::data::models::comfyui::{ValidationResult, SDKValidationError as ValidationError};
let mut result = ValidationResult::success(); let mut result = ValidationResult::success();

View File

@ -9,7 +9,7 @@ use uuid::Uuid;
// 重新导出 SDK 类型 // 重新导出 SDK 类型
pub use comfyui_sdk::types::{ pub use comfyui_sdk::types::{
ComfyUIWorkflow, ParameterSchema, ParameterType, ParameterValues, ComfyUIWorkflow, ParameterSchema, ParameterType, ParameterValues,
ValidationResult, ValidationError, TemplateMetadata, WorkflowTemplateData, ValidationResult, ValidationError as SDKValidationError, TemplateMetadata, WorkflowTemplateData,
QueueStatus, SystemStats, ObjectInfo QueueStatus, SystemStats, ObjectInfo
}; };
@ -435,6 +435,33 @@ pub struct QueueStatistics {
pub average_wait_time: Option<u64>, pub average_wait_time: Option<u64>,
} }
/// 旧版 ComfyUI 配置(用于 Infrastructure 服务)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComfyuiConfig {
/// 服务基础 URL
pub base_url: String,
/// 连接超时时间(秒)
pub timeout: Option<u64>,
/// 重试次数
pub retry_attempts: Option<u32>,
/// 是否启用缓存
pub enable_cache: Option<bool>,
/// 最大并发数
pub max_concurrency: Option<u32>,
}
impl Default for ComfyuiConfig {
fn default() -> Self {
Self {
base_url: "http://localhost:8188".to_string(),
timeout: Some(300),
retry_attempts: Some(3),
enable_cache: Some(true),
max_concurrency: Some(4),
}
}
}
/// ComfyUI 服务配置 /// ComfyUI 服务配置
/// 基于 SDK 的统一配置结构 /// 基于 SDK 的统一配置结构
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@ -490,26 +517,26 @@ impl ComfyUIConfig {
// 验证 URL // 验证 URL
if self.base_url.is_empty() { if self.base_url.is_empty() {
result.add_error(ValidationError::new("base_url", "Base URL cannot be empty")); result.add_error(SDKValidationError::new("base_url".to_string(), "Base URL cannot be empty".to_string(), None));
} else if url::Url::parse(&self.base_url).is_err() { } else if url::Url::parse(&self.base_url).is_err() {
result.add_error(ValidationError::new("base_url", "Invalid URL format")); result.add_error(SDKValidationError::new("base_url".to_string(), "Invalid URL format".to_string(), None));
} }
// 验证超时时间 // 验证超时时间
if self.timeout_seconds == 0 { if self.timeout_seconds == 0 {
result.add_error(ValidationError::new("timeout_seconds", "Timeout must be greater than 0")); result.add_error(SDKValidationError::new("timeout_seconds".to_string(), "Timeout must be greater than 0".to_string(), None));
} }
// 验证重试次数 // 验证重试次数
if self.retry_attempts > 10 { if self.retry_attempts > 10 {
result.add_error(ValidationError::new("retry_attempts", "Retry attempts should not exceed 10")); result.add_error(SDKValidationError::new("retry_attempts".to_string(), "Retry attempts should not exceed 10".to_string(), None));
} }
// 验证并发数 // 验证并发数
if self.max_concurrency == 0 { if self.max_concurrency == 0 {
result.add_error(ValidationError::new("max_concurrency", "Max concurrency must be greater than 0")); result.add_error(SDKValidationError::new("max_concurrency".to_string(), "Max concurrency must be greater than 0".to_string(), None));
} else if self.max_concurrency > 100 { } else if self.max_concurrency > 100 {
result.add_error(ValidationError::new("max_concurrency", "Max concurrency should not exceed 100")); result.add_error(SDKValidationError::new("max_concurrency".to_string(), "Max concurrency should not exceed 100".to_string(), None));
} }
result result
@ -686,7 +713,7 @@ pub struct ApiRootResponse {
/// HTTP 验证错误详情 /// HTTP 验证错误详情
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationError { pub struct HttpValidationError {
/// 错误位置 /// 错误位置
pub loc: Vec<serde_json::Value>, pub loc: Vec<serde_json::Value>,
/// 错误消息 /// 错误消息
@ -700,7 +727,7 @@ pub struct ValidationError {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HTTPValidationError { pub struct HTTPValidationError {
/// 错误详情列表 /// 错误详情列表
pub detail: Vec<ValidationError>, pub detail: Vec<HttpValidationError>,
} }
/// ComfyUI API 错误类型 /// ComfyUI API 错误类型

View File

@ -34,7 +34,7 @@ impl ComfyuiInfrastructureService {
} }
/// 获取配置信息 /// 获取配置信息
pub fn get_config(&self) -> &ComfyuiConfig { pub fn get_config(&self) -> &ComfyUIConfig {
&self.config &self.config
} }
@ -346,7 +346,7 @@ impl ComfyuiInfrastructureService {
} }
/// 更新服务配置 /// 更新服务配置
pub fn update_config(&mut self, config: ComfyuiConfig) -> Result<()> { pub fn update_config(&mut self, config: ComfyUIConfig) -> Result<()> {
// 验证新配置 // 验证新配置
let temp_service = Self::new(config.clone())?; let temp_service = Self::new(config.clone())?;
temp_service.validate_config()?; temp_service.validate_config()?;

View File

@ -735,12 +735,15 @@ pub fn run() {
} }
// 初始化 ComfyUI 服务 - 使用本地 ComfyUI 服务器 // 初始化 ComfyUI 服务 - 使用本地 ComfyUI 服务器
let comfyui_config = data::models::comfyui::ComfyuiConfig { let comfyui_config = data::models::comfyui::ComfyUIConfig {
base_url: "https://bowongai-dev--waas-demo-fastapi-webapp.modal.run".to_string(), base_url: "https://bowongai-dev--waas-demo-fastapi-webapp.modal.run".to_string(),
timeout: Some(600), // 10分钟超时适应 ComfyUI 工作流的长时间处理 timeout_seconds: 600, // 10分钟超时适应 ComfyUI 工作流的长时间处理
retry_attempts: Some(3), retry_attempts: 3,
enable_cache: Some(true), retry_delay_ms: 1000,
max_concurrency: Some(8), enable_websocket: true,
enable_cache: true,
max_concurrency: 8,
custom_headers: None,
}; };
if let Err(e) = state.initialize_comfyui_service(comfyui_config) { if let Err(e) = state.initialize_comfyui_service(comfyui_config) {

View File

@ -397,7 +397,7 @@ pub async fn comfyui_node_get_data(
#[tauri::command] #[tauri::command]
pub async fn comfyui_get_config( pub async fn comfyui_get_config(
state: State<'_, AppState>, state: State<'_, AppState>,
) -> Result<ComfyuiConfig, String> { ) -> Result<ComfyUIConfig, String> {
info!("Command: comfyui_get_config"); info!("Command: comfyui_get_config");
let app_state = state.inner(); let app_state = state.inner();
@ -424,7 +424,7 @@ pub async fn comfyui_get_config(
/// ``` /// ```
#[tauri::command] #[tauri::command]
pub async fn comfyui_update_config( pub async fn comfyui_update_config(
config: ComfyuiConfig, config: ComfyUIConfig,
state: State<'_, AppState>, state: State<'_, AppState>,
) -> Result<bool, String> { ) -> Result<bool, String> {
info!("Command: comfyui_update_config"); info!("Command: comfyui_update_config");