mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-21 13:38:21 -05:00
change: revert Cookie Strings back to &str
This commit is contained in:
parent
6e9250c03a
commit
d912bff94e
@ -21,24 +21,24 @@ pub struct SearchParams {
|
|||||||
/// A named struct which is used to deserialize the cookies fetched from the client side.
|
/// A named struct which is used to deserialize the cookies fetched from the client side.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Cookie {
|
pub struct Cookie<'a> {
|
||||||
/// It stores the theme name used in the website.
|
/// It stores the theme name used in the website.
|
||||||
pub theme: String,
|
pub theme: &'a str,
|
||||||
/// It stores the colorscheme name used for the website theme.
|
/// It stores the colorscheme name used for the website theme.
|
||||||
pub colorscheme: String,
|
pub colorscheme: &'a str,
|
||||||
/// It stores the user selected upstream search engines selected from the UI.
|
/// It stores the user selected upstream search engines selected from the UI.
|
||||||
pub engines: Vec<String>,
|
pub engines: Vec<String>,
|
||||||
/// It stores the user selected safe search level from the UI.
|
/// It stores the user selected safe search level from the UI.
|
||||||
pub safe_search_level: u8,
|
pub safe_search_level: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cookie {
|
impl<'a> Cookie<'a> {
|
||||||
/// server_models::Cookie contructor function
|
/// server_models::Cookie contructor function
|
||||||
pub fn build(style: &Style, mut engines: Vec<String>, safe_search_level: u8) -> Self {
|
pub fn build(style: &'a Style, mut engines: Vec<String>, safe_search_level: u8) -> Self {
|
||||||
engines.sort();
|
engines.sort();
|
||||||
Self {
|
Self {
|
||||||
theme: style.theme.clone(),
|
theme: &style.theme,
|
||||||
colorscheme: style.colorscheme.clone(),
|
colorscheme: &style.colorscheme,
|
||||||
engines,
|
engines,
|
||||||
safe_search_level,
|
safe_search_level,
|
||||||
}
|
}
|
||||||
|
@ -62,9 +62,11 @@ pub async fn search(
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let cookie = req.cookie("appCookie");
|
||||||
|
|
||||||
// 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 mut search_settings: server_models::Cookie = match req.cookie("appCookie") {
|
let mut search_settings: server_models::Cookie<'_> = match cookie {
|
||||||
Some(cookie_value) => {
|
Some(ref cookie_value) => {
|
||||||
match serde_json::from_str(cookie_value.value()) {
|
match serde_json::from_str(cookie_value.value()) {
|
||||||
Ok(cookie) => 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
|
||||||
@ -127,10 +129,10 @@ async fn results(
|
|||||||
cache: &web::Data<SharedCache>,
|
cache: &web::Data<SharedCache>,
|
||||||
query: &str,
|
query: &str,
|
||||||
page: u32,
|
page: u32,
|
||||||
user_settings: &server_models::Cookie,
|
search_settings: &server_models::Cookie<'_>,
|
||||||
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
||||||
// eagerly parse cookie value to evaluate safe search level
|
// eagerly parse cookie value to evaluate safe search level
|
||||||
let safe_search_level = user_settings.safe_search_level;
|
let safe_search_level = search_settings.safe_search_level;
|
||||||
|
|
||||||
let cache_key = format!(
|
let cache_key = format!(
|
||||||
"http://{}:{}/search?q={}&page={}&safesearch={}&engines={}",
|
"http://{}:{}/search?q={}&page={}&safesearch={}&engines={}",
|
||||||
@ -139,7 +141,7 @@ async fn results(
|
|||||||
query,
|
query,
|
||||||
page,
|
page,
|
||||||
safe_search_level,
|
safe_search_level,
|
||||||
user_settings.engines.join(",")
|
search_settings.engines.join(",")
|
||||||
);
|
);
|
||||||
|
|
||||||
// fetch the cached results json.
|
// fetch the cached results json.
|
||||||
@ -167,14 +169,14 @@ async fn results(
|
|||||||
// default selected upstream search engines from the config file otherwise
|
// default selected upstream search engines from the config file otherwise
|
||||||
// parse the non-empty cookie and grab the user selected engines from the
|
// parse the non-empty cookie and grab the user selected engines from the
|
||||||
// UI and use that.
|
// UI and use that.
|
||||||
let mut results: SearchResults = match user_settings.engines.is_empty() {
|
let mut results: SearchResults = match search_settings.engines.is_empty() {
|
||||||
false => {
|
false => {
|
||||||
aggregate(
|
aggregate(
|
||||||
query,
|
query,
|
||||||
page,
|
page,
|
||||||
config.aggregator.random_delay,
|
config.aggregator.random_delay,
|
||||||
config.debug,
|
config.debug,
|
||||||
&user_settings
|
&search_settings
|
||||||
.engines
|
.engines
|
||||||
.clone()
|
.clone()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
Loading…
Reference in New Issue
Block a user