* Sanity refactor to clean up common warnings
! ALso using the new common module
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use serde::Serialize;
|
||||
use std::fs::DirEntry;
|
||||
use std::{io, env};
|
||||
use std::io;
|
||||
use rocket::serde::json::Json;
|
||||
use crate::common::get_clips_dir;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Category {
|
||||
@@ -15,7 +16,7 @@ pub struct Category {
|
||||
struct List {
|
||||
categories: Vec<Category>
|
||||
}
|
||||
fn get_category_dirs(path: &str) -> std::io::Result<Vec<DirEntry>> {
|
||||
pub fn get_category_dirs(path: &str) -> std::io::Result<Vec<DirEntry>> {
|
||||
let path = std::path::Path::new(path);
|
||||
if !path.is_dir() {
|
||||
let e = io::Error::new(io::ErrorKind::NotFound, "Unable to open");
|
||||
@@ -35,10 +36,7 @@ fn get_category_dirs(path: &str) -> std::io::Result<Vec<DirEntry>> {
|
||||
pub fn list() -> Json<Vec<Category>> {
|
||||
// WARN: misconfigured servers are just going to get shafted and serve up
|
||||
// a tonne of 500's
|
||||
let dir = match env::var("CLIPS_DIR") {
|
||||
Ok(val) => val,
|
||||
Err(_) => "/media/clips/".to_string()
|
||||
};
|
||||
let dir = get_clips_dir();
|
||||
|
||||
let mut cats: Vec<Category> = Vec::new();
|
||||
if let Ok(dirs) = get_category_dirs(&dir) {
|
||||
|
||||
Reference in New Issue
Block a user