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())?))
}
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))?)
}
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 {
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>> {
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 {
env: state.env.clone(),
link: "uwu".into()
link: file.leftmost_link()
};
Ok(Box::new(warp::reply::html(uploaded.render().unwrap())))