From 6b66a44ed035c33c43377a63b23856923743ea09 Mon Sep 17 00:00:00 2001 From: krolxon Date: Sun, 28 Apr 2024 23:59:42 +0530 Subject: fix queue deletion & make get_full_path return an option --- src/connection.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/connection.rs') diff --git a/src/connection.rs b/src/connection.rs index 1ec76ae..8f4fe72 100755 --- a/src/connection.rs +++ b/src/connection.rs @@ -188,18 +188,26 @@ impl Connection { } /// Given a song name from a directory, it returns the full path of the song in the database - pub fn get_full_path(&self, short_path: &str) -> AppResult { - let list = self - .songs_filenames - .iter() - .map(|f| f.as_str()) - .collect::>(); - let (filename, _) = rust_fuzzy_search::fuzzy_search_sorted(&short_path, &list) - .get(0) - .unwrap() - .clone(); + pub fn get_full_path(&self, short_path: &str) -> Option { + // let list = self + // .songs_filenames + // .iter() + // .map(|f| f.as_str()) + // .collect::>(); + // let (filename, _) = rust_fuzzy_search::fuzzy_search_sorted(&short_path, &list) + // .get(0) + // .unwrap() + // .clone(); + + for (i, f) in self.songs_filenames.iter().enumerate() { + if f.contains(short_path) { + return Some(self.songs_filenames.get(i).unwrap().to_string()); + } + } + + None - Ok(filename.to_string()) + // Ok(filename.to_string()) } /// Print status to stdout -- cgit v1.2.3