draft route by status code and content type

This commit is contained in:
yggverse 2024-09-26 02:17:19 +03:00
parent cb270e9f45
commit 60574ae449

View File

@ -135,27 +135,54 @@ impl Page {
response.0, response.0,
) { ) {
Ok(data) => { Ok(data) => {
// Update // Format response
meta.borrow_mut().title = meta.borrow_mut().title = GString::from("Done"); // @TODO
GString::from("Done"); // @TODO meta.borrow_mut().progress_fraction = 1.0;
meta.borrow_mut()
.progress_fraction = 1.0;
let _ = widget.activate_action( // Parse response @TODO read bytes
"win.update", let parts = Regex::split_simple(
None, r"^(\d+)?\s([\w]+\/[\w]+)?(.*)?",
);
// Detect page meta
let meta = Regex::split_simple(
r"^(\d+)?\s([\w]+\/[\w]+)?",
&data, &data,
RegexCompileFlags::DEFAULT, RegexCompileFlags::DEFAULT,
RegexMatchFlags::DEFAULT, RegexMatchFlags::DEFAULT,
); );
//println!("{:?}", meta); // https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes
//println!("Result: {}", data); match parts.get(1) {
Some(code) => match code.as_str() {
"20" => {
match parts.get(2) {
Some(mime) => match mime.as_str() {
"text/gemini" => {
meta.borrow_mut().mime = Mime::TextGemini;
// @TODO
},
"text/plain" => {
meta.borrow_mut().mime = Mime::TextPlain;
// @TODO
},
_ => {
meta.borrow_mut().title = GString::from("Oops");
meta.borrow_mut().description = GString::from(format!("Content {mime} not supported"));
},
}
None => todo!(),
};
// @TODO
},
_ => {
meta.borrow_mut().title = GString::from("Oops");
meta.borrow_mut().description = GString::from(format!("Status {code} not supported"));
},
}
None => todo!(),
};
// Update
let _ = widget.activate_action(
"win.update",
None,
);
} }
Err(e) => { Err(e) => {
eprintln!( eprintln!(