mirror of
https://github.com/YGGverse/btracker-gemini.git
synced 2026-03-31 09:05:30 +00:00
decode search query
This commit is contained in:
parent
ca2a93379b
commit
20d9a5e573
2 changed files with 10 additions and 3 deletions
|
|
@ -157,7 +157,7 @@ fn response(
|
||||||
debug!("Incoming request from `{peer}` to `{}`", request.url.path());
|
debug!("Incoming request from `{peer}` to `{}`", request.url.path());
|
||||||
send(
|
send(
|
||||||
&match Route::from_url(&request.url) {
|
&match Route::from_url(&request.url) {
|
||||||
Route::List { page } => match list(config, public, request.url.query(), page) {
|
Route::List { page, keyword } => match list(config, public, keyword.as_deref(), page) {
|
||||||
Ok(data) => success::Default {
|
Ok(data) => success::Default {
|
||||||
data: data.as_bytes(),
|
data: data.as_bytes(),
|
||||||
meta: success::default::Meta {
|
meta: success::default::Meta {
|
||||||
|
|
|
||||||
11
src/route.rs
11
src/route.rs
|
|
@ -6,7 +6,10 @@ use url::Url;
|
||||||
|
|
||||||
pub enum Route {
|
pub enum Route {
|
||||||
Info(Id20),
|
Info(Id20),
|
||||||
List { page: Option<usize> },
|
List {
|
||||||
|
keyword: Option<String>,
|
||||||
|
page: Option<usize>,
|
||||||
|
},
|
||||||
NotFound,
|
NotFound,
|
||||||
Search,
|
Search,
|
||||||
}
|
}
|
||||||
|
|
@ -17,7 +20,10 @@ impl Route {
|
||||||
let q = url.query();
|
let q = url.query();
|
||||||
|
|
||||||
if p.is_empty() {
|
if p.is_empty() {
|
||||||
return Self::List { page: None };
|
return Self::List {
|
||||||
|
keyword: None,
|
||||||
|
page: None,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(id) = Id20::from_str(p.trim_matches('/')) {
|
if let Ok(id) = Id20::from_str(p.trim_matches('/')) {
|
||||||
|
|
@ -30,6 +36,7 @@ impl Route {
|
||||||
|
|
||||||
if Regex::new(r"^/(|search)").unwrap().is_match(&p) {
|
if Regex::new(r"^/(|search)").unwrap().is_match(&p) {
|
||||||
return Self::List {
|
return Self::List {
|
||||||
|
keyword: q.and_then(|k| urlencoding::decode(k).ok().map(|k| k.into())),
|
||||||
page: Regex::new(r"/(\d+)$").unwrap().captures(&p).map(|c| {
|
page: Regex::new(r"/(\d+)$").unwrap().captures(&p).map(|c| {
|
||||||
c.get(1)
|
c.get(1)
|
||||||
.map_or(1, |p| p.as_str().parse::<usize>().unwrap_or(1))
|
.map_or(1, |p| p.as_str().parse::<usize>().unwrap_or(1))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue