mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-24 18:14:14 +00:00
rename mod to Request
, reorganize feature
logic
This commit is contained in:
parent
e5e3f9956a
commit
cfaa0152d6
@ -1,9 +1,9 @@
|
||||
mod protocol;
|
||||
mod feature;
|
||||
mod redirect;
|
||||
mod status;
|
||||
|
||||
// Children dependencies
|
||||
use protocol::Protocol;
|
||||
use feature::Feature;
|
||||
use redirect::Redirect;
|
||||
use status::Status;
|
||||
|
||||
@ -88,9 +88,10 @@ impl Client {
|
||||
}
|
||||
|
||||
// Route request by protocol
|
||||
match Protocol::from_string(query) {
|
||||
Protocol::Gemini { uri } | Protocol::Titan { uri } => todo!("{uri}"),
|
||||
Protocol::Undefined => todo!(),
|
||||
match Feature::from_string(query) {
|
||||
Feature::Default { request }
|
||||
| Feature::Download { request }
|
||||
| Feature::Source { request } => request.send(), // @TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,17 @@
|
||||
mod request;
|
||||
|
||||
// Local dependencies
|
||||
use request::Request;
|
||||
|
||||
/// Special features enumeration
|
||||
/// * may not be available for some protocols
|
||||
pub enum Feature {
|
||||
/// Common feature for protocol selected (e.g. browser view)
|
||||
Default { request: String },
|
||||
Default { request: Request },
|
||||
/// Download request with externally selected method (e.g. to file)
|
||||
Download { request: String },
|
||||
Download { request: Request },
|
||||
/// View request as the source (like `source-view`)
|
||||
Source { request: String },
|
||||
Source { request: Request },
|
||||
}
|
||||
|
||||
impl Feature {
|
||||
@ -17,18 +22,18 @@ impl Feature {
|
||||
pub fn from_string(request: &str) -> Self {
|
||||
if let Some(postfix) = request.strip_prefix("download:") {
|
||||
return Self::Download {
|
||||
request: postfix.to_string(),
|
||||
request: Request::from_string(postfix),
|
||||
};
|
||||
}
|
||||
|
||||
if let Some(postfix) = request.strip_prefix("source:") {
|
||||
return Self::Source {
|
||||
request: postfix.to_string(),
|
||||
request: Request::from_string(postfix),
|
||||
};
|
||||
}
|
||||
|
||||
Self::Default {
|
||||
request: request.to_string(),
|
||||
request: Request::from_string(request),
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
mod uri;
|
||||
|
||||
// Global dependencies
|
||||
use gtk::glib::{Uri, UriFlags};
|
||||
|
||||
pub enum Request {
|
||||
Gemini { uri: Uri },
|
||||
Titan { uri: Uri },
|
||||
Undefined,
|
||||
}
|
||||
|
||||
impl Request {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self` from parsable request string
|
||||
pub fn from_string(request: &str) -> Self {
|
||||
match Uri::parse(request, UriFlags::NONE) {
|
||||
Ok(uri) => match uri.scheme().as_str() {
|
||||
"gemini" => Self::Gemini { uri },
|
||||
"titan" => Self::Titan { uri },
|
||||
_ => Self::Undefined,
|
||||
},
|
||||
// Search request if the request could not be parsed as the valid [URI](https://docs.gtk.org/glib/struct.Uri.html)
|
||||
// * @TODO implement DNS resolver lookup before assign this option
|
||||
Err(_) => Self::Gemini {
|
||||
uri: uri::tgls(request),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Send request using protocol driver constructed
|
||||
pub fn send(&self) {
|
||||
match self {
|
||||
Request::Gemini { uri } => todo!("{uri}"),
|
||||
Request::Titan { uri } => todo!("{uri}"),
|
||||
Request::Undefined => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
use gtk::glib::{Uri, UriFlags};
|
||||
|
||||
/// Build TGLS [Uri](https://docs.gtk.org/glib/struct.Uri.html)
|
||||
pub fn tgls(request: &str) -> Uri {
|
||||
pub fn tgls(query: &str) -> Uri {
|
||||
Uri::build(
|
||||
UriFlags::NONE,
|
||||
"gemini",
|
||||
@ -12,7 +12,7 @@ pub fn tgls(request: &str) -> Uri {
|
||||
Some("tlgs.one"),
|
||||
1965,
|
||||
"search",
|
||||
Some(&Uri::escape_string(request, None, false)), // @TODO is `escape_string` really wanted in `build` context?
|
||||
Some(&Uri::escape_string(query, None, false)), // @TODO is `escape_string` really wanted in `build` context?
|
||||
None,
|
||||
)
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
mod feature;
|
||||
mod uri;
|
||||
|
||||
use feature::Feature;
|
||||
|
||||
use gtk::glib::{Uri, UriFlags};
|
||||
|
||||
pub enum Protocol {
|
||||
Gemini { /*feature: Feature,*/ uri: Uri },
|
||||
Titan { /*feature: Feature,*/ uri: Uri },
|
||||
Undefined,
|
||||
}
|
||||
|
||||
impl Protocol {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self` from parsable request string
|
||||
pub fn from_string(request: &str) -> Self {
|
||||
match Feature::from_string(request) {
|
||||
Feature::Default { request }
|
||||
| Feature::Download { request }
|
||||
| Feature::Source { request } => match Uri::parse(&request, UriFlags::NONE) {
|
||||
Ok(uri) => match uri.scheme().as_str() {
|
||||
"gemini" => Self::Gemini { uri },
|
||||
"titan" => Self::Titan { uri },
|
||||
_ => Self::Undefined,
|
||||
},
|
||||
Err(_) => Self::Gemini {
|
||||
uri: uri::tgls(&request),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user