From 5b3f6efebf3413bcb9d2b458aa82ceae489018b4 Mon Sep 17 00:00:00 2001 From: shockrah Date: Mon, 4 Oct 2021 12:19:41 -0700 Subject: [PATCH] * Simplifying backend api by... alot --- {clippable-server => api}/Cargo.toml | 1 - api/src/main.rs | 17 +++++++++ api/src/video.rs | 30 ++++++++++++++++ {clippable-server => api}/static/img/tmp.png | Bin {clippable-server => api}/static/index.html | 0 {clippable-server => api}/static/style.css | 0 api/store.json | 11 ++++++ api/target/CACHEDIR.TAG | 3 ++ clippable-server/src/api.rs | 36 ------------------- clippable-server/src/main.rs | 28 --------------- 10 files changed, 61 insertions(+), 65 deletions(-) rename {clippable-server => api}/Cargo.toml (87%) create mode 100644 api/src/main.rs create mode 100644 api/src/video.rs rename {clippable-server => api}/static/img/tmp.png (100%) rename {clippable-server => api}/static/index.html (100%) rename {clippable-server => api}/static/style.css (100%) create mode 100644 api/store.json create mode 100644 api/target/CACHEDIR.TAG delete mode 100644 clippable-server/src/api.rs delete mode 100644 clippable-server/src/main.rs diff --git a/clippable-server/Cargo.toml b/api/Cargo.toml similarity index 87% rename from clippable-server/Cargo.toml rename to api/Cargo.toml index 3bc9db0..053d3e3 100644 --- a/clippable-server/Cargo.toml +++ b/api/Cargo.toml @@ -7,7 +7,6 @@ edition = "2018" [dependencies] rocket = "0.4" -dblib = { version = "0.1.0", path = "../dblib" } serde = { version = "1.0", features = [ "derive" ] } [dependencies.rocket_contrib] diff --git a/api/src/main.rs b/api/src/main.rs new file mode 100644 index 0000000..67a190f --- /dev/null +++ b/api/src/main.rs @@ -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(); +} diff --git a/api/src/video.rs b/api/src/video.rs new file mode 100644 index 0000000..cc9f75a --- /dev/null +++ b/api/src/video.rs @@ -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 = 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}) +} diff --git a/clippable-server/static/img/tmp.png b/api/static/img/tmp.png similarity index 100% rename from clippable-server/static/img/tmp.png rename to api/static/img/tmp.png diff --git a/clippable-server/static/index.html b/api/static/index.html similarity index 100% rename from clippable-server/static/index.html rename to api/static/index.html diff --git a/clippable-server/static/style.css b/api/static/style.css similarity index 100% rename from clippable-server/static/style.css rename to api/static/style.css diff --git a/api/store.json b/api/store.json new file mode 100644 index 0000000..a0ae653 --- /dev/null +++ b/api/store.json @@ -0,0 +1,11 @@ +{ + "keys":[ + { + "name": "shockrah", + "key": "asdf" + } + ], + "videos": { + "video": { "name": "cool" } + } +} diff --git a/api/target/CACHEDIR.TAG b/api/target/CACHEDIR.TAG new file mode 100644 index 0000000..20d7c31 --- /dev/null +++ b/api/target/CACHEDIR.TAG @@ -0,0 +1,3 @@ +Signature: 8a477f597d28d172789f06886806bc55 +# This file is a cache directory tag created by cargo. +# For information about cache directory tags see https://bford.info/cachedir/ diff --git a/clippable-server/src/api.rs b/clippable-server/src/api.rs deleted file mode 100644 index 7d690ac..0000000 --- a/clippable-server/src/api.rs +++ /dev/null @@ -1,36 +0,0 @@ -use rocket_contrib::json::Json; -use rocket_contrib::json::JsonValue; -use dblib::{DB, request::ApiKey}; -use dblib::KeyStore; -use serde::Serialize; - -#[derive(Serialize)] -pub struct GenericResponse<'m> { - msg: Option<&'m str>, - err: bool -} - -#[get("/by-id")] -pub fn get_vid_by_id(id: String) -> JsonValue { - todo!() -} - -#[get("/by-name")] -pub fn get_vid_by_name(name: String) -> JsonValue { - todo!() -} - -#[update("/description?&")] -pub fn update_description<'m>(key: ApiKey, id: String, desc: String) -> Json> { - todo!() -} - -#[delete("/video?")] -pub fn delete_video(key: ApiKey, id: String) -> Json> { - todo!() -} - -#[update("/name?&")] -pub fn update_vid_name<'m>(key: ApiKey, id: String, dest: String) -> Json> { - todo!() -} \ No newline at end of file diff --git a/clippable-server/src/main.rs b/clippable-server/src/main.rs deleted file mode 100644 index ff534c7..0000000 --- a/clippable-server/src/main.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![feature(decl_macro)] -#[macro_use] extern crate rocket; -use rocket_contrib::serve::StaticFiles; -use std::env; - -mod api; - -#[get("/")] -fn video_page(id: u64) -> String { - format!("Video id requested: {}", id) -} - -fn main() { - // emoji's crash my terminal - env::set_var("ROCKET_CLI_COLORS", "off"); - - let _ = rocket::ignite() - .mount("/clip", routes![video_page]) - .mount("/video-api", routes![ - api::get_vid_by_id, - api::get_vid_by_name, - api::update_description, - api::delete_video, - api::update_vid_name, - ]) - .mount("/", StaticFiles::from("static")) - .launch(); -}