improve mime & content-disposition for thumbnails
parent
5f8182e9b7
commit
aa67b93e4e
|
@ -2434,6 +2434,7 @@ dependencies = [
|
||||||
"libsqlite3-sys",
|
"libsqlite3-sys",
|
||||||
"log",
|
"log",
|
||||||
"lru",
|
"lru",
|
||||||
|
"mime",
|
||||||
"nonempty",
|
"nonempty",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"opener",
|
"opener",
|
||||||
|
|
|
@ -50,6 +50,7 @@ unsigned-varint = { version = "^0", features = ["std"] }
|
||||||
uuid = { version = "0.8", features = ["v4"] }
|
uuid = { version = "0.8", features = ["v4"] }
|
||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
|
|
||||||
|
mime = "^0.3.16"
|
||||||
tree_magic_mini = "3.0.2"
|
tree_magic_mini = "3.0.2"
|
||||||
|
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
|
|
|
@ -323,7 +323,14 @@ pub async fn get_thumbnail(
|
||||||
let thumbnail_path = thumbnail_store
|
let thumbnail_path = thumbnail_store
|
||||||
.get(hash)
|
.get(hash)
|
||||||
.map_err(error::ErrorInternalServerError)?;
|
.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 {
|
} else {
|
||||||
Err(ErrorBadRequest(
|
Err(ErrorBadRequest(
|
||||||
"Address does not refer to a thumbnailable object.",
|
"Address does not refer to a thumbnailable object.",
|
||||||
|
|
Loading…
Reference in New Issue