diff --git a/filed/src/files/lookup.rs b/filed/src/files/lookup.rs index 3e67233..f223724 100644 --- a/filed/src/files/lookup.rs +++ b/filed/src/files/lookup.rs @@ -102,30 +102,32 @@ impl FileManager { pub fn save(self: &Self, file: &File, kind: LookupKind) -> Result<(), Box> { let file = file.clone(); - let midfix = match kind { - LookupKind::ByName => "-name-", - LookupKind::ByHash => "-hash-" - }; match kind { LookupKind::ByName => { - if (&file).name.is_none() { + if let Some(name) = file.name.clone() { + log::debug!("Using {} as a custom file name", name); + return Ok(self.save_int( + &file, + format!( + "{}-name-{}", + self.env.redis.prefix, + name + ) + )?) + } else { return Err("Filename can't be None when LookupKind is ByName!".into()) } } - _ => () + _ => log::debug!("No custom file name detected") } self.save_int( &file, format!( - "{}{}{}", + "{}-hash-{}", self.env.redis.prefix, - midfix, - match kind { - LookupKind::ByName => (&file).name.as_ref().unwrap().clone(), - LookupKind::ByHash => (&file).hash() - } + file.hash() ) ) } diff --git a/filed/src/web/forms.rs b/filed/src/web/forms.rs index cbfcecf..cd94914 100644 --- a/filed/src/web/forms.rs +++ b/filed/src/web/forms.rs @@ -95,7 +95,7 @@ impl UploadFormData { if val.is_checked() { let name = data.get("filename")?; out.filename = Some(name.as_atr_or_none()?); - out.lookup_kind = LookupKind::ByHash + out.lookup_kind = LookupKind::ByName } }, None => () @@ -107,7 +107,6 @@ impl UploadFormData { if val.is_checked() { let pass = data.get("password")?; out.password = Some(pass.as_atr_or_none()?); - out.lookup_kind = LookupKind::ByName } }, None => ()