mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-04 23:44:13 +00:00
implement search request handler
This commit is contained in:
parent
3f4efee60b
commit
e669034452
@ -73,9 +73,17 @@ impl Client {
|
||||
time: now(),
|
||||
value: query.to_string(),
|
||||
});
|
||||
Request::parse(query, None)
|
||||
.unwrap() // @TODO
|
||||
.handle(self, self.new_cancellable(), callback);
|
||||
match Request::parse(query, None) {
|
||||
Ok(request) => request.handle(self, self.new_cancellable(), callback),
|
||||
Err(e) => callback(match e {
|
||||
// return failure response on unsupported scheme detected
|
||||
request::Error::Unsupported => Response::Failure(response::Failure::Error {
|
||||
message: "Request scheme yet not supported".to_string(),
|
||||
}),
|
||||
// request redirection to default search provider
|
||||
_ => Response::Redirect(response::Redirect::Foreground(request::search(query))),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get new [Cancellable](https://docs.gtk.org/gio/class.Cancellable.html) by cancel previous one
|
||||
|
@ -1,9 +1,10 @@
|
||||
mod error;
|
||||
mod feature;
|
||||
mod gemini;
|
||||
mod search;
|
||||
|
||||
use super::{Client, Response};
|
||||
use error::Error;
|
||||
pub use error::Error;
|
||||
use feature::Feature;
|
||||
use gtk::{
|
||||
gio::Cancellable,
|
||||
@ -47,7 +48,7 @@ impl Request {
|
||||
feature: feature.unwrap_or_default(),
|
||||
referrer: referrer.map(Box::new),
|
||||
uri,
|
||||
}),
|
||||
}), // @TODO validate request len by constructor
|
||||
"titan" => Ok(Self::Titan {
|
||||
referrer: referrer.map(Box::new),
|
||||
uri,
|
||||
@ -105,3 +106,14 @@ impl Request {
|
||||
1 + count
|
||||
}
|
||||
}
|
||||
|
||||
// Tools
|
||||
|
||||
/// Create new search `Request`
|
||||
/// @TODO
|
||||
// * implement DNS lookup before apply this option
|
||||
// * make search provider optional
|
||||
// * validate request len by gemini specifications
|
||||
pub fn search(query: &str) -> Request {
|
||||
Request::from_uri(search::tgls(query), None, None).unwrap() // no handler as unexpected
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
//! Search providers asset
|
||||
|
||||
use gtk::glib::{Uri, UriFlags};
|
||||
|
||||
/// Default search provider
|
||||
pub fn tgls(query: &str) -> Uri {
|
||||
Uri::build(
|
||||
UriFlags::NONE,
|
||||
"gemini",
|
||||
None,
|
||||
Some("tlgs.one"),
|
||||
-1,
|
||||
"/search",
|
||||
Some(&Uri::escape_string(query, None, false)),
|
||||
None,
|
||||
)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user