* Cargo clippy cleanup
This commit is contained in:
parent
0698f62659
commit
db637c0889
@ -25,14 +25,12 @@ pub fn get_category_dirs(path: &str) -> std::io::Result<Vec<DirEntry>> {
|
||||
}
|
||||
|
||||
let mut ret: Vec<DirEntry> = Vec::new();
|
||||
for entry in std::fs::read_dir(path)? {
|
||||
if let Ok(entry) = 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<String> {
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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/<cat..>")]
|
||||
@ -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("/<file..>")]
|
||||
|
@ -21,15 +21,13 @@ fn vid_file_entries(path: &OsStr) -> std::io::Result<Vec<DirEntry>> {
|
||||
panic!("<{:?}> is not a valid directory", path);
|
||||
}
|
||||
let mut entries: Vec<DirEntry> = Vec::new();
|
||||
for ent in path.read_dir()? {
|
||||
if let Ok(ent) = 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<Json<Vec<VideoPreview>>> {
|
||||
* 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<VideoPreview> = Vec::new();
|
||||
// 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 None;
|
||||
None
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user