* Cargo clippy cleanup

This commit is contained in:
shockrah 2022-02-05 13:49:49 -08:00
parent 0698f62659
commit db637c0889
4 changed files with 23 additions and 27 deletions

View File

@ -25,14 +25,12 @@ pub fn get_category_dirs(path: &str) -> std::io::Result<Vec<DirEntry>> {
} }
let mut ret: Vec<DirEntry> = Vec::new(); let mut ret: Vec<DirEntry> = Vec::new();
for entry in std::fs::read_dir(path)? { for entry in (std::fs::read_dir(path)?).flatten() {
if let Ok(entry) = entry { if entry.path().is_dir() {
if entry.path().is_dir() { ret.push(entry)
ret.push(entry)
}
} }
} }
return Ok(ret); Ok(ret)
} }
pub fn get_category_thumbnail(category: &str) -> std::io::Result<String> { pub fn get_category_thumbnail(category: &str) -> std::io::Result<String> {

View File

@ -1,15 +1,15 @@
use std::env; use std::env;
pub fn get_clips_dir() -> String { pub fn get_clips_dir() -> String {
return match env::var("CLIPS_DIR") { match env::var("CLIPS_DIR") {
Ok(val) => val, Ok(val) => val,
Err(_) => String::from("/media/clips/".to_string()) Err(_) => "/media/clips/".to_string()
} }
} }
pub fn thumbs_dir() -> String { pub fn thumbs_dir() -> String {
return match env::var("THUMBS_DIR") { match env::var("THUMBS_DIR") {
Ok(val) => val, Ok(val) => val,
Err(_) => String::from("/media/thumbnails/".to_string()) Err(_) => "/media/thumbnails/".to_string()
} }
} }

View File

@ -9,13 +9,13 @@ use std::env;
lazy_static! { lazy_static! {
static ref SITENAME: String = { 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 = { 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 = { 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("sitetitle", SITENAME.clone());
h.insert("sitedesc", SITEDESC.clone()); h.insert("sitedesc", SITEDESC.clone());
h.insert("siteurl", SITEURL.clone()); h.insert("siteurl", SITEURL.clone());
return h; h
} }
#[get("/")] #[get("/")]
@ -34,7 +34,7 @@ pub async fn home() -> Template {
h.insert("page", String::from("home")); h.insert("page", String::from("home"));
h.insert("title", SITENAME.clone()); h.insert("title", SITENAME.clone());
return Template::render("list", &h); Template::render("list", &h)
} }
#[get("/category/<cat..>")] #[get("/category/<cat..>")]
@ -50,10 +50,10 @@ pub async fn category(cat: PathBuf) -> Template {
h.insert("desc", format!("{} clips", cat)); h.insert("desc", format!("{} clips", cat));
h.insert("ogimg", format!("/thumbnail/{}/category-thumbnail.jpg", 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 // This takes a category and base filename and basically looks for the file
// that maps to those parameters // that maps to those parameters
// This basically aims to get rid of the extension in the URL so that social // 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); let clip_thumbnail = format!("/thumbnail/{}/{}.jpg", &cat, &file);
h.insert("clip_thumbnail", &clip_thumbnail); h.insert("clip_thumbnail", &clip_thumbnail);
return Template::render("video", &h); Template::render("video", &h)
} }
#[get("/<file..>")] #[get("/<file..>")]

View File

@ -21,15 +21,13 @@ fn vid_file_entries(path: &OsStr) -> std::io::Result<Vec<DirEntry>> {
panic!("<{:?}> is not a valid directory", path); panic!("<{:?}> is not a valid directory", path);
} }
let mut entries: Vec<DirEntry> = Vec::new(); let mut entries: Vec<DirEntry> = Vec::new();
for ent in path.read_dir()? { for ent in (path.read_dir()?).flatten() {
if let Ok(ent) = ent { let name = ent.file_name().into_string().unwrap();
let name = ent.file_name().into_string().unwrap(); if name.ends_with("mkv") || name.ends_with("mp4") || name.ends_with("webm") {
if name.ends_with("mkv") || name.ends_with("mp4") || name.ends_with("webm") { entries.push(ent);
entries.push(ent);
}
} }
} }
return Ok(entries); Ok(entries)
} }
@ -39,7 +37,7 @@ pub fn list(cat: PathBuf) -> Option<Json<Vec<VideoPreview>>> {
* List out the videos to a given category * List out the videos to a given category
*/ */
// First we have to make sure this given category is even registered with us // 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) { if let Ok(entries) = vid_file_entries(file_path) {
let mut previews: Vec<VideoPreview> = Vec::new(); let mut previews: Vec<VideoPreview> = Vec::new();
// Autismo but at least its bare-able // Autismo but at least its bare-able
@ -58,7 +56,7 @@ pub fn list(cat: PathBuf) -> Option<Json<Vec<VideoPreview>>> {
} }
return Some(Json(previews)) return Some(Json(previews))
} }
return None; None
} }