! Bulk commit of progression
A lot off issues with the current design make 100% more sense by cutting hugo out of the picture entirely This means we're switching fully to rocket however we're not going to leave behind the work done with hugo, we're just going to migrate it over first
This commit is contained in:
@@ -12,6 +12,6 @@ fn main() {
|
||||
* CLIP_DIR
|
||||
*/
|
||||
let _ = rocket::ignite()
|
||||
.mount("/api", routes![video::list_categories])
|
||||
.mount("/api", routes![video::list_categories, video::list_videos])
|
||||
.launch();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,13 @@ struct Category {
|
||||
thumbnail: Option<String>
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Video {
|
||||
name: String,
|
||||
category: String,
|
||||
thumbnail: Option<String>
|
||||
}
|
||||
|
||||
fn get_nail(dirpath: &Path) -> std::io::Result<Option<String>> {
|
||||
let mut t_path = dirpath.to_path_buf(); t_path.push(".thumbnail.jpg");
|
||||
|
||||
@@ -29,7 +36,7 @@ fn get_nail(dirpath: &Path) -> std::io::Result<Option<String>> {
|
||||
pub fn list_categories() -> JsonValue {
|
||||
let dir = match env::var("CLIPS_DIR") {
|
||||
Ok(val) => val,
|
||||
Err(e) => "/media/clips/".to_string()
|
||||
Err(_) => "/media/clips/".to_string()
|
||||
};
|
||||
|
||||
// Fucking hell this is going to be dumb
|
||||
@@ -48,3 +55,24 @@ pub fn list_categories() -> JsonValue {
|
||||
|
||||
json!({"categories": cats})
|
||||
}
|
||||
|
||||
#[get("/category/<cat>")]
|
||||
pub fn list_videos(cat: String) -> JsonValue {
|
||||
let dir = match env::var("CLIPS_DIR") {
|
||||
Ok(val) => val,
|
||||
Err(_) => "/media/clips".to_string()
|
||||
};
|
||||
|
||||
let mut vids: Vec<Video> = Vec::new();
|
||||
for file in fs::read_dir(dir).unwrap() {
|
||||
match file {
|
||||
Ok(file) => {
|
||||
let name = file.file_name()
|
||||
.into_string().unwrap_or(String::new());
|
||||
vids.push(Video {name, category: cat.clone(), thumbnail: None})
|
||||
},
|
||||
_ => continue
|
||||
}
|
||||
}
|
||||
return json!({"videos": vids})
|
||||
}
|
||||
Reference in New Issue
Block a user