mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
update ggemini api version
This commit is contained in:
parent
0ad857f02e
commit
7757bc2283
2 changed files with 64 additions and 51 deletions
|
|
@ -17,7 +17,7 @@ features = ["v1_6"]
|
||||||
|
|
||||||
[dependencies.gemini]
|
[dependencies.gemini]
|
||||||
package = "ggemini"
|
package = "ggemini"
|
||||||
version = "0.5.1"
|
version = "0.6.0"
|
||||||
|
|
||||||
[dependencies.gemtext]
|
[dependencies.gemtext]
|
||||||
package = "ggemtext"
|
package = "ggemtext"
|
||||||
|
|
|
||||||
|
|
@ -364,12 +364,8 @@ impl Page {
|
||||||
|
|
||||||
// Private helpers @TODO
|
// Private helpers @TODO
|
||||||
fn load_gemini(&self, uri: Uri) {
|
fn load_gemini(&self, uri: Uri) {
|
||||||
// Use local namespaces
|
// Use local namespaces @TODO
|
||||||
use gemini::client::response::{
|
// use gemini::client::response::
|
||||||
body::Error as BodyError,
|
|
||||||
header::{Error as HeaderError, Mime as ClientMime, Status as ClientStatus},
|
|
||||||
Body, Header,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Init shared objects (async)
|
// Init shared objects (async)
|
||||||
let action_page_open = self.action_page_open.clone();
|
let action_page_open = self.action_page_open.clone();
|
||||||
|
|
@ -434,32 +430,30 @@ impl Page {
|
||||||
None::<&Cancellable>,
|
None::<&Cancellable>,
|
||||||
move |request| match request {
|
move |request| match request {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Read header from input stream
|
// Read meta from input stream
|
||||||
Header::from_socket_connection_async(
|
gemini::client::response::Meta::from_socket_connection_async(
|
||||||
connection.clone(),
|
connection.clone(),
|
||||||
Some(Priority::DEFAULT),
|
Some(Priority::DEFAULT),
|
||||||
None::<Cancellable>,
|
None::<Cancellable>,
|
||||||
move |result| match result
|
move |result| match result
|
||||||
{
|
{
|
||||||
Ok(header) => {
|
Ok(response) => {
|
||||||
// Route by status
|
// Route by status
|
||||||
match header.status() {
|
match response.status() {
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#input-expected
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#input-expected
|
||||||
ClientStatus::Input | ClientStatus::SensitiveInput => {
|
gemini::client::response::meta::Status::Input |
|
||||||
|
gemini::client::response::meta::Status::SensitiveInput => {
|
||||||
// Format response
|
// Format response
|
||||||
let status = Status::Input;
|
let status = Status::Input;
|
||||||
let title = gformat!("Input expected");
|
let title = gformat!("Input expected");
|
||||||
let description = match header.meta() {
|
let description = match response.data().value() {
|
||||||
Some(meta) => match meta.to_gstring() {
|
Some(value) => value,
|
||||||
Ok(value) => value,
|
None => &title,
|
||||||
Err(_) => title.clone(),
|
|
||||||
},
|
|
||||||
None => title.clone(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Toggle input form variant
|
// Toggle input form variant
|
||||||
match header.status() {
|
match response.status() {
|
||||||
ClientStatus::SensitiveInput =>
|
gemini::client::response::meta::Status::SensitiveInput =>
|
||||||
input.set_new_sensitive(
|
input.set_new_sensitive(
|
||||||
action_page_open,
|
action_page_open,
|
||||||
uri,
|
uri,
|
||||||
|
|
@ -485,12 +479,12 @@ impl Page {
|
||||||
// Update page
|
// Update page
|
||||||
action_update.activate(Some(&id));
|
action_update.activate(Some(&id));
|
||||||
},
|
},
|
||||||
ClientStatus::Success => {
|
gemini::client::response::meta::Status::Success => {
|
||||||
// Route by MIME
|
// Route by MIME
|
||||||
match header.mime() {
|
match response.mime() {
|
||||||
Some(ClientMime::TextGemini) => {
|
gemini::client::response::meta::Mime::TextGemini => {
|
||||||
// Read entire input stream to buffer
|
// Read entire input stream to buffer
|
||||||
Body::from_socket_connection_async(
|
gemini::client::response::Body::from_socket_connection_async(
|
||||||
connection,
|
connection,
|
||||||
move |result|{
|
move |result|{
|
||||||
match result {
|
match result {
|
||||||
|
|
@ -513,12 +507,12 @@ impl Page {
|
||||||
let status = Status::Failure;
|
let status = Status::Failure;
|
||||||
let title = gformat!("Oops");
|
let title = gformat!("Oops");
|
||||||
let description = match reason {
|
let description = match reason {
|
||||||
BodyError::InputStreamRead => match message {
|
gemini::client::response::body::Error::InputStreamRead => match message {
|
||||||
Some(error) => gformat!("{error}"),
|
Some(error) => gformat!("{error}"),
|
||||||
None => gformat!("Undefined connection error")
|
None => gformat!("Undefined connection error")
|
||||||
} ,
|
} ,
|
||||||
BodyError::BufferOverflow => gformat!("Buffer overflow"),
|
gemini::client::response::body::Error::BufferOverflow => gformat!("Buffer overflow"),
|
||||||
BodyError::Decode => gformat!("Buffer decode error"),
|
gemini::client::response::body::Error::Decode => gformat!("Buffer decode error"),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
|
|
@ -541,10 +535,11 @@ impl Page {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Some(
|
gemini::client::response::meta::Mime::ImagePng |
|
||||||
ClientMime::ImagePng | ClientMime::ImageGif |
|
gemini::client::response::meta::Mime::ImageGif |
|
||||||
ClientMime::ImageJpeg | ClientMime::ImageWebp
|
gemini::client::response::meta::Mime::ImageJpeg |
|
||||||
) => {
|
gemini::client::response::meta::Mime::ImageWebp
|
||||||
|
=> {
|
||||||
// Final image size unknown, show loading widget
|
// Final image size unknown, show loading widget
|
||||||
let status = content.set_status_loading(
|
let status = content.set_status_loading(
|
||||||
Some(&"Loading.."),
|
Some(&"Loading.."),
|
||||||
|
|
@ -680,7 +675,8 @@ impl Page {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#redirection
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#redirection
|
||||||
ClientStatus::Redirect | ClientStatus::PermanentRedirect => {
|
gemini::client::response::meta::Status::Redirect |
|
||||||
|
gemini::client::response::meta::Status::PermanentRedirect => {
|
||||||
|
|
||||||
// @TODO ClientStatus::TemporaryRedirect
|
// @TODO ClientStatus::TemporaryRedirect
|
||||||
|
|
||||||
|
|
@ -689,18 +685,11 @@ impl Page {
|
||||||
meta.borrow_mut().title = Some(gformat!("Redirect"));
|
meta.borrow_mut().title = Some(gformat!("Redirect"));
|
||||||
|
|
||||||
// Build gemtext message for manual redirection @TODO use template?
|
// Build gemtext message for manual redirection @TODO use template?
|
||||||
match header.meta() {
|
match response.data().value() {
|
||||||
Some(meta) => {
|
Some(url) => {
|
||||||
let _ = content.set_text_gemini(
|
content.set_text_gemini(
|
||||||
&uri,
|
&uri,
|
||||||
&match meta.to_gstring() {
|
&gformat!("# Redirect\n\nAuto-follow not implemented, click on link below to continue\n\n=> {url}")
|
||||||
Ok(url) => gformat!(
|
|
||||||
"# Redirect\n\nAuto-follow not implemented, click on link below to continue\n\n=> {url}"
|
|
||||||
),
|
|
||||||
Err(_) => gformat!(
|
|
||||||
"# Redirect\n\nProvider request redirect but not provided any target."
|
|
||||||
)
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
|
|
@ -720,26 +709,50 @@ impl Page {
|
||||||
let status = Status::Failure;
|
let status = Status::Failure;
|
||||||
let title = gformat!("Oops");
|
let title = gformat!("Oops");
|
||||||
let description = match reason {
|
let description = match reason {
|
||||||
HeaderError::Buffer => match message {
|
// Common
|
||||||
Some(error) => gformat!("{error}"),
|
gemini::client::response::meta::Error::InputStream => match message {
|
||||||
None => gformat!("Buffer error")
|
|
||||||
},
|
|
||||||
HeaderError::InputStream => match message {
|
|
||||||
Some(error) => gformat!("{error}"),
|
Some(error) => gformat!("{error}"),
|
||||||
None => gformat!("Input stream reading error")
|
None => gformat!("Input stream reading error")
|
||||||
},
|
},
|
||||||
HeaderError::Protocol => match message {
|
gemini::client::response::meta::Error::Protocol => match message {
|
||||||
Some(error) => gformat!("{error}"),
|
Some(error) => gformat!("{error}"),
|
||||||
None => gformat!("Incorrect protocol")
|
None => gformat!("Incorrect protocol")
|
||||||
},
|
},
|
||||||
HeaderError::StatusDecode => match message {
|
// Status
|
||||||
|
gemini::client::response::meta::Error::StatusDecode => match message {
|
||||||
Some(error) => gformat!("{error}"),
|
Some(error) => gformat!("{error}"),
|
||||||
None => gformat!("Could not detect status code")
|
None => gformat!("Could not detect status code")
|
||||||
},
|
},
|
||||||
HeaderError::StatusUndefined => match message {
|
gemini::client::response::meta::Error::StatusUndefined => match message {
|
||||||
Some(error) => gformat!("{error}"),
|
Some(error) => gformat!("{error}"),
|
||||||
None => gformat!("Status code yet not supported")
|
None => gformat!("Status code yet not supported")
|
||||||
},
|
},
|
||||||
|
gemini::client::response::meta::Error::StatusProtocol => match message {
|
||||||
|
Some(error) => gformat!("{error}"),
|
||||||
|
None => gformat!("Incorrect status code protocol")
|
||||||
|
},
|
||||||
|
// Data
|
||||||
|
gemini::client::response::meta::Error::DataDecode => match message {
|
||||||
|
Some(error) => gformat!("{error}"),
|
||||||
|
None => gformat!("Incorrect data encoding")
|
||||||
|
},
|
||||||
|
gemini::client::response::meta::Error::DataProtocol => match message {
|
||||||
|
Some(error) => gformat!("{error}"),
|
||||||
|
None => gformat!("Incorrect data protocol")
|
||||||
|
},
|
||||||
|
// MIME
|
||||||
|
gemini::client::response::meta::Error::MimeDecode => match message {
|
||||||
|
Some(error) => gformat!("{error}"),
|
||||||
|
None => gformat!("Incorrect MIME encoding")
|
||||||
|
},
|
||||||
|
gemini::client::response::meta::Error::MimeProtocol => match message {
|
||||||
|
Some(error) => gformat!("{error}"),
|
||||||
|
None => gformat!("Incorrect MIME protocol")
|
||||||
|
},
|
||||||
|
gemini::client::response::meta::Error::MimeUndefined => match message {
|
||||||
|
Some(error) => gformat!("{error}"),
|
||||||
|
None => gformat!("MIME type yet not supported (by library)")
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue