Compare commits

...

3 Commits

Author SHA1 Message Date
blek ea15e25fe2
hardcode the midfix variable 2023-12-11 02:42:52 +10:00
blek e84ddee2a4
refactor code for readability 2023-12-09 22:14:09 +10:00
blek 080498d80c
fix #23 2023-12-09 22:13:42 +10:00
2 changed files with 15 additions and 14 deletions

View File

@ -102,30 +102,32 @@ impl FileManager {
pub fn save(self: &Self, file: &File, kind: LookupKind) -> Result<(), Box<dyn Error>> { pub fn save(self: &Self, file: &File, kind: LookupKind) -> Result<(), Box<dyn Error>> {
let file = file.clone(); let file = file.clone();
let midfix = match kind {
LookupKind::ByName => "-name-",
LookupKind::ByHash => "-hash-"
};
match kind { match kind {
LookupKind::ByName => { 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()) return Err("Filename can't be None when LookupKind is ByName!".into())
} }
} }
_ => () _ => log::debug!("No custom file name detected")
} }
self.save_int( self.save_int(
&file, &file,
format!( format!(
"{}{}{}", "{}-hash-{}",
self.env.redis.prefix, self.env.redis.prefix,
midfix, file.hash()
match kind {
LookupKind::ByName => (&file).name.as_ref().unwrap().clone(),
LookupKind::ByHash => (&file).hash()
}
) )
) )
} }

View File

@ -95,7 +95,7 @@ impl UploadFormData {
if val.is_checked() { if val.is_checked() {
let name = data.get("filename")?; let name = data.get("filename")?;
out.filename = Some(name.as_atr_or_none()?); out.filename = Some(name.as_atr_or_none()?);
out.lookup_kind = LookupKind::ByHash out.lookup_kind = LookupKind::ByName
} }
}, },
None => () None => ()
@ -107,7 +107,6 @@ impl UploadFormData {
if val.is_checked() { if val.is_checked() {
let pass = data.get("password")?; let pass = data.get("password")?;
out.password = Some(pass.as_atr_or_none()?); out.password = Some(pass.as_atr_or_none()?);
out.lookup_kind = LookupKind::ByName
} }
}, },
None => () None => ()