frames_core/validators/
image.rs1use crate::{
2 types::{
3 errors::{Error, ErrorCode, FrameErrors},
4 image::{AspectRatio, FrameImage},
5 },
6 URL_REGEX,
7};
8
9impl FrameImage {
10 pub fn validate(&self) -> Result<(), FrameErrors> {
11 let mut errors = FrameErrors::new();
12
13 if !URL_REGEX.is_match(&self.url) {
17 let error = Error {
18 description: "The URL provided is invalid.".to_string(),
19 code: ErrorCode::InvalidURL,
20 key: Some("fc:frame:image".to_string()),
21 };
22 errors.add_error(error);
23 }
24
25 if self.aspect_ratio == AspectRatio::Error {
26 let error = Error {
27 description: "Invalid image aspect ratio.".to_string(),
28 code: ErrorCode::InvalidAspectRadio,
29 key: Some("fc:frame:image:aspect_ratio".to_string()),
30 };
31 errors.add_error(error);
32 }
33
34 if !errors.is_empty() {
35 return Err(errors);
36 }
37
38 Ok(())
39 }
40}