* Simplifying backend api by... alot
This commit is contained in:
17
api/src/main.rs
Normal file
17
api/src/main.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
#![feature(decl_macro)]
|
||||
#[macro_use] extern crate rocket;
|
||||
use std::env;
|
||||
|
||||
mod video;
|
||||
|
||||
fn main() {
|
||||
// emoji's crash my terminal
|
||||
env::set_var("ROCKET_CLI_COLORS", "off");
|
||||
/*
|
||||
* Some of the target vars that we look for
|
||||
* CLIP_DIR
|
||||
*/
|
||||
let _ = rocket::ignite()
|
||||
.mount("/api", routes![video::list_categories])
|
||||
.launch();
|
||||
}
|
||||
30
api/src/video.rs
Normal file
30
api/src/video.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use rocket_contrib::json;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
|
||||
|
||||
#[get("/categories")]
|
||||
pub fn list_categories() -> JsonValue {
|
||||
let dir = match env::var("CLIPS_DIR") {
|
||||
Ok(val) => val,
|
||||
Err(e) => "/media/clips/".to_string()
|
||||
};
|
||||
println!("Directory to search: {}", dir);
|
||||
|
||||
// Fucking hell this is going to be dumb
|
||||
let mut cats: Vec<String> = Vec::new();
|
||||
for file in fs::read_dir(dir).unwrap() {
|
||||
match file {
|
||||
Ok(file) => {
|
||||
match file.file_name().into_string() {
|
||||
Ok(s) => cats.push(s),
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
Err(_) => continue
|
||||
}
|
||||
}
|
||||
|
||||
json!({"categories": cats})
|
||||
}
|
||||
Reference in New Issue
Block a user