Case-insensitivity should be handled by the lookup functions instead of the callers.

Don't code on no sleep, folks
This commit is contained in:
Karcsesz 2024-02-15 11:36:13 +01:00
parent 6bf7803b99
commit 3d69a6dd28
3 changed files with 4 additions and 3 deletions

View file

@ -4,7 +4,7 @@ use std::path::PathBuf;
pub fn query(database_path: PathBuf, handle: String) {
let data = LookupHandler::load(database_path).unwrap();
let resource = data.lookup(handle.trim().to_lowercase().as_str()).unwrap();
let resource = data.lookup(handle.trim()).unwrap();
serde_json::to_writer_pretty(stdout(), resource).unwrap();
println!()
}

View file

@ -65,7 +65,8 @@ impl LookupHandler {
}
pub fn lookup_with_index(&self, resource_query: &str) -> Option<(usize, &Resource)> {
let resource_index = *self.lookup.get(resource_query)?;
let resource_query = resource_query.to_lowercase();
let resource_index = *self.lookup.get(resource_query.as_str())?;
let found_resource = &self.resources.0[resource_index];
debug!("Lookup for {resource_query} returned {found_resource:?}");
Some((resource_index, found_resource))

View file

@ -111,7 +111,7 @@ async fn run_webfinger_query(
let resource = datastore
.read()
.await
.lookup(resource_query.to_lowercase().as_str())
.lookup(resource_query)
.ok_or(StatusCode::NOT_FOUND)?
.clone();
debug!("Found resource: {resource:?}");