| 1 | //! Teams video clips: an AMS `<video src=".../views/video">`, shown through the object's thumbnail view. |
| 2 | |
| 3 | const VIDEO_VIEW: &str = "/views/video"; |
| 4 | const THUMBNAIL_VIEW: &str = "/views/thumbnail"; |
| 5 | |
| 6 | /// The thumbnail view of the AMS video clip at `src`. |
| 7 | pub fn video_thumbnail_url(src: &str) -> Option<String> { |
| 8 | let object = src.strip_suffix(VIDEO_VIEW)?; |
| 9 | chatsvc::is_ams_image_url(src).then(|| format!("{object}{THUMBNAIL_VIEW}")) |
| 10 | } |
| 11 | |
| 12 | /// The clip behind a thumbnail from [`video_thumbnail_url`]. |
| 13 | pub fn thumbnail_video_url(url: &str) -> Option<String> { |
| 14 | let object = url.strip_suffix(THUMBNAIL_VIEW)?; |
| 15 | chatsvc::is_ams_image_url(url).then(|| format!("{object}{VIDEO_VIEW}")) |
| 16 | } |
| 17 | |
| 18 | #[cfg(test)] |
| 19 | mod tests { |
| 20 | use super::*; |
| 21 | |
| 22 | const CLIP: &str = "https://eu-api.asm.skype.com/v1/objects/0-weu-d19-abc/views/video"; |
| 23 | |
| 24 | #[test] |
| 25 | fn an_ams_clip_is_shown_by_its_thumbnail_and_played_from_it() { |
| 26 | let thumbnail = video_thumbnail_url(CLIP).unwrap(); |
| 27 | assert_eq!( |
| 28 | thumbnail, |
| 29 | "https://eu-api.asm.skype.com/v1/objects/0-weu-d19-abc/views/thumbnail" |
| 30 | ); |
| 31 | assert_eq!(thumbnail_video_url(&thumbnail).as_deref(), Some(CLIP)); |
| 32 | assert_eq!( |
| 33 | video_thumbnail_url("https://x.example/v1/objects/a/views/video"), |
| 34 | None |
| 35 | ); |
| 36 | assert_eq!( |
| 37 | thumbnail_video_url("https://eu-api.asm.skype.com/v1/objects/a/views/imgo"), |
| 38 | None |
| 39 | ); |
| 40 | } |
| 41 | } |