* Simplifying backend api by... alot

This commit is contained in:
shockrah
2021-10-04 12:19:41 -07:00
parent 87b373bde8
commit 5b3f6efebf
10 changed files with 61 additions and 65 deletions

17
api/src/main.rs Normal file
View 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
View 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})
}