mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
update ggemini api to v0.15.0 / checkout repository version
This commit is contained in:
parent
eb6f8bac91
commit
fdeb16e4b1
2 changed files with 204 additions and 208 deletions
|
|
@ -30,7 +30,7 @@ version = "0.9.1"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ansi-parser = "0.9.1"
|
ansi-parser = "0.9.1"
|
||||||
ggemini = "0.14.0"
|
ggemini = "0.15.0"
|
||||||
ggemtext = "0.3.0"
|
ggemtext = "0.3.0"
|
||||||
indexmap = "2.7.0"
|
indexmap = "2.7.0"
|
||||||
itertools = "0.14.0"
|
itertools = "0.14.0"
|
||||||
|
|
@ -40,7 +40,7 @@ plurify = "0.2.0"
|
||||||
syntect = "5.2.0"
|
syntect = "5.2.0"
|
||||||
|
|
||||||
# development
|
# development
|
||||||
# [patch.crates-io]
|
[patch.crates-io]
|
||||||
# ggemini = { git = "https://github.com/YGGverse/ggemini.git" }
|
ggemini = { git = "https://github.com/YGGverse/ggemini.git" }
|
||||||
# ggemtext = { git = "https://github.com/YGGverse/ggemtext.git" }
|
# ggemtext = { git = "https://github.com/YGGverse/ggemtext.git" }
|
||||||
# plurify = { git = "https://github.com/YGGverse/plurify.git" }
|
# plurify = { git = "https://github.com/YGGverse/plurify.git" }
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
use super::{Feature, Page};
|
use super::{Feature, Page};
|
||||||
use ggemini::client::{
|
use ggemini::client::connection::response::{
|
||||||
connection::response::{data::Text, meta::Status},
|
failure::{Permanent, Temporary},
|
||||||
Client, Request,
|
Certificate, Failure, Input, Redirect, Success,
|
||||||
};
|
};
|
||||||
|
use ggemini::client::{connection::response::data::Text, Client, Request, Response};
|
||||||
use gtk::glib::Bytes;
|
use gtk::glib::Bytes;
|
||||||
use gtk::glib::{GString, UriFlags};
|
use gtk::glib::{GString, UriFlags};
|
||||||
use gtk::{
|
use gtk::{
|
||||||
|
|
@ -137,35 +138,33 @@ fn handle(
|
||||||
let page = page.clone();
|
let page = page.clone();
|
||||||
let redirects = redirects.clone();
|
let redirects = redirects.clone();
|
||||||
move |result| match result {
|
move |result| match result {
|
||||||
Ok(response) => {
|
Ok((response, connection)) => match response {
|
||||||
match response.meta.status {
|
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#input-expected
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#input-expected
|
||||||
Status::Input | Status::SensitiveInput => {
|
Response::Input(input) => {
|
||||||
let title = match response.meta.data {
|
let title = input.to_string();
|
||||||
Some(data) => data.to_string(),
|
|
||||||
None => Status::Input.to_string(),
|
|
||||||
};
|
|
||||||
if matches!(response.meta.status, Status::SensitiveInput) {
|
|
||||||
page.input.set_new_sensitive(
|
|
||||||
page.item_action.clone(),
|
|
||||||
uri,
|
|
||||||
Some(&title),
|
|
||||||
Some(1024),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
page.input.set_new_response(
|
|
||||||
page.item_action.clone(),
|
|
||||||
uri,
|
|
||||||
Some(&title),
|
|
||||||
Some(1024),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&title);
|
page.set_title(&title);
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
match input {
|
||||||
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-10
|
||||||
|
Input::Default { message } => page.input.set_new_response(
|
||||||
|
page.item_action.clone(),
|
||||||
|
uri,
|
||||||
|
Some(message.as_ref().unwrap_or(&title)),
|
||||||
|
Some(1024),
|
||||||
|
),
|
||||||
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-11-sensitive-input
|
||||||
|
Input::Sensitive { message } => page.input.set_new_sensitive(
|
||||||
|
page.item_action.clone(),
|
||||||
|
uri,
|
||||||
|
Some(message.as_ref().unwrap_or(&title)),
|
||||||
|
Some(1024),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-20
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-20
|
||||||
Status::Success => match *feature {
|
Response::Success(success) => match success {
|
||||||
|
Success::Default { mime } => match *feature {
|
||||||
Feature::Download => {
|
Feature::Download => {
|
||||||
// Init download widget
|
// Init download widget
|
||||||
let status = page.content.to_status_download(
|
let status = page.content.to_status_download(
|
||||||
|
|
@ -174,7 +173,7 @@ fn handle(
|
||||||
&cancellable,
|
&cancellable,
|
||||||
{
|
{
|
||||||
let cancellable = cancellable.clone();
|
let cancellable = cancellable.clone();
|
||||||
let stream = response.connection.stream();
|
let stream = connection.stream();
|
||||||
move |file, action| {
|
move |file, action| {
|
||||||
match file.replace(
|
match file.replace(
|
||||||
None,
|
None,
|
||||||
|
|
@ -233,10 +232,9 @@ fn handle(
|
||||||
page.set_title(&status.title());
|
page.set_title(&status.title());
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
},
|
},
|
||||||
_ => match response.meta.mime {
|
_ => match mime.as_str() {
|
||||||
Some(mime) => match mime.as_str() {
|
|
||||||
"text/gemini" => Text::from_stream_async(
|
"text/gemini" => Text::from_stream_async(
|
||||||
response.connection.stream(),
|
connection.stream(),
|
||||||
Priority::DEFAULT,
|
Priority::DEFAULT,
|
||||||
cancellable.clone(),
|
cancellable.clone(),
|
||||||
move |result| match result {
|
move |result| match result {
|
||||||
|
|
@ -278,7 +276,7 @@ fn handle(
|
||||||
// show bytes count in loading widget, validate max size for incoming data
|
// show bytes count in loading widget, validate max size for incoming data
|
||||||
// * no dependency of Gemini library here, feel free to use any other `IOStream` processor
|
// * no dependency of Gemini library here, feel free to use any other `IOStream` processor
|
||||||
ggemini::gio::memory_input_stream::from_stream_async(
|
ggemini::gio::memory_input_stream::from_stream_async(
|
||||||
response.connection.stream(),
|
connection.stream(),
|
||||||
cancellable.clone(),
|
cancellable.clone(),
|
||||||
Priority::DEFAULT,
|
Priority::DEFAULT,
|
||||||
0x400, // 1024 bytes per chunk, optional step for images download tracking
|
0x400, // 1024 bytes per chunk, optional step for images download tracking
|
||||||
|
|
@ -329,22 +327,14 @@ fn handle(
|
||||||
page.set_title(&status.title());
|
page.set_title(&status.title());
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
None => {
|
|
||||||
let status = page.content.to_status_failure();
|
|
||||||
status.set_description(Some("MIME type not found"));
|
|
||||||
page.set_progress(0.0);
|
|
||||||
page.set_title(&status.title());
|
|
||||||
redirects.replace(0); // reset
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Response::Redirect(redirect) => match &redirect {
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-30-temporary-redirection
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-30-temporary-redirection
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-31-permanent-redirection
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-31-permanent-redirection
|
||||||
Status::PermanentRedirect | Status::Redirect => {
|
Redirect::Temporary { target } |
|
||||||
// Expected target URL in response meta
|
Redirect::Permanent { target } => match redirection_base(uri).parse_relative(target, UriFlags::NONE) {
|
||||||
match response.meta.data {
|
|
||||||
Some(data) => match redirection_base(uri).parse_relative(data.as_str(), UriFlags::NONE) {
|
|
||||||
Ok(target) => {
|
Ok(target) => {
|
||||||
// Increase client redirection counter
|
// Increase client redirection counter
|
||||||
let total = redirects.take() + 1;
|
let total = redirects.take() + 1;
|
||||||
|
|
@ -369,7 +359,7 @@ fn handle(
|
||||||
*/
|
*/
|
||||||
// Valid
|
// Valid
|
||||||
} else {
|
} else {
|
||||||
if matches!(response.meta.status, Status::PermanentRedirect) {
|
if matches!(redirect, Redirect::Permanent { .. }) {
|
||||||
page.navigation.set_request(&target.to_string());
|
page.navigation.set_request(&target.to_string());
|
||||||
}
|
}
|
||||||
redirects.replace(total);
|
redirects.replace(total);
|
||||||
|
|
@ -384,48 +374,54 @@ fn handle(
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
|
||||||
let status = page.content.to_status_failure();
|
|
||||||
status.set_description(Some("Redirection target not found"));
|
|
||||||
page.set_progress(0.0);
|
|
||||||
page.set_title(&status.title());
|
|
||||||
redirects.replace(0); // reset
|
|
||||||
}
|
}
|
||||||
}
|
Response::Certificate(ref certificate) => match certificate {
|
||||||
},
|
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-60
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-60
|
||||||
Status::CertificateRequest |
|
Certificate::Required { message } |
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-61-certificate-not-authorized
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-61-certificate-not-authorized
|
||||||
Status::CertificateUnauthorized |
|
Certificate::NotAuthorized { message } |
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-62-certificate-not-valid
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-62-certificate-not-valid
|
||||||
Status::CertificateInvalid => {
|
Certificate::NotValid { message } => {
|
||||||
let status = page.content.to_status_identity();
|
let status = page.content.to_status_identity();
|
||||||
status.set_description(Some(&match response.meta.data {
|
status.set_description(Some(message.as_ref().unwrap_or(&certificate.to_string())));
|
||||||
Some(data) => data.to_string(),
|
|
||||||
None => response.meta.status.to_string(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&status.title());
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
}
|
}
|
||||||
error => {
|
}
|
||||||
|
Response::Failure(failure) => match failure {
|
||||||
|
Failure::Temporary(ref temporary) => match temporary {
|
||||||
|
Temporary::CgiError { message } |
|
||||||
|
Temporary::Default { message } |
|
||||||
|
Temporary::ProxyError { message } |
|
||||||
|
Temporary::ServerUnavailable { message } |
|
||||||
|
Temporary::SlowDown { message } => {
|
||||||
let status = page.content.to_status_failure();
|
let status = page.content.to_status_failure();
|
||||||
|
status.set_description(Some(message.as_ref().unwrap_or(&temporary.to_string())));
|
||||||
status.set_description(
|
|
||||||
Some(&match response.meta.data {
|
|
||||||
Some(message) => message.to_string(),
|
|
||||||
None => error.to_string()
|
|
||||||
})
|
|
||||||
);
|
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(&status.title());
|
page.set_title(&status.title());
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
|
||||||
if let Some(callback) = on_failure {
|
if let Some(callback) = on_failure {
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
Failure::Permanent(ref permanent) => match permanent {
|
||||||
|
Permanent::BadRequest { message } |
|
||||||
|
Permanent::Default { message } |
|
||||||
|
Permanent::Gone { message } |
|
||||||
|
Permanent::NotFound { message } |
|
||||||
|
Permanent::ProxyRequestRefused { message } => {
|
||||||
|
let status = page.content.to_status_failure();
|
||||||
|
status.set_description(Some(message.as_ref().unwrap_or(&permanent.to_string())));
|
||||||
|
page.set_progress(0.0);
|
||||||
|
page.set_title(&status.title());
|
||||||
|
redirects.replace(0); // reset
|
||||||
|
if let Some(callback) = on_failure {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue