added content types for cached uploads. weird caching bug still not fixed
This commit is contained in:
parent
9a22170dfa
commit
a4ca431a82
|
@ -107,6 +107,7 @@ dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"hyper",
|
"hyper",
|
||||||
"memory-cache-rs",
|
"memory-cache-rs",
|
||||||
|
"mime_guess",
|
||||||
"rand",
|
"rand",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
|
@ -385,6 +386,16 @@ version = "0.3.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
|
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]]
|
[[package]]
|
||||||
name = "mio"
|
name = "mio"
|
||||||
version = "0.8.5"
|
version = "0.8.5"
|
||||||
|
@ -778,6 +789,15 @@ version = "0.2.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
|
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]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.5"
|
version = "1.0.5"
|
||||||
|
|
|
@ -14,4 +14,5 @@ tokio-stream = "0.1"
|
||||||
tower = "0.4.13"
|
tower = "0.4.13"
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
mime_guess = "2.0.4"
|
||||||
memory-cache-rs = "0.2.0"
|
memory-cache-rs = "0.2.0"
|
||||||
|
|
|
@ -139,6 +139,8 @@ pub async fn new(
|
||||||
println!("[upl] caching upload!!");
|
println!("[upl] caching upload!!");
|
||||||
cache.insert(name, data.freeze(), Some(Duration::from_secs(120)));
|
cache.insert(name, data.freeze(), Some(Duration::from_secs(120)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop(cache);
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(url)
|
Ok(url)
|
||||||
|
|
16
src/view.rs
16
src/view.rs
|
@ -7,10 +7,11 @@ use std::{
|
||||||
use axum::{
|
use axum::{
|
||||||
body::StreamBody,
|
body::StreamBody,
|
||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
response::{IntoResponse, Response}, debug_handler,
|
response::{IntoResponse, Response}, debug_handler, http::HeaderValue,
|
||||||
};
|
};
|
||||||
use bytes::{buf::Reader, Bytes};
|
use bytes::{buf::Reader, Bytes};
|
||||||
use hyper::StatusCode;
|
use hyper::StatusCode;
|
||||||
|
use mime_guess::{mime, Mime};
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
use tokio_util::io::ReaderStream;
|
use tokio_util::io::ReaderStream;
|
||||||
|
|
||||||
|
@ -76,7 +77,18 @@ pub async fn view(
|
||||||
|
|
||||||
let data = cache_item.unwrap().clone();
|
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(
|
/* pub async fn view(
|
||||||
|
|
Loading…
Reference in New Issue