diff --git a/Cargo.lock b/Cargo.lock index f49f7e4..fb9cf4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2434,6 +2434,7 @@ dependencies = [ "libsqlite3-sys", "log", "lru", + "mime", "nonempty", "once_cell", "opener", diff --git a/Cargo.toml b/Cargo.toml index 08ba6b6..f5d8a1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/routes.rs b/src/routes.rs index 543af1c..4ce0d90 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -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.",