Spaces:
Running
Running
neon_arch
commited on
Commit
·
b9d651c
1
Parent(s):
30ca95a
🧹 chore: make github actions happy (#203)
Browse files- src/config/parser.rs +37 -25
src/config/parser.rs
CHANGED
|
@@ -36,6 +36,7 @@ pub struct Config {
|
|
| 36 |
pub request_timeout: u8,
|
| 37 |
pub threads: u8,
|
| 38 |
pub rate_limiter: RateLimiter,
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
impl Config {
|
|
@@ -79,33 +80,44 @@ impl Config {
|
|
| 79 |
parsed_threads
|
| 80 |
};
|
| 81 |
|
| 82 |
-
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
redis_url: globals.get::<_, String>("redis_url")?,
|
| 92 |
-
aggregator: AggregatorConfig {
|
| 93 |
-
random_delay: globals.get::<_, bool>("production_use")?,
|
| 94 |
-
},
|
| 95 |
-
logging,
|
| 96 |
-
debug,
|
| 97 |
-
upstream_search_engines: globals
|
| 98 |
-
.get::<_, HashMap<String, bool>>("upstream_search_engines")?
|
| 99 |
-
.into_iter()
|
| 100 |
-
.filter_map(|(key, value)| value.then_some(key))
|
| 101 |
-
.filter_map(|engine| crate::engines::engine_models::EngineHandler::new(&engine))
|
| 102 |
-
.collect(),
|
| 103 |
-
request_timeout: globals.get::<_, u8>("request_timeout")?,
|
| 104 |
-
threads,
|
| 105 |
-
rate_limiter: RateLimiter {
|
| 106 |
-
number_of_requests: rate_limiter["number_of_requests"],
|
| 107 |
-
time_limit: rate_limiter["time_limit"],
|
| 108 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
})
|
| 110 |
}
|
| 111 |
}
|
|
|
|
| 36 |
pub request_timeout: u8,
|
| 37 |
pub threads: u8,
|
| 38 |
pub rate_limiter: RateLimiter,
|
| 39 |
+
pub safe_search: u8,
|
| 40 |
}
|
| 41 |
|
| 42 |
impl Config {
|
|
|
|
| 80 |
parsed_threads
|
| 81 |
};
|
| 82 |
|
| 83 |
+
let rate_limiter = globals.get::<_, HashMap<String, u8>>("rate_limiter")?;
|
| 84 |
|
| 85 |
+
let parsed_safe_search: u8 = globals.get::<_, u8>("safe_search")?;
|
| 86 |
+
let safe_search: u8 = match parsed_safe_search {
|
| 87 |
+
0..=4 => parsed_safe_search,
|
| 88 |
+
_ => {
|
| 89 |
+
log::error!("Config Error: The value of `safe_search` option should be a non zero positive integer from 0 to 4.");
|
| 90 |
+
log::error!("Falling back to using the value `1` for the option");
|
| 91 |
+
1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
Ok(Config {
|
| 96 |
+
port: globals.get::<_, u16>("port")?,
|
| 97 |
+
binding_ip: globals.get::<_, String>("binding_ip")?,
|
| 98 |
+
style: Style::new(
|
| 99 |
+
globals.get::<_, String>("theme")?,
|
| 100 |
+
globals.get::<_, String>("colorscheme")?,
|
| 101 |
+
),
|
| 102 |
+
redis_url: globals.get::<_, String>("redis_url")?,
|
| 103 |
+
aggregator: AggregatorConfig {
|
| 104 |
+
random_delay: globals.get::<_, bool>("production_use")?,
|
| 105 |
+
},
|
| 106 |
+
logging,
|
| 107 |
+
debug,
|
| 108 |
+
upstream_search_engines: globals
|
| 109 |
+
.get::<_, HashMap<String, bool>>("upstream_search_engines")?
|
| 110 |
+
.into_iter()
|
| 111 |
+
.filter_map(|(key, value)| value.then_some(key))
|
| 112 |
+
.filter_map(|engine| crate::engines::engine_models::EngineHandler::new(&engine))
|
| 113 |
+
.collect(),
|
| 114 |
+
request_timeout: globals.get::<_, u8>("request_timeout")?,
|
| 115 |
+
threads,
|
| 116 |
+
rate_limiter: RateLimiter {
|
| 117 |
+
number_of_requests: rate_limiter["number_of_requests"],
|
| 118 |
+
time_limit: rate_limiter["time_limit"],
|
| 119 |
+
},
|
| 120 |
+
safe_search,
|
| 121 |
})
|
| 122 |
}
|
| 123 |
}
|