diff --git a/api/src/category.rs b/api/src/category.rs index aa2f95a..5bcf46d 100644 --- a/api/src/category.rs +++ b/api/src/category.rs @@ -25,14 +25,12 @@ pub fn get_category_dirs(path: &str) -> std::io::Result> { } let mut ret: Vec = Vec::new(); - for entry in std::fs::read_dir(path)? { - if let Ok(entry) = entry { - if entry.path().is_dir() { - ret.push(entry) - } + for entry in (std::fs::read_dir(path)?).flatten() { + if entry.path().is_dir() { + ret.push(entry) } } - return Ok(ret); + Ok(ret) } pub fn get_category_thumbnail(category: &str) -> std::io::Result { diff --git a/api/src/common.rs b/api/src/common.rs index 5dfd574..56a8173 100644 --- a/api/src/common.rs +++ b/api/src/common.rs @@ -1,15 +1,15 @@ use std::env; pub fn get_clips_dir() -> String { - return match env::var("CLIPS_DIR") { + match env::var("CLIPS_DIR") { Ok(val) => val, - Err(_) => String::from("/media/clips/".to_string()) + Err(_) => "/media/clips/".to_string() } } pub fn thumbs_dir() -> String { - return match env::var("THUMBS_DIR") { + match env::var("THUMBS_DIR") { Ok(val) => val, - Err(_) => String::from("/media/thumbnails/".to_string()) + Err(_) => "/media/thumbnails/".to_string() } } diff --git a/api/src/page.rs b/api/src/page.rs index 6b17fde..6b22eeb 100644 --- a/api/src/page.rs +++ b/api/src/page.rs @@ -9,13 +9,13 @@ use std::env; lazy_static! { static ref SITENAME: String = { - env::var("SITE_NAME").unwrap_or("Clippable".to_string()) + env::var("SITE_NAME").unwrap_or_else(|_| "Clippable".to_string()) }; static ref SITEDESC: String = { - env::var("SITE_DESC").unwrap_or("Short clips".to_string()) + env::var("SITE_DESC").unwrap_or_else(|_| "Short clips".to_string()) }; static ref SITEURL: String = { - env::var("SITE_URL").unwrap_or("#".to_string()) + env::var("SITE_URL").unwrap_or_else(|_| "#".to_string()) }; } @@ -24,7 +24,7 @@ pub fn default_map() -> HashMap<&'static str, String> { h.insert("sitetitle", SITENAME.clone()); h.insert("sitedesc", SITEDESC.clone()); h.insert("siteurl", SITEURL.clone()); - return h; + h } #[get("/")] @@ -34,7 +34,7 @@ pub async fn home() -> Template { h.insert("page", String::from("home")); h.insert("title", SITENAME.clone()); - return Template::render("list", &h); + Template::render("list", &h) } #[get("/category/")] @@ -50,10 +50,10 @@ pub async fn category(cat: PathBuf) -> Template { h.insert("desc", format!("{} clips", cat)); h.insert("ogimg", format!("/thumbnail/{}/category-thumbnail.jpg", cat)); - return Template::render("list", &h); + Template::render("list", &h) } -fn map_base_vfile(category: &PathBuf, base: &PathBuf) -> String { +fn map_base_vfile(category: &Path, base: &Path) -> String { // This takes a category and base filename and basically looks for the file // that maps to those parameters // This basically aims to get rid of the extension in the URL so that social @@ -107,7 +107,7 @@ pub fn video(cat: PathBuf, file_base: PathBuf) -> Template { let clip_thumbnail = format!("/thumbnail/{}/{}.jpg", &cat, &file); h.insert("clip_thumbnail", &clip_thumbnail); - return Template::render("video", &h); + Template::render("video", &h) } #[get("/")] diff --git a/api/src/video.rs b/api/src/video.rs index b21ef4b..f9088f0 100644 --- a/api/src/video.rs +++ b/api/src/video.rs @@ -21,15 +21,13 @@ fn vid_file_entries(path: &OsStr) -> std::io::Result> { panic!("<{:?}> is not a valid directory", path); } let mut entries: Vec = Vec::new(); - for ent in path.read_dir()? { - if let Ok(ent) = ent { - let name = ent.file_name().into_string().unwrap(); - if name.ends_with("mkv") || name.ends_with("mp4") || name.ends_with("webm") { - entries.push(ent); - } + for ent in (path.read_dir()?).flatten() { + let name = ent.file_name().into_string().unwrap(); + if name.ends_with("mkv") || name.ends_with("mp4") || name.ends_with("webm") { + entries.push(ent); } } - return Ok(entries); + Ok(entries) } @@ -39,7 +37,7 @@ pub fn list(cat: PathBuf) -> Option>> { * List out the videos to a given category */ // First we have to make sure this given category is even registered with us - let file_path = cat.file_name().unwrap_or(OsStr::new("")); + let file_path = cat.file_name().unwrap_or_else(|| OsStr::new("")); if let Ok(entries) = vid_file_entries(file_path) { let mut previews: Vec = Vec::new(); // Autismo but at least its bare-able @@ -58,7 +56,7 @@ pub fn list(cat: PathBuf) -> Option>> { } return Some(Json(previews)) } - return None; + None }