mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +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]
|
||||
ansi-parser = "0.9.1"
|
||||
ggemini = "0.14.0"
|
||||
ggemini = "0.15.0"
|
||||
ggemtext = "0.3.0"
|
||||
indexmap = "2.7.0"
|
||||
itertools = "0.14.0"
|
||||
|
|
@ -40,7 +40,7 @@ plurify = "0.2.0"
|
|||
syntect = "5.2.0"
|
||||
|
||||
# development
|
||||
# [patch.crates-io]
|
||||
# ggemini = { git = "https://github.com/YGGverse/ggemini.git" }
|
||||
[patch.crates-io]
|
||||
ggemini = { git = "https://github.com/YGGverse/ggemini.git" }
|
||||
# ggemtext = { git = "https://github.com/YGGverse/ggemtext.git" }
|
||||
# plurify = { git = "https://github.com/YGGverse/plurify.git" }
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use super::{Feature, Page};
|
||||
use ggemini::client::{
|
||||
connection::response::{data::Text, meta::Status},
|
||||
Client, Request,
|
||||
use ggemini::client::connection::response::{
|
||||
failure::{Permanent, Temporary},
|
||||
Certificate, Failure, Input, Redirect, Success,
|
||||
};
|
||||
use ggemini::client::{connection::response::data::Text, Client, Request, Response};
|
||||
use gtk::glib::Bytes;
|
||||
use gtk::glib::{GString, UriFlags};
|
||||
use gtk::{
|
||||
|
|
@ -137,35 +138,33 @@ fn handle(
|
|||
let page = page.clone();
|
||||
let redirects = redirects.clone();
|
||||
move |result| match result {
|
||||
Ok(response) => {
|
||||
match response.meta.status {
|
||||
Ok((response, connection)) => match response {
|
||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#input-expected
|
||||
Status::Input | Status::SensitiveInput => {
|
||||
let title = match response.meta.data {
|
||||
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),
|
||||
);
|
||||
}
|
||||
Response::Input(input) => {
|
||||
let title = input.to_string();
|
||||
page.set_progress(0.0);
|
||||
page.set_title(&title);
|
||||
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
|
||||
Status::Success => match *feature {
|
||||
Response::Success(success) => match success {
|
||||
Success::Default { mime } => match *feature {
|
||||
Feature::Download => {
|
||||
// Init download widget
|
||||
let status = page.content.to_status_download(
|
||||
|
|
@ -174,7 +173,7 @@ fn handle(
|
|||
&cancellable,
|
||||
{
|
||||
let cancellable = cancellable.clone();
|
||||
let stream = response.connection.stream();
|
||||
let stream = connection.stream();
|
||||
move |file, action| {
|
||||
match file.replace(
|
||||
None,
|
||||
|
|
@ -233,10 +232,9 @@ fn handle(
|
|||
page.set_title(&status.title());
|
||||
redirects.replace(0); // reset
|
||||
},
|
||||
_ => match response.meta.mime {
|
||||
Some(mime) => match mime.as_str() {
|
||||
_ => match mime.as_str() {
|
||||
"text/gemini" => Text::from_stream_async(
|
||||
response.connection.stream(),
|
||||
connection.stream(),
|
||||
Priority::DEFAULT,
|
||||
cancellable.clone(),
|
||||
move |result| match result {
|
||||
|
|
@ -278,7 +276,7 @@ fn handle(
|
|||
// 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
|
||||
ggemini::gio::memory_input_stream::from_stream_async(
|
||||
response.connection.stream(),
|
||||
connection.stream(),
|
||||
cancellable.clone(),
|
||||
Priority::DEFAULT,
|
||||
0x400, // 1024 bytes per chunk, optional step for images download tracking
|
||||
|
|
@ -329,22 +327,14 @@ fn handle(
|
|||
page.set_title(&status.title());
|
||||
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-31-permanent-redirection
|
||||
Status::PermanentRedirect | Status::Redirect => {
|
||||
// Expected target URL in response meta
|
||||
match response.meta.data {
|
||||
Some(data) => match redirection_base(uri).parse_relative(data.as_str(), UriFlags::NONE) {
|
||||
Redirect::Temporary { target } |
|
||||
Redirect::Permanent { target } => match redirection_base(uri).parse_relative(target, UriFlags::NONE) {
|
||||
Ok(target) => {
|
||||
// Increase client redirection counter
|
||||
let total = redirects.take() + 1;
|
||||
|
|
@ -369,7 +359,7 @@ fn handle(
|
|||
*/
|
||||
// Valid
|
||||
} else {
|
||||
if matches!(response.meta.status, Status::PermanentRedirect) {
|
||||
if matches!(redirect, Redirect::Permanent { .. }) {
|
||||
page.navigation.set_request(&target.to_string());
|
||||
}
|
||||
redirects.replace(total);
|
||||
|
|
@ -384,48 +374,54 @@ fn handle(
|
|||
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
|
||||
Status::CertificateRequest |
|
||||
Certificate::Required { message } |
|
||||
// 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
|
||||
Status::CertificateInvalid => {
|
||||
Certificate::NotValid { message } => {
|
||||
let status = page.content.to_status_identity();
|
||||
status.set_description(Some(&match response.meta.data {
|
||||
Some(data) => data.to_string(),
|
||||
None => response.meta.status.to_string(),
|
||||
}));
|
||||
|
||||
status.set_description(Some(message.as_ref().unwrap_or(&certificate.to_string())));
|
||||
page.set_progress(0.0);
|
||||
page.set_title(&status.title());
|
||||
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();
|
||||
|
||||
status.set_description(
|
||||
Some(&match response.meta.data {
|
||||
Some(message) => message.to_string(),
|
||||
None => error.to_string()
|
||||
})
|
||||
);
|
||||
status.set_description(Some(message.as_ref().unwrap_or(&temporary.to_string())));
|
||||
page.set_progress(0.0);
|
||||
page.set_title(&status.title());
|
||||
redirects.replace(0); // reset
|
||||
|
||||
if let Some(callback) = on_failure {
|
||||
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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue