mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-21 21:48:21 -05:00
fix: safe search url parameter ignored
This commit is contained in:
parent
7d762b3726
commit
6e9250c03a
@ -63,19 +63,21 @@ pub async fn search(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get search settings using the user's cookie or from the server's config
|
// Get search settings using the user's cookie or from the server's config
|
||||||
let search_settings: server_models::Cookie = match req.cookie("appCookie") {
|
let mut search_settings: server_models::Cookie = match req.cookie("appCookie") {
|
||||||
Some(cookie_value) => {
|
Some(cookie_value) => {
|
||||||
if let Ok(cookie) = serde_json::from_str(cookie_value.value()) {
|
match serde_json::from_str(cookie_value.value()) {
|
||||||
cookie
|
Ok(cookie) => cookie,
|
||||||
// If there's an issue parsing the cookie's value, default to the config
|
// If there's an issue parsing the cookie's value, default to the config
|
||||||
} else {
|
Err(_) => build_cookie(),
|
||||||
build_cookie()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If there's no cookie saved, use the server's config
|
// If there's no cookie saved, use the server's config
|
||||||
None => build_cookie(),
|
None => build_cookie(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
search_settings.safe_search_level =
|
||||||
|
get_safesearch_level(¶ms.safesearch, config.safe_search);
|
||||||
|
|
||||||
// Closure wrapping the results function capturing local references
|
// Closure wrapping the results function capturing local references
|
||||||
let get_results = |page| results(&config, &cache, query, page, &search_settings);
|
let get_results = |page| results(&config, &cache, query, page, &search_settings);
|
||||||
|
|
||||||
@ -228,3 +230,24 @@ fn is_match_from_filter_list(
|
|||||||
|
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A helper function which returns the safe search level based on the url params
|
||||||
|
/// and cookie value.
|
||||||
|
///
|
||||||
|
/// # Argurments
|
||||||
|
///
|
||||||
|
/// * `safe_search` - Safe search level from the url.
|
||||||
|
/// * `cookie` - User's cookie
|
||||||
|
/// * `default` - Safe search level to fall back to
|
||||||
|
fn get_safesearch_level(safe_search: &Option<u8>, default: u8) -> u8 {
|
||||||
|
match safe_search {
|
||||||
|
Some(ss) => {
|
||||||
|
if *ss >= 3 {
|
||||||
|
default
|
||||||
|
} else {
|
||||||
|
*ss
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => default,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user