|
| 1 | +use crate::types::field::{FieldType, SchemaField}; |
| 2 | +use crate::types::node::{I18nValue, NodeDefine}; |
| 3 | +use std::collections::HashMap; |
| 4 | + |
| 5 | +pub const NODE_TYPE: &str = "HTTPClient"; |
| 6 | + |
| 7 | +#[derive(Default)] |
| 8 | +pub struct HttpNode; |
| 9 | + |
| 10 | +impl HttpNode { |
| 11 | + pub fn new() -> Self { |
| 12 | + Self {} |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +impl NodeDefine for HttpNode { |
| 17 | + fn action_type(&self) -> String { |
| 18 | + NODE_TYPE.to_string() |
| 19 | + } |
| 20 | + |
| 21 | + fn name(&self) -> I18nValue { |
| 22 | + I18nValue { |
| 23 | + zh: "HTTP 请求".to_string(), |
| 24 | + en: "HTTP Request".to_string(), |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + fn icon(&self) -> String { |
| 29 | + String::from( |
| 30 | + "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgY2xhc3M9Imx1Y2lkZSBsdWNpZGUtZ2xvYmUtaWNvbiBsdWNpZGUtZ2xvYmUiPjxjaXJjbGUgY3g9IjEyIiBjeT0iMTIiIHI9IjEwIi8+PHBhdGggZD0iTTEyIDJhMTQuNSAxNC41IDAgMCAwIDAgMjAgMTQuNSAxNC41IDAgMCAwIDAtMjAiLz48cGF0aCBkPSJNMiAxMmgyMCIvPjwvc3ZnPg==", |
| 31 | + ) |
| 32 | + } |
| 33 | + |
| 34 | + fn category(&self) -> Option<I18nValue> { |
| 35 | + Some(I18nValue { |
| 36 | + zh: "网络请求".to_string(), |
| 37 | + en: "Network".to_string(), |
| 38 | + }) |
| 39 | + } |
| 40 | + |
| 41 | + fn description(&self) -> Option<I18nValue> { |
| 42 | + Some(I18nValue { |
| 43 | + zh: "发送简单的 HTTP 请求(基于 reqwest)。".to_string(), |
| 44 | + en: "Send simple HTTP requests using reqwest.".to_string(), |
| 45 | + }) |
| 46 | + } |
| 47 | + |
| 48 | + fn output_schema(&self, _input: HashMap<String, serde_json::Value>) -> Vec<SchemaField> { |
| 49 | + vec![ |
| 50 | + SchemaField { |
| 51 | + name: "status".to_string(), |
| 52 | + field_type: FieldType::Number, |
| 53 | + item_type: None, |
| 54 | + description: Some(I18nValue { |
| 55 | + zh: "HTTP 状态码".to_string(), |
| 56 | + en: "HTTP status code".to_string(), |
| 57 | + }), |
| 58 | + enums: vec![], |
| 59 | + default: None, |
| 60 | + condition: None, |
| 61 | + }, |
| 62 | + SchemaField { |
| 63 | + name: "body".to_string(), |
| 64 | + field_type: FieldType::String, |
| 65 | + item_type: None, |
| 66 | + description: Some(I18nValue { |
| 67 | + zh: "响应正文".to_string(), |
| 68 | + en: "Response body".to_string(), |
| 69 | + }), |
| 70 | + enums: vec![], |
| 71 | + default: None, |
| 72 | + condition: None, |
| 73 | + }, |
| 74 | + ] |
| 75 | + } |
| 76 | + |
| 77 | + fn input_schema(&self) -> Vec<SchemaField> { |
| 78 | + vec![ |
| 79 | + SchemaField { |
| 80 | + name: "method".to_string(), |
| 81 | + field_type: FieldType::String, |
| 82 | + item_type: None, |
| 83 | + description: Some(I18nValue { |
| 84 | + zh: "HTTP 方法,支持 GET/POST".to_string(), |
| 85 | + en: "HTTP method, supports GET/POST".to_string(), |
| 86 | + }), |
| 87 | + enums: vec!["GET".to_string(), "POST".to_string()], |
| 88 | + default: Some("GET".to_string()), |
| 89 | + condition: None, |
| 90 | + }, |
| 91 | + SchemaField { |
| 92 | + name: "url".to_string(), |
| 93 | + field_type: FieldType::String, |
| 94 | + item_type: None, |
| 95 | + description: Some(I18nValue { |
| 96 | + zh: "请求 URL".to_string(), |
| 97 | + en: "Request URL".to_string(), |
| 98 | + }), |
| 99 | + enums: vec![], |
| 100 | + default: None, |
| 101 | + condition: None, |
| 102 | + }, |
| 103 | + SchemaField { |
| 104 | + name: "headers".to_string(), |
| 105 | + field_type: FieldType::Array, |
| 106 | + item_type: Some(FieldType::String), |
| 107 | + description: Some(I18nValue { |
| 108 | + zh: "可选请求头列表,格式:Key: Value".to_string(), |
| 109 | + en: "Optional headers list, format: Key: Value".to_string(), |
| 110 | + }), |
| 111 | + enums: vec![], |
| 112 | + default: None, |
| 113 | + condition: None, |
| 114 | + }, |
| 115 | + SchemaField { |
| 116 | + name: "body".to_string(), |
| 117 | + field_type: FieldType::String, |
| 118 | + item_type: None, |
| 119 | + description: Some(I18nValue { |
| 120 | + zh: "POST 请求体,文本/JSON 皆可。".to_string(), |
| 121 | + en: "POST body, plain text or JSON string.".to_string(), |
| 122 | + }), |
| 123 | + enums: vec![], |
| 124 | + default: Some("".to_string()), |
| 125 | + condition: None, |
| 126 | + }, |
| 127 | + SchemaField { |
| 128 | + name: "timeout_ms".to_string(), |
| 129 | + field_type: FieldType::Number, |
| 130 | + item_type: None, |
| 131 | + description: Some(I18nValue { |
| 132 | + zh: "请求超时时间(毫秒),默认 30000。".to_string(), |
| 133 | + en: "Request timeout in milliseconds, default 30000.".to_string(), |
| 134 | + }), |
| 135 | + enums: vec![], |
| 136 | + default: Some("30000".to_string()), |
| 137 | + condition: None, |
| 138 | + }, |
| 139 | + ] |
| 140 | + } |
| 141 | +} |
0 commit comments