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]]
name = "datatrash"
version = "1.1.0"
version = "1.1.1"
dependencies = [
"actix-files",
"actix-multipart",

View File

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

View File

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