From 080498d80cf1488680b6938b2b4de5f0d13c9bab Mon Sep 17 00:00:00 2001 From: blek Date: Sat, 9 Dec 2023 22:13:42 +1000 Subject: [PATCH 1/3] fix #23 --- filed/src/web/forms.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 => () -- 2.40.1 From e84ddee2a437972fb4b27a055df8e84036f472a1 Mon Sep 17 00:00:00 2001 From: blek Date: Sat, 9 Dec 2023 22:14:09 +1000 Subject: [PATCH 2/3] refactor code for readability --- filed/src/files/lookup.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/filed/src/files/lookup.rs b/filed/src/files/lookup.rs index 3e67233..63210a7 100644 --- a/filed/src/files/lookup.rs +++ b/filed/src/files/lookup.rs @@ -109,11 +109,22 @@ impl FileManager { 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!( + "{}{}{}", + self.env.redis.prefix, + midfix, + name + ) + )?) + } else { return Err("Filename can't be None when LookupKind is ByName!".into()) } } - _ => () + _ => log::debug!("No custom file name detected") } self.save_int( @@ -122,10 +133,7 @@ impl FileManager { "{}{}{}", self.env.redis.prefix, midfix, - match kind { - LookupKind::ByName => (&file).name.as_ref().unwrap().clone(), - LookupKind::ByHash => (&file).hash() - } + file.hash() ) ) } -- 2.40.1 From ea15e25fe2e59f06ff4523362cb4a9e152ef0267 Mon Sep 17 00:00:00 2001 From: blek Date: Mon, 11 Dec 2023 02:42:52 +1000 Subject: [PATCH 3/3] hardcode the midfix variable --- filed/src/files/lookup.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/filed/src/files/lookup.rs b/filed/src/files/lookup.rs index 63210a7..f223724 100644 --- a/filed/src/files/lookup.rs +++ b/filed/src/files/lookup.rs @@ -102,10 +102,6 @@ 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 => { @@ -114,9 +110,8 @@ impl FileManager { return Ok(self.save_int( &file, format!( - "{}{}{}", + "{}-name-{}", self.env.redis.prefix, - midfix, name ) )?) @@ -130,9 +125,8 @@ impl FileManager { self.save_int( &file, format!( - "{}{}{}", + "{}-hash-{}", self.env.redis.prefix, - midfix, file.hash() ) ) -- 2.40.1