option for list folders only

This commit is contained in:
jb-alvarado 2023-01-22 15:51:53 +01:00
parent e752a7a951
commit 143085991d

View File

@ -20,6 +20,8 @@ pub struct PathObject {
parent: Option<String>,
folders: Option<Vec<String>>,
files: Option<Vec<VideoFile>>,
#[serde(default)]
pub folders_only: bool,
}
impl PathObject {
@ -29,6 +31,7 @@ impl PathObject {
parent,
folders: Some(vec![]),
files: Some(vec![]),
folders_only: false,
}
}
}
@ -105,6 +108,7 @@ pub async fn browser(
let (path, parent, path_component) = norm_abs_path(&config.storage.path, &path_obj.source);
let mut obj = PathObject::new(path_component, Some(parent));
obj.folders_only = path_obj.folders_only;
let mut paths: Vec<PathBuf> = match fs::read_dir(path) {
Ok(p) => p.filter_map(|r| r.ok()).map(|p| p.path()).collect(),
@ -126,7 +130,7 @@ pub async fn browser(
if path.is_dir() {
folders.push(path.file_name().unwrap().to_string_lossy().to_string());
} else if path.is_file() {
} else if path.is_file() && !path_obj.folders_only {
if let Some(ext) = file_extension(&path) {
if extensions.contains(&ext.to_string().to_lowercase()) {
let media = MediaProbe::new(&path.display().to_string());