|
| 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 = "Base64Decode"; |
| 6 | + |
| 7 | +#[derive(Default)] |
| 8 | +pub struct Base64DecodeNode; |
| 9 | + |
| 10 | +impl Base64DecodeNode { |
| 11 | + pub fn new() -> Self { |
| 12 | + Self {} |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +impl NodeDefine for Base64DecodeNode { |
| 17 | + fn action_type(&self) -> String { |
| 18 | + NODE_TYPE.to_string() |
| 19 | + } |
| 20 | + |
| 21 | + fn name(&self) -> I18nValue { |
| 22 | + I18nValue { |
| 23 | + zh: "Base64 解码".to_string(), |
| 24 | + en: "Base64 Decode".to_string(), |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + fn icon(&self) -> String { |
| 29 | + String::from( |
| 30 | + "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCI+PHJlY3QgeD0iMyIgeT0iMyIgd2lkdGg9IjE4IiBoZWlnaHQ9IjE4IiByeD0iMiIvPjxwYXRoIGQ9Ik04IDEwaDgiLz48cGF0aCBkPSJNMTIgMTR2NCIvPjxwYXRoIGQ9Ik05LjUgMTUuNSAxMiAxOGwyLjUtMi41Ii8+PC9zdmc+", |
| 31 | + ) |
| 32 | + } |
| 33 | + |
| 34 | + fn category(&self) -> Option<I18nValue> { |
| 35 | + Some(I18nValue { |
| 36 | + zh: "文本处理".to_string(), |
| 37 | + en: "Text Processing".to_string(), |
| 38 | + }) |
| 39 | + } |
| 40 | + |
| 41 | + fn description(&self) -> Option<I18nValue> { |
| 42 | + Some(I18nValue { |
| 43 | + zh: "将 Base64 字符串解码为文本,包含 UTF-8 检查与长度信息。".to_string(), |
| 44 | + en: "Decode a Base64 string into text with UTF-8 validation and length info." |
| 45 | + .to_string(), |
| 46 | + }) |
| 47 | + } |
| 48 | + |
| 49 | + fn output_schema(&self, _input: HashMap<String, serde_json::Value>) -> Vec<SchemaField> { |
| 50 | + vec![ |
| 51 | + SchemaField { |
| 52 | + name: "decoded".to_string(), |
| 53 | + field_type: FieldType::String, |
| 54 | + item_type: None, |
| 55 | + description: Some(I18nValue { |
| 56 | + zh: "解码得到的文本(非 UTF-8 会采用替换字符)".to_string(), |
| 57 | + en: "Decoded text (non UTF-8 bytes are lossily converted).".to_string(), |
| 58 | + }), |
| 59 | + enums: vec![], |
| 60 | + default: None, |
| 61 | + condition: None, |
| 62 | + }, |
| 63 | + SchemaField { |
| 64 | + name: "is_utf8".to_string(), |
| 65 | + field_type: FieldType::Boolean, |
| 66 | + item_type: None, |
| 67 | + description: Some(I18nValue { |
| 68 | + zh: "解码结果是否是有效 UTF-8".to_string(), |
| 69 | + en: "Whether the decoded bytes are valid UTF-8.".to_string(), |
| 70 | + }), |
| 71 | + enums: vec![], |
| 72 | + default: None, |
| 73 | + condition: None, |
| 74 | + }, |
| 75 | + SchemaField { |
| 76 | + name: "byte_length".to_string(), |
| 77 | + field_type: FieldType::Number, |
| 78 | + item_type: None, |
| 79 | + description: Some(I18nValue { |
| 80 | + zh: "解码结果的字节长度".to_string(), |
| 81 | + en: "Byte length of the decoded result.".to_string(), |
| 82 | + }), |
| 83 | + enums: vec![], |
| 84 | + default: None, |
| 85 | + condition: None, |
| 86 | + }, |
| 87 | + ] |
| 88 | + } |
| 89 | + |
| 90 | + fn input_schema(&self) -> Vec<SchemaField> { |
| 91 | + vec![ |
| 92 | + SchemaField { |
| 93 | + name: "data".to_string(), |
| 94 | + field_type: FieldType::String, |
| 95 | + item_type: None, |
| 96 | + description: Some(I18nValue { |
| 97 | + zh: "需要解码的 Base64 字符串".to_string(), |
| 98 | + en: "Base64 string to decode.".to_string(), |
| 99 | + }), |
| 100 | + enums: vec![], |
| 101 | + default: None, |
| 102 | + condition: None, |
| 103 | + }, |
| 104 | + SchemaField { |
| 105 | + name: "url_safe".to_string(), |
| 106 | + field_type: FieldType::Boolean, |
| 107 | + item_type: None, |
| 108 | + description: Some(I18nValue { |
| 109 | + zh: "是否使用 URL Safe 字母表".to_string(), |
| 110 | + en: "Use the URL-safe alphabet.".to_string(), |
| 111 | + }), |
| 112 | + enums: vec![], |
| 113 | + default: None, |
| 114 | + condition: None, |
| 115 | + }, |
| 116 | + SchemaField { |
| 117 | + name: "no_padding".to_string(), |
| 118 | + field_type: FieldType::Boolean, |
| 119 | + item_type: None, |
| 120 | + description: Some(I18nValue { |
| 121 | + zh: "输入是否移除了末尾填充符号 \"=\"".to_string(), |
| 122 | + en: "Input omits trailing padding characters (=).".to_string(), |
| 123 | + }), |
| 124 | + enums: vec![], |
| 125 | + default: None, |
| 126 | + condition: None, |
| 127 | + }, |
| 128 | + ] |
| 129 | + } |
| 130 | +} |
0 commit comments