data_faking/data/image/
flickr.rs1use wasm_bindgen::prelude::*;
2
3use crate::utils::seeder;
4
5const URL_BASE: &str = "https://loremflickr.com";
6
7pub fn image_flickr(props: Option<Flickr_Properties>) -> String {
9 let mut height = seeder::gen_range(1..4000);
10 let mut width = seeder::gen_range(1..4000);
11 let mut category: String = "".to_string();
12 let lock: u32 = seeder::gen();
13
14 if props.is_some() {
15 let p = props.unwrap();
16 if p.height.is_some() {
17 let h = p.height.unwrap();
18 height = if h < 1 {
19 1
20 } else if h >= 4000 {
21 3999
22 } else {
23 h
24 };
25 }
26
27 if p.width.is_some() {
28 let w = p.width.unwrap();
29 width = if w < 1 {
30 1
31 } else if w >= 4000 {
32 3999
33 } else {
34 w
35 }
36 }
37
38 if p.category.is_some() {
39 let c = p.category.unwrap();
40 category = c.to_string();
41 }
42 }
43
44 format!("{}/{}/{}/{}?lock={}", URL_BASE, width.to_string(), height.to_string(), category, lock.to_string())
45}
46
47#[derive(Clone)]
49pub struct Flickr_Properties {
50 pub height: Option<u16>,
51 pub width: Option<u16>,
52 pub category: Option<&'static str>,
53}