2023-09-03 13:50:50 -04:00
|
|
|
//! This module provides the models to parse cookies and search parameters from the search
|
|
|
|
//! engine website.
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
2024-01-07 18:29:39 -05:00
|
|
|
use super::parser_models::Style;
|
|
|
|
|
2023-09-03 13:50:50 -04:00
|
|
|
/// A named struct which deserializes all the user provided search parameters and stores them.
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct SearchParams {
|
|
|
|
/// It stores the search parameter option `q` (or query in simple words)
|
|
|
|
/// of the search url.
|
|
|
|
pub q: Option<String>,
|
|
|
|
/// It stores the search parameter `page` (or pageno in simple words)
|
|
|
|
/// of the search url.
|
|
|
|
pub page: Option<u32>,
|
2023-09-17 05:48:52 -04:00
|
|
|
/// It stores the search parameter `safesearch` (or safe search level in simple words) of the
|
|
|
|
/// search url.
|
|
|
|
pub safesearch: Option<u8>,
|
2023-09-03 13:50:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A named struct which is used to deserialize the cookies fetched from the client side.
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[derive(Deserialize)]
|
2024-01-08 13:46:21 -05:00
|
|
|
pub struct Cookie<'a> {
|
2023-09-03 13:50:50 -04:00
|
|
|
/// It stores the theme name used in the website.
|
2024-01-08 13:46:21 -05:00
|
|
|
pub theme: &'a str,
|
2023-09-03 13:50:50 -04:00
|
|
|
/// It stores the colorscheme name used for the website theme.
|
2024-01-08 13:46:21 -05:00
|
|
|
pub colorscheme: &'a str,
|
2023-09-03 13:50:50 -04:00
|
|
|
/// It stores the user selected upstream search engines selected from the UI.
|
2024-01-07 18:29:39 -05:00
|
|
|
pub engines: Vec<String>,
|
2023-09-22 12:53:34 -04:00
|
|
|
/// It stores the user selected safe search level from the UI.
|
|
|
|
pub safe_search_level: u8,
|
2023-09-03 13:50:50 -04:00
|
|
|
}
|
2024-01-07 18:29:39 -05:00
|
|
|
|
2024-01-08 13:46:21 -05:00
|
|
|
impl<'a> Cookie<'a> {
|
2024-01-07 18:29:39 -05:00
|
|
|
/// server_models::Cookie contructor function
|
2024-01-08 13:46:21 -05:00
|
|
|
pub fn build(style: &'a Style, mut engines: Vec<String>, safe_search_level: u8) -> Self {
|
2024-01-07 18:29:39 -05:00
|
|
|
engines.sort();
|
|
|
|
Self {
|
2024-01-08 13:46:21 -05:00
|
|
|
theme: &style.theme,
|
|
|
|
colorscheme: &style.colorscheme,
|
2024-01-07 18:29:39 -05:00
|
|
|
engines,
|
|
|
|
safe_search_level,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|