Properly handle Content-Type

This commit is contained in:
Alex Auvolat
2023-05-12 16:11:29 +02:00
parent 20fa2cacf4
commit 24d3b289da
3 changed files with 29 additions and 21 deletions
+6 -4
View File
@@ -269,13 +269,15 @@ pub fn plume_media_files(file: PathBuf) -> Option<CachedFile> {
#[cfg(feature="s3")]
{
let ct = file.extension()
.and_then(|ext| ContentType::from_extension(&ext.to_string_lossy()))
.unwrap_or(ContentType::Binary);
let data = CONFIG.s3.as_ref().unwrap().get_bucket()
.get_object_blocking(format!("static/media/{}", file.to_string_lossy())).ok()?;
let ct = data.headers().get("content-type")
.and_then(|x| ContentType::parse_flexible(&x))
.or_else(|| file.extension()
.and_then(|ext| ContentType::from_extension(&ext.to_string_lossy())))
.unwrap_or(ContentType::Binary);
Some(CachedFile {
inner: FileKind::S3 ( data.to_vec(), ct),
cache_control: CacheControl(vec![CacheDirective::MaxAge(60 * 60 * 24 * 30)]),