use html view even if content matches text/html

This commit is contained in:
neri 2022-04-23 23:40:35 +02:00
parent 7f26e7c456
commit d9c92a2827
3 changed files with 9 additions and 9 deletions

2
Cargo.lock generated
View File

@ -434,7 +434,7 @@ dependencies = [
[[package]] [[package]]
name = "datatrash" name = "datatrash"
version = "1.1.0" version = "1.1.1"
dependencies = [ dependencies = [
"actix-files", "actix-files",
"actix-multipart", "actix-multipart",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "datatrash" name = "datatrash"
version = "1.1.0" version = "1.1.1"
authors = ["neri"] authors = ["neri"]
edition = "2021" edition = "2021"

View File

@ -91,6 +91,9 @@ async fn get_view_type(
if delete_on_download || req.query_string().contains("dl") { if delete_on_download || req.query_string().contains("dl") {
return ViewType::Download; return ViewType::Download;
} }
if req.query_string().contains("raw") {
return ViewType::Raw;
}
let is_text = let is_text =
FileKind::from_str(file_kind) == Ok(FileKind::Text) || file_mime.type_() == mime::TEXT; FileKind::from_str(file_kind) == Ok(FileKind::Text) || file_mime.type_() == mime::TEXT;
if !is_text { if !is_text {
@ -101,18 +104,15 @@ async fn get_view_type(
} }
if let Ok(accept) = Accept::parse(req) { if let Ok(accept) = Accept::parse(req) {
for accept_mime in accept.ranked() { for accept_mime in accept.ranked() {
if mime_matches(&accept_mime, file_mime) {
return ViewType::Raw;
}
if accept_mime == TEXT_HTML { if accept_mime == TEXT_HTML {
return ViewType::Html;
}
if mime_matches(&accept_mime, file_mime) {
break; break;
} }
} }
} else {
return ViewType::Raw;
} }
ViewType::Raw
ViewType::Html
} }
fn mime_matches(accept: &Mime, content: &Mime) -> bool { fn mime_matches(accept: &Mime, content: &Mime) -> bool {