improve mime & content-disposition for thumbnails

feat/vaults
Tomáš Mládek 2021-12-26 17:40:47 +01:00
parent 5f8182e9b7
commit aa67b93e4e
No known key found for this signature in database
GPG Key ID: ED21612889E75EC5
3 changed files with 10 additions and 1 deletions

1
Cargo.lock generated
View File

@ -2434,6 +2434,7 @@ dependencies = [
"libsqlite3-sys",
"log",
"lru",
"mime",
"nonempty",
"once_cell",
"opener",

View File

@ -50,6 +50,7 @@ unsigned-varint = { version = "^0", features = ["std"] }
uuid = { version = "0.8", features = ["v4"] }
walkdir = "2"
mime = "^0.3.16"
tree_magic_mini = "3.0.2"
dotenv = "0.15.0"

View File

@ -323,7 +323,14 @@ pub async fn get_thumbnail(
let thumbnail_path = thumbnail_store
.get(hash)
.map_err(error::ErrorInternalServerError)?;
Ok(NamedFile::open(thumbnail_path)?)
let mut file = NamedFile::open(&thumbnail_path)?.disable_content_disposition();
if let Some(mime_type) = tree_magic_mini::from_filepath(&thumbnail_path) {
if let Ok(mime) = mime_type.parse() {
file = file.set_content_type(mime);
}
}
Ok(file)
} else {
Err(ErrorBadRequest(
"Address does not refer to a thumbnailable object.",