1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use serde::{Deserialize, Serialize};
use validator::Validate;
use crate::compose;
use crate::val_helpr::ValidationResult;
#[derive(Default, Validate, Debug, Serialize, Deserialize)]
pub struct Contents {
#[validate(length(max = 3000))]
pub image_url: String,
#[validate(length(max = 2000))]
pub alt_text: String,
#[validate(custom = "compose::validation::text_is_plain")]
#[validate(custom = "validation::text_max_len_2k")]
pub title: Option<compose::Text>,
#[validate(length(max = 255))]
pub block_id: Option<String>,
}
impl Contents {
pub fn validate(&self) -> ValidationResult {
Validate::validate(self)
}
}
mod validation {
use crate::compose;
use crate::val_helpr::ValidatorResult;
pub fn text_max_len_2k(text: &compose::Text) -> ValidatorResult {
compose::validation::text_max_len(text, 2000)
}
}