markdown_translator/
types.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct TranslationConfig {
22 pub enabled: bool,
24 pub source_lang: String,
26 pub target_lang: String,
28 pub deeplx_api_url: String,
30 pub max_requests_per_second: f64,
32 pub max_text_length: usize,
34 pub max_paragraphs_per_request: usize,
36}
37
38impl Default for TranslationConfig {
39 fn default() -> Self {
40 Self {
41 enabled: false,
42 source_lang: "auto".to_string(),
43 target_lang: "zh".to_string(),
44 deeplx_api_url: "http://localhost:1188/translate".to_string(),
45 max_requests_per_second: 0.5,
46 max_text_length: 3000,
47 max_paragraphs_per_request: 10,
48 }
49 }
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct RetryConfig {
54 pub max_retries: usize,
55 pub initial_delay_ms: u64,
56 pub max_delay_ms: u64,
57 pub backoff_multiplier: f64,
58}
59
60impl Default for RetryConfig {
61 fn default() -> Self {
62 Self {
63 max_retries: 1, initial_delay_ms: 100, max_delay_ms: 1000, backoff_multiplier: 1.2, }
68 }
69}
70
71#[derive(Debug, Serialize, Deserialize)]
72pub struct DeepLXRequest {
73 pub text: String,
74 pub source_lang: String,
75 pub target_lang: String,
76}
77
78#[derive(Debug, Serialize, Deserialize)]
79pub struct DpTransRequest {
80 pub text: String,
81 pub source_lang: String,
82 pub target_lang: String,
83}
84
85#[derive(Debug, Deserialize)]
86pub struct DeepLXResponse {
87 pub code: i32,
88 pub data: String,
89}
90
91#[derive(Debug, Clone)]
92pub struct TextSegment {
93 pub content: String,
94 pub is_code_block: bool,
95}