added content types for cached uploads. weird caching bug still not fixed

This commit is contained in:
minish 2023-01-02 18:04:13 -05:00 committed by minish
parent 9a22170dfa
commit a4ca431a82
4 changed files with 37 additions and 2 deletions

20
Cargo.lock generated
View File

@ -107,6 +107,7 @@ dependencies = [
"bytes",
"hyper",
"memory-cache-rs",
"mime_guess",
"rand",
"tokio",
"tokio-stream",
@ -385,6 +386,16 @@ version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
]
[[package]]
name = "mio"
version = "0.8.5"
@ -778,6 +789,15 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]]
name = "unicode-ident"
version = "1.0.5"

View File

@ -14,4 +14,5 @@ tokio-stream = "0.1"
tower = "0.4.13"
bytes = "1"
rand = "0.8.5"
mime_guess = "2.0.4"
memory-cache-rs = "0.2.0"

View File

@ -139,6 +139,8 @@ pub async fn new(
println!("[upl] caching upload!!");
cache.insert(name, data.freeze(), Some(Duration::from_secs(120)));
}
drop(cache);
});
Ok(url)

View File

@ -7,10 +7,11 @@ use std::{
use axum::{
body::StreamBody,
extract::{Path, State},
response::{IntoResponse, Response}, debug_handler,
response::{IntoResponse, Response}, debug_handler, http::HeaderValue,
};
use bytes::{buf::Reader, Bytes};
use hyper::StatusCode;
use mime_guess::{mime, Mime};
use tokio::fs::File;
use tokio_util::io::ReaderStream;
@ -76,7 +77,18 @@ pub async fn view(
let data = cache_item.unwrap().clone();
return data.into_response();
drop(cache);
let contentType = mime_guess::from_path(name).first().unwrap_or(mime::APPLICATION_OCTET_STREAM).to_string();
let mut res = data.into_response();
let mut headers = res.headers_mut();
headers.clear();
headers.insert("content-type", HeaderValue::from(contentType));
return res;
}
/* pub async fn view(