-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New category info endpoint and FS methods to support
- Loading branch information
1 parent
f73dee7
commit 4f4d6d0
Showing
5 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
[agent] | ||
port = 3000 | ||
name = "Agent Smith" | ||
base_path = "/path/to/stuff" | ||
base_path = "C:\\media" | ||
|
||
[[categories]] | ||
name = "Category A" | ||
relative_path = "a/" | ||
|
||
[[categories]] | ||
name = "Category B" | ||
relative_path = "tv" | ||
id = "movies" | ||
name = "Movies" | ||
relative_path = "movies\\" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
/* generic functions */ | ||
pub fn build_path(base_path: &String, category_path: &String) -> PathBuf { | ||
Path::new(base_path).join(category_path) | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
pub(crate) struct CategoryItem { | ||
category: String, | ||
id: String, | ||
name: String, | ||
items: Vec<CategoryItem>, | ||
} | ||
|
||
fn entry_to_item(entry: fs::DirEntry, category_id: String) -> CategoryItem { | ||
CategoryItem { | ||
category: category_id.clone(), | ||
id: entry.file_name().into_string().unwrap(), | ||
name: entry.file_name().into_string().unwrap(), | ||
items: vec![], | ||
} | ||
} | ||
|
||
pub fn get_category_items(category_path: PathBuf, category_id: String) -> Vec<CategoryItem> { | ||
match fs::read_dir(category_path) { | ||
Err(why) => { | ||
println!("ERROR: Unable to list path: {:?}", why.kind()); | ||
vec![] | ||
} | ||
Ok(paths) => paths | ||
.filter(|i| i.as_ref().unwrap().file_type().unwrap().is_dir()) | ||
.map(|i| entry_to_item(i.unwrap(), category_id.clone())) | ||
.collect(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters