mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-24 06:58:22 -05:00
refactor search route and change default page to 0
that thing was utterly insane, and i am not sorry for saying this
This commit is contained in:
parent
bb65e4e018
commit
1f90b4e15c
@ -30,8 +30,8 @@ function navigate_backward() {
|
|||||||
let page = parseInt(searchParams.get('page'));
|
let page = parseInt(searchParams.get('page'));
|
||||||
|
|
||||||
if (isNaN(page)) {
|
if (isNaN(page)) {
|
||||||
page = 1;
|
page = 0;
|
||||||
} else if (page > 1) {
|
} else if (page > 0) {
|
||||||
page--;
|
page--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//! This module provides the functionality to handle different routes of the `websurfx`
|
//! This module provides the functionality to handle different routes of the `websurfx`
|
||||||
//! meta search engine website and provide approriate response to each route/page
|
//! meta search engine website and provide appropriate response to each route/page
|
||||||
//! when requested.
|
//! when requested.
|
||||||
|
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
@ -82,40 +82,16 @@ pub async fn search(
|
|||||||
.insert_header(("location", "/"))
|
.insert_header(("location", "/"))
|
||||||
.finish())
|
.finish())
|
||||||
} else {
|
} else {
|
||||||
let page_url: String; // Declare the page_url variable without initializing it
|
let page = match ¶ms.page {
|
||||||
|
Some(page) => *page,
|
||||||
// ...
|
None => 0,
|
||||||
|
|
||||||
let page = match params.page {
|
|
||||||
Some(page_number) => {
|
|
||||||
if page_number <= 1 {
|
|
||||||
page_url = format!(
|
|
||||||
"http://{}:{}/search?q={}&page={}",
|
|
||||||
config.binding_ip_addr, config.port, query, 1
|
|
||||||
);
|
|
||||||
1
|
|
||||||
} else {
|
|
||||||
page_url = format!(
|
|
||||||
"http://{}:{}/search?q={}&page={}",
|
|
||||||
config.binding_ip_addr, config.port, query, page_number
|
|
||||||
);
|
|
||||||
|
|
||||||
page_number
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
page_url = format!(
|
|
||||||
"http://{}:{}{}&page={}",
|
|
||||||
config.binding_ip_addr,
|
|
||||||
config.port,
|
|
||||||
req.uri(),
|
|
||||||
1
|
|
||||||
);
|
|
||||||
|
|
||||||
1
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let page_url = format!(
|
||||||
|
"http://{}:{}/search?q={}&page={}",
|
||||||
|
config.binding_ip_addr, config.port, query, page
|
||||||
|
);
|
||||||
|
|
||||||
// fetch the cached results json.
|
// fetch the cached results json.
|
||||||
let cached_results_json = redis_cache.cached_results_json(&page_url);
|
let cached_results_json = redis_cache.cached_results_json(&page_url);
|
||||||
// check if fetched results was indeed fetched or it was an error and if so
|
// check if fetched results was indeed fetched or it was an error and if so
|
||||||
|
Loading…
Reference in New Issue
Block a user