diff --git a/Cargo.lock b/Cargo.lock index 3682f37..e4469aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -159,6 +159,7 @@ dependencies = [ name = "clippable" version = "0.1.0" dependencies = [ + "base64 0.13.0", "clap", "rocket", "rocket_contrib", @@ -178,6 +179,7 @@ dependencies = [ name = "clippable-server" version = "0.1.0" dependencies = [ + "base64 0.13.0", "rocket", "rocket_contrib", "serde", @@ -709,9 +711,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" dependencies = [ "proc-macro2 1.0.29", ] @@ -868,8 +870,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" dependencies = [ "proc-macro2 1.0.29", - "quote 1.0.9", - "syn 1.0.77", + "quote 1.0.10", + "syn 1.0.78", ] [[package]] @@ -904,9 +906,9 @@ checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" [[package]] name = "smallvec" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" [[package]] name = "state" @@ -939,12 +941,12 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.77" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5239bc68e0fef57495900cfea4e8dc75596d9a319d7e16b1e0a440d24e6fe0a0" +checksum = "a4eac2e6c19f5c3abc0c229bea31ff0b9b091c7b14990e8924b92902a303a0c0" dependencies = [ "proc-macro2 1.0.29", - "quote 1.0.9", + "quote 1.0.10", "unicode-xid 0.2.2", ] diff --git a/Cargo.toml b/Cargo.toml index fb62b86..649e233 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,13 +18,16 @@ path = "api/src/main.rs" # For json hehexd serde = { version = "1.0", features = ["derive"] } +# This is primarily for turning images(thumbnails) in the api +# into base64 strings +base64 = "0.13.0" + # For commanline parsing clap = "2.33.3" # For the backend server we just use rocket rocket = "0.4" - [dependencies.rocket_contrib] version = "0.4.10" default-features = false diff --git a/api/Cargo.toml b/api/Cargo.toml index 053d3e3..3e899d7 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [dependencies] rocket = "0.4" serde = { version = "1.0", features = [ "derive" ] } +base64 = "0.13.0" [dependencies.rocket_contrib] version = "0.4.10" diff --git a/api/src/video.rs b/api/src/video.rs index cc9f75a..5b5df7d 100644 --- a/api/src/video.rs +++ b/api/src/video.rs @@ -1,8 +1,29 @@ use rocket_contrib::json; use rocket_contrib::json::JsonValue; -use std::env; -use std::fs; +use serde::Serialize; +use base64; +use std::path::Path; +use std::{fs, env}; +use std::fs::File; +use std::io::prelude::*; +#[derive(Serialize)] +struct Category { + name: String, + thumbnail: Option +} + +fn get_nail(dirpath: &Path) -> std::io::Result> { + let mut t_path = dirpath.to_path_buf(); t_path.push(".thumbnail.jpg"); + + if t_path.is_file() { + let mut buf = Vec::new(); + let mut file = File::open(t_path)?; + file.read_to_end(&mut buf)?; + return Ok(Some(base64::encode(buf).to_string())); + } + Ok(None) +} #[get("/categories")] pub fn list_categories() -> JsonValue { @@ -10,19 +31,18 @@ pub fn list_categories() -> JsonValue { 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(); + 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), - _ => {} - } + let name = file.file_name() + .into_string().unwrap_or(String::new()); + let nail = get_nail(file.path().as_ref()); + cats.push(Category { name, thumbnail: nail.unwrap_or(None) }); }, - Err(_) => continue + _ => continue } }