fix hardcoded link

This commit is contained in:
blek 2023-10-11 23:34:19 +10:00
parent 92b8ebffb3
commit ff66e120b9
Signed by: blek
GPG Key ID: 14546221E3595D0C
4 changed files with 10 additions and 2 deletions

View File

@ -33,6 +33,7 @@ impl FileManager {
Ok(Some(serde_json::from_str(data.as_str())?)) Ok(Some(serde_json::from_str(data.as_str())?))
} }
pub fn find_by_name(self: &Self, name: String) -> Result<Option<File>, Box<dyn Error>> { pub fn find_by_name(self: &Self, name: String) -> Result<Option<File>, Box<dyn Error>> {
println!("{}-name-{}", self.env.redis.prefix, name);
Ok(self.find(format!("{}-name-{}", self.env.redis.prefix, name))?) Ok(self.find(format!("{}-name-{}", self.env.redis.prefix, name))?)
} }
pub fn find_by_hash(self: &Self, hash: String) -> Result<Option<File>, Box<dyn Error>> { pub fn find_by_hash(self: &Self, hash: String) -> Result<Option<File>, Box<dyn Error>> {

View File

@ -29,6 +29,13 @@ impl File {
pub fn hash(self: &Self) -> String { pub fn hash(self: &Self) -> String {
self.sha512.clone() self.sha512.clone()
} }
pub fn leftmost_link(self: &Self) -> String {
if self.name.is_none() {
self.hash()
} else {
self.name.clone().unwrap()
}
}
pub async fn read(self: &Self) -> Result<Vec<u8>, Box<dyn Error>> { pub async fn read(self: &Self) -> Result<Vec<u8>, Box<dyn Error>> {
let data = self.read_unchecked().await?; let data = self.read_unchecked().await?;

View File

@ -101,7 +101,7 @@ pub async fn upload(form: FormData, state: SharedState) -> Result<Box<dyn Reply>
let uploaded = UploadSuccessPage { let uploaded = UploadSuccessPage {
env: state.env.clone(), env: state.env.clone(),
link: "uwu".into() link: file.leftmost_link()
}; };
Ok(Box::new(warp::reply::html(uploaded.render().unwrap()))) Ok(Box::new(warp::reply::html(uploaded.render().unwrap())))

View File

@ -9,7 +9,7 @@ pub async fn uploaded((file, _state): (String, SharedState)) -> Result<Box<dyn R
if file_res.is_none() { if file_res.is_none() {
file_res = _state.file_mgr.find_by_name(file.clone()) file_res = _state.file_mgr.find_by_name(file.clone())
.map_err(|x| warp::reject::custom(HttpReject::StringError(x.to_string())))?; .map_err(|x| warp::reject::custom(HttpReject::StringError(x.to_string())))?;
} }
if file_res.is_none() { if file_res.is_none() {