0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-21 21:48:21 -05:00

♻️ refactor: rewrite the parsing of the upstream search engines option (#302)

This commit is contained in:
neon_arch 2023-11-18 21:46:36 +03:00
parent 686e26ad6d
commit c39d9ff0b0

View File

@ -3,7 +3,6 @@
use crate::handler::paths::{file_path, FileType}; use crate::handler::paths::{file_path, FileType};
use crate::models::engine_models::{EngineError, EngineHandler};
use crate::models::parser_models::{AggregatorConfig, RateLimiter, Style}; use crate::models::parser_models::{AggregatorConfig, RateLimiter, Style};
use log::LevelFilter; use log::LevelFilter;
use mlua::Lua; use mlua::Lua;
@ -29,7 +28,7 @@ pub struct Config {
/// It stores the option to whether enable or disable debug mode. /// It stores the option to whether enable or disable debug mode.
pub debug: bool, pub debug: bool,
/// It stores all the engine names that were enabled by the user. /// It stores all the engine names that were enabled by the user.
pub upstream_search_engines: Vec<EngineHandler>, pub upstream_search_engines: HashMap<String, bool>,
/// It stores the time (secs) which controls the server request timeout. /// It stores the time (secs) which controls the server request timeout.
pub request_timeout: u8, pub request_timeout: u8,
/// It stores the number of threads which controls the app will use to run. /// It stores the number of threads which controls the app will use to run.
@ -109,11 +108,7 @@ impl Config {
logging, logging,
debug, debug,
upstream_search_engines: globals upstream_search_engines: globals
.get::<_, HashMap<String, bool>>("upstream_search_engines")? .get::<_, HashMap<String, bool>>("upstream_search_engines")?,
.into_iter()
.filter_map(|(key, value)| value.then_some(key))
.map(|engine| EngineHandler::new(&engine))
.collect::<Result<Vec<EngineHandler>, error_stack::Report<EngineError>>>()?,
request_timeout: globals.get::<_, u8>("request_timeout")?, request_timeout: globals.get::<_, u8>("request_timeout")?,
threads, threads,
rate_limiter: RateLimiter { rate_limiter: RateLimiter {