forked from neri/datatrash
use html view even if content matches text/html
This commit is contained in:
parent
7f26e7c456
commit
d9c92a2827
|
@ -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",
|
||||||
|
|
|
@ -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"
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue