check content type renderability before preload the data

This commit is contained in:
yggverse 2025-06-29 12:20:40 +03:00
parent 67072eb8ea
commit 3bd799af78

View file

@ -142,6 +142,14 @@ impl Nex {
return download(c.upcast::<IOStream>(), (p, uri), cancellable); return download(c.upcast::<IOStream>(), (p, uri), cancellable);
} }
// Navigate to the download gateway on content type is not supported
if !is_renderable(&path) {
p.content
.to_status_mime(&path, Some((&p.item_action, &uri)));
p.set_progress(0.0);
return;
}
// Is renderable types.. // Is renderable types..
// Show loading status page if awaiting time > 1 second // Show loading status page if awaiting time > 1 second
@ -219,12 +227,7 @@ fn render(
) { ) {
use crate::tool::uri_to_title; use crate::tool::uri_to_title;
let q = u.to_string(); let q = u.to_string();
if q.ends_with(".gif") if is_image(&q) {
|| q.ends_with(".jpeg")
|| q.ends_with(".jpg")
|| q.ends_with(".png")
|| q.ends_with(".webp")
{
p.window_action.find.simple_action.set_enabled(false); p.window_action.find.simple_action.set_enabled(false);
Pixbuf::from_stream_async(&m, Some(&c), move |r| match r { Pixbuf::from_stream_async(&m, Some(&c), move |r| match r {
Ok(b) => { Ok(b) => {
@ -235,13 +238,7 @@ fn render(
} }
Err(e) => failure(&p, &e.to_string()), Err(e) => failure(&p, &e.to_string()),
}) })
} else if q.ends_with(".txt") } else if is_text(&q) {
|| q.ends_with(".log")
|| q.ends_with(".gmi")
|| q.ends_with(".gemini")
|| q.ends_with("/")
|| !u.path().contains(".")
{
p.window_action.find.simple_action.set_enabled(true); p.window_action.find.simple_action.set_enabled(true);
match *f { match *f {
Feature::Default | Feature::Source => { Feature::Default | Feature::Source => {
@ -274,9 +271,7 @@ fn render(
Feature::Download => panic!(), // unexpected Feature::Download => panic!(), // unexpected
} }
} else { } else {
p.content panic!() // unexpected
.to_status_mime(&u.path(), Some((&p.item_action, &u)));
p.set_progress(0.0)
} }
} }
@ -342,3 +337,24 @@ fn download(s: IOStream, (p, u): (Rc<Page>, Uri), c: Cancellable) {
} }
}); });
} }
fn is_image(q: &str) -> bool {
q.ends_with(".gif")
|| q.ends_with(".jpeg")
|| q.ends_with(".jpg")
|| q.ends_with(".png")
|| q.ends_with(".webp")
}
fn is_text(q: &str) -> bool {
q.ends_with(".txt")
|| q.ends_with(".log")
|| q.ends_with(".gmi")
|| q.ends_with(".gemini")
|| q.ends_with("/")
|| !q.contains(".")
}
fn is_renderable(q: &str) -> bool {
is_text(q) || is_image(q)
}