Milim
commited on
Commit
•
1f90b4e
1
Parent(s):
bb65e4e
refactor search route and change default page to 0
Browse filesthat thing was utterly insane, and i am not sorry for saying this
- public/static/pagination.js +2 -2
- src/server/routes.rs +9 -33
public/static/pagination.js
CHANGED
@@ -30,8 +30,8 @@ function navigate_backward() {
|
|
30 |
let page = parseInt(searchParams.get('page'));
|
31 |
|
32 |
if (isNaN(page)) {
|
33 |
-
page =
|
34 |
-
} else if (page >
|
35 |
page--;
|
36 |
}
|
37 |
|
|
|
30 |
let page = parseInt(searchParams.get('page'));
|
31 |
|
32 |
if (isNaN(page)) {
|
33 |
+
page = 0;
|
34 |
+
} else if (page > 0) {
|
35 |
page--;
|
36 |
}
|
37 |
|
src/server/routes.rs
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
//! This module provides the functionality to handle different routes of the `websurfx`
|
2 |
-
//! meta search engine website and provide
|
3 |
//! when requested.
|
4 |
|
5 |
use std::fs::read_to_string;
|
@@ -82,40 +82,16 @@ pub async fn search(
|
|
82 |
.insert_header(("location", "/"))
|
83 |
.finish())
|
84 |
} else {
|
85 |
-
let
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
let page = match params.page {
|
90 |
-
Some(page_number) => {
|
91 |
-
if page_number <= 1 {
|
92 |
-
page_url = format!(
|
93 |
-
"http://{}:{}/search?q={}&page={}",
|
94 |
-
config.binding_ip_addr, config.port, query, 1
|
95 |
-
);
|
96 |
-
1
|
97 |
-
} else {
|
98 |
-
page_url = format!(
|
99 |
-
"http://{}:{}/search?q={}&page={}",
|
100 |
-
config.binding_ip_addr, config.port, query, page_number
|
101 |
-
);
|
102 |
-
|
103 |
-
page_number
|
104 |
-
}
|
105 |
-
}
|
106 |
-
None => {
|
107 |
-
page_url = format!(
|
108 |
-
"http://{}:{}{}&page={}",
|
109 |
-
config.binding_ip_addr,
|
110 |
-
config.port,
|
111 |
-
req.uri(),
|
112 |
-
1
|
113 |
-
);
|
114 |
-
|
115 |
-
1
|
116 |
-
}
|
117 |
};
|
118 |
|
|
|
|
|
|
|
|
|
|
|
119 |
// fetch the cached results json.
|
120 |
let cached_results_json = redis_cache.cached_results_json(&page_url);
|
121 |
// check if fetched results was indeed fetched or it was an error and if so
|
|
|
1 |
//! This module provides the functionality to handle different routes of the `websurfx`
|
2 |
+
//! meta search engine website and provide appropriate response to each route/page
|
3 |
//! when requested.
|
4 |
|
5 |
use std::fs::read_to_string;
|
|
|
82 |
.insert_header(("location", "/"))
|
83 |
.finish())
|
84 |
} else {
|
85 |
+
let page = match ¶ms.page {
|
86 |
+
Some(page) => *page,
|
87 |
+
None => 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
};
|
89 |
|
90 |
+
let page_url = format!(
|
91 |
+
"http://{}:{}/search?q={}&page={}",
|
92 |
+
config.binding_ip_addr, config.port, query, page
|
93 |
+
);
|
94 |
+
|
95 |
// fetch the cached results json.
|
96 |
let cached_results_json = redis_cache.cached_results_json(&page_url);
|
97 |
// check if fetched results was indeed fetched or it was an error and if so
|