mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
begin ggemini 0.18 features integration, collect header data in page info holder
This commit is contained in:
parent
2275802eae
commit
f7b2bbc432
2 changed files with 172 additions and 160 deletions
|
|
@ -31,7 +31,7 @@ version = "0.9.1"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ansi-parser = "0.9.1"
|
ansi-parser = "0.9.1"
|
||||||
anyhow = "1.0.97"
|
anyhow = "1.0.97"
|
||||||
ggemini = "0.17.3"
|
ggemini = "0.18.0"
|
||||||
ggemtext = "0.6.0"
|
ggemtext = "0.6.0"
|
||||||
indexmap = "2.7.0"
|
indexmap = "2.7.0"
|
||||||
itertools = "0.14.0"
|
itertools = "0.14.0"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use super::{Feature, Page};
|
use super::{Feature, Page};
|
||||||
use ggemini::client::connection::response::{
|
use ggemini::client::connection::response::{
|
||||||
Certificate, Failure, Input, Redirect,
|
Certificate, Failure, Input, Redirect, Success,
|
||||||
failure::{Permanent, Temporary},
|
failure::{Permanent, Temporary},
|
||||||
};
|
};
|
||||||
use ggemini::{
|
use ggemini::{
|
||||||
|
|
@ -98,10 +98,13 @@ impl Gemini {
|
||||||
cancellable: Cancellable,
|
cancellable: Cancellable,
|
||||||
is_snap_history: bool,
|
is_snap_history: bool,
|
||||||
) {
|
) {
|
||||||
use ggemini::client::connection::Request;
|
use ggemini::client::connection::request::{Mode, Request};
|
||||||
match uri.scheme().as_str() {
|
match uri.scheme().as_str() {
|
||||||
"gemini" => handle(
|
"gemini" => handle(
|
||||||
Request::Gemini { uri },
|
Request::Gemini {
|
||||||
|
uri,
|
||||||
|
mode: Mode::Header,
|
||||||
|
},
|
||||||
(
|
(
|
||||||
self.client.clone(),
|
self.client.clone(),
|
||||||
self.page.clone(),
|
self.page.clone(),
|
||||||
|
|
@ -124,6 +127,7 @@ impl Gemini {
|
||||||
data: bytes,
|
data: bytes,
|
||||||
mime: header.mime.map(|mime| mime.into()),
|
mime: header.mime.map(|mime| mime.into()),
|
||||||
token: header.token.map(|token| token.into()),
|
token: header.token.map(|token| token.into()),
|
||||||
|
mode: Mode::Header,
|
||||||
},
|
},
|
||||||
(
|
(
|
||||||
client.clone(),
|
client.clone(),
|
||||||
|
|
@ -301,7 +305,9 @@ fn handle(
|
||||||
}
|
}
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
},
|
},
|
||||||
_ => match success.mime() {
|
_ => match success {
|
||||||
|
Success::Default(default) => match default.header.mime() {
|
||||||
|
Ok(mime) => match mime.as_str() {
|
||||||
"text/gemini" | "text/plain" => memory_input_stream::from_stream_async(
|
"text/gemini" | "text/plain" => memory_input_stream::from_stream_async(
|
||||||
connection.stream(),
|
connection.stream(),
|
||||||
Priority::DEFAULT,
|
Priority::DEFAULT,
|
||||||
|
|
@ -317,18 +323,20 @@ fn handle(
|
||||||
vec![0; total],
|
vec![0; total],
|
||||||
Priority::DEFAULT,
|
Priority::DEFAULT,
|
||||||
Some(&cancellable),
|
Some(&cancellable),
|
||||||
|
{
|
||||||
|
let m = mime.clone();
|
||||||
move |result| match result {
|
move |result| match result {
|
||||||
Ok((buffer, _ ,_)) => match std::str::from_utf8(&buffer) {
|
Ok((buffer, _ ,_)) => match std::str::from_utf8(&buffer) {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
let mut i = page.navigation.request.info.borrow_mut();
|
let mut i = page.navigation.request.info.borrow_mut();
|
||||||
i
|
i
|
||||||
.add_event("Parsing".to_string())
|
.add_event("Parsing".to_string())
|
||||||
.set_mime(Some(success.mime().to_string()))
|
.set_mime(Some(mime))
|
||||||
.set_size(None, Some(data.len()));
|
.set_size(Some(default.header.len()), Some(data.len()));
|
||||||
let w = if matches!(*feature, Feature::Source) {
|
let w = if matches!(*feature, Feature::Source) {
|
||||||
page.content.to_text_source(data)
|
page.content.to_text_source(data)
|
||||||
} else {
|
} else {
|
||||||
match success.mime() {
|
match m.as_str() {
|
||||||
"text/gemini" => page.content.to_text_gemini(&uri, data),
|
"text/gemini" => page.content.to_text_gemini(&uri, data),
|
||||||
"text/plain" => page.content.to_text_plain(data),
|
"text/plain" => page.content.to_text_plain(data),
|
||||||
_ => panic!() // unexpected
|
_ => panic!() // unexpected
|
||||||
|
|
@ -378,6 +386,7 @@ fn handle(
|
||||||
update_page_info(&page, EVENT_COMPLETED);
|
update_page_info(&page, EVENT_COMPLETED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
),
|
),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let s = page.content.to_status_failure();
|
let s = page.content.to_status_failure();
|
||||||
|
|
@ -427,7 +436,7 @@ fn handle(
|
||||||
let mut i = page.navigation.request.info.borrow_mut();
|
let mut i = page.navigation.request.info.borrow_mut();
|
||||||
i
|
i
|
||||||
.add_event(EVENT_COMPLETED.to_string())
|
.add_event(EVENT_COMPLETED.to_string())
|
||||||
.set_mime(Some(success.mime().to_string()))
|
.set_mime(Some(mime))
|
||||||
.set_size(None, Some(buffer.byte_length()))
|
.set_size(None, Some(buffer.byte_length()))
|
||||||
.commit();
|
.commit();
|
||||||
page.navigation.request.update_secondary_icon(&i)
|
page.navigation.request.update_secondary_icon(&i)
|
||||||
|
|
@ -482,6 +491,9 @@ fn handle(
|
||||||
.commit();
|
.commit();
|
||||||
page.navigation.request.update_secondary_icon(&i)
|
page.navigation.request.update_secondary_icon(&i)
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
Err(_) => todo!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-30-temporary-redirection
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-30-temporary-redirection
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue