fix: 修复ComfyUI V2模板创建参数解析问题并重构工作流创建
主要修改: 1. **扩展ComfyUI SDK参数类型支持** - 在ParameterType枚举中添加Integer、Float、Image、Audio、Video类型 - 在ParameterSchema中添加节点映射和媒体文件相关字段 - 添加step、accept、maxSize、width、height、duration、node_mapping字段 - 为新字段添加serde默认值支持 2. **修复参数解析问题** - 解决comfyui_v2_create_template命令缺少type字段的错误 - 确保前端传递的参数类型与后端ParameterType枚举匹配 - 修复r#enum字段的正确使用(用于JSON Schema兼容性) 3. **重构工作流模板创建方式** - 将ai_model_face_hair_fix.rs中的create_workflow函数重构为create_workflow_from_json - 改为从JSON字符串解析ComfyUIWorkflow,而非手动构建HashMap - 提高可维护性和与实际使用场景的一致性 4. **更新相关测试和验证代码** - 修复validation.rs中的测试用例,添加新字段的默认值 - 确保所有ParameterSchema创建都包含完整字段 5. **添加测试数据** - 创建test_template_creation.json用于测试参数格式 这些修改解决了前端传递的参数格式与后端期望格式不匹配的问题, 使工作流模板创建功能能够正常工作。
This commit is contained in:
@@ -39,12 +39,23 @@ pub enum ParameterType {
|
||||
Boolean,
|
||||
Array,
|
||||
Object,
|
||||
Integer,
|
||||
Float,
|
||||
Image,
|
||||
Audio,
|
||||
Video,
|
||||
}
|
||||
|
||||
/// Node mapping configuration for parameter-to-workflow binding
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct NodeMapping {
|
||||
pub node_id: String,
|
||||
pub input_field: String,
|
||||
}
|
||||
|
||||
/// Parameter schema definition
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ParameterSchema {
|
||||
#[serde(rename = "type")]
|
||||
pub param_type: ParameterType,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub required: Option<bool>,
|
||||
@@ -59,11 +70,35 @@ pub struct ParameterSchema {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub max: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(default)]
|
||||
pub step: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub pattern: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub items: Option<Box<ParameterSchema>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub properties: Option<HashMap<String, ParameterSchema>>,
|
||||
// Media file related properties
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(default)]
|
||||
pub accept: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(rename = "maxSize")]
|
||||
#[serde(default)]
|
||||
pub max_size: Option<u64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(default)]
|
||||
pub width: Option<u32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(default)]
|
||||
pub height: Option<u32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(default)]
|
||||
pub duration: Option<f64>,
|
||||
// Workflow node mapping
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(default)]
|
||||
pub node_mapping: Option<NodeMapping>,
|
||||
}
|
||||
|
||||
/// Template metadata
|
||||
@@ -190,3 +225,28 @@ impl ValidationError {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ParameterSchema {
|
||||
/// Creates a new ParameterSchema with the given type and default values for other fields
|
||||
pub fn new(param_type: ParameterType) -> Self {
|
||||
Self {
|
||||
param_type,
|
||||
required: None,
|
||||
default: None,
|
||||
description: None,
|
||||
r#enum: None,
|
||||
min: None,
|
||||
max: None,
|
||||
step: None,
|
||||
pattern: None,
|
||||
items: None,
|
||||
properties: None,
|
||||
accept: None,
|
||||
max_size: None,
|
||||
width: None,
|
||||
height: None,
|
||||
duration: None,
|
||||
node_mapping: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user