Spaces:
Runtime error
Runtime error
neon_arch
commited on
Commit
•
3e6f786
1
Parent(s):
27247ba
✨ feat: add code to parse cookies and handle engine selection from UI
Browse files- src/server/routes.rs +15 -2
src/server/routes.rs
CHANGED
@@ -51,6 +51,14 @@ pub async fn not_found(
|
|
51 |
.body(page_content))
|
52 |
}
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
/// Handles the route of search page of the `websurfx` meta search engine website and it takes
|
55 |
/// two search url parameters `q` and `page` where `page` parameter is optional.
|
56 |
///
|
@@ -127,8 +135,13 @@ pub async fn search(
|
|
127 |
Ok(HttpResponse::Ok().body(page_content))
|
128 |
}
|
129 |
Err(_) => {
|
130 |
-
let mut results_json: crate::search_results_handler::aggregation_models::SearchResults =
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
132 |
results_json.add_style(config.style.clone());
|
133 |
redis_cache
|
134 |
.cache_results(serde_json::to_string(&results_json)?, &page_url)?;
|
|
|
51 |
.body(page_content))
|
52 |
}
|
53 |
|
54 |
+
#[allow(dead_code)]
|
55 |
+
#[derive(Deserialize)]
|
56 |
+
struct Cookie {
|
57 |
+
theme: String,
|
58 |
+
colorscheme: String,
|
59 |
+
engines: Vec<String>,
|
60 |
+
}
|
61 |
+
|
62 |
/// Handles the route of search page of the `websurfx` meta search engine website and it takes
|
63 |
/// two search url parameters `q` and `page` where `page` parameter is optional.
|
64 |
///
|
|
|
135 |
Ok(HttpResponse::Ok().body(page_content))
|
136 |
}
|
137 |
Err(_) => {
|
138 |
+
let mut results_json: crate::search_results_handler::aggregation_models::SearchResults = match req.cookie("appCookie") {
|
139 |
+
Some(cookie_value) => {
|
140 |
+
let cookie_value:Cookie = serde_json::from_str(cookie_value.name_value().1).unwrap();
|
141 |
+
aggregate(query.clone(), page, config.aggregator.random_delay, config.debug, cookie_value.engines).await?
|
142 |
+
},
|
143 |
+
None => aggregate(query.clone(), page, config.aggregator.random_delay, config.debug, config.upstream_search_engines.clone()).await?,
|
144 |
+
};
|
145 |
results_json.add_style(config.style.clone());
|
146 |
redis_cache
|
147 |
.cache_results(serde_json::to_string(&results_json)?, &page_url)?;
|