* Simplifying backend api by... alot
This commit is contained in:
15
api/Cargo.toml
Normal file
15
api/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "clippable-server"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rocket = "0.4"
|
||||
serde = { version = "1.0", features = [ "derive" ] }
|
||||
|
||||
[dependencies.rocket_contrib]
|
||||
version = "0.4.10"
|
||||
default-features = false
|
||||
features = ["serve", "json"]
|
||||
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})
|
||||
}
|
||||
BIN
api/static/img/tmp.png
Normal file
BIN
api/static/img/tmp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 160 KiB |
57
api/static/index.html
Normal file
57
api/static/index.html
Normal file
@@ -0,0 +1,57 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Clippable</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/purecss@2.0.6/build/pure-min.css" integrity="sha384-Uu6IeWbM+gzNVXJcM9XV3SohHtmWE+3VGi496jvgX1jyvDTXfdK+rfZc8C1Aehk5" crossorigin="anonymous">
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
<div class="content">
|
||||
<form class="pure-form">
|
||||
<h1>Clippable</h1>
|
||||
<fieldset>
|
||||
<input type="text" placeholder="Search"/>
|
||||
<button class="pure-button pure-button-primary">Search</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
<div class="video-gallery ">
|
||||
<div class="video-block">
|
||||
<h2>Video title</h2>
|
||||
<p>some random description that's actually really long for some reason</p>
|
||||
<img class="pure-img" src="/img/tmp.png">
|
||||
</div>
|
||||
<div class="video-block">
|
||||
<h2>Video title</h2>
|
||||
<p>some random description that's actually really long for some reason</p>
|
||||
<img class="pure-img" src="/img/tmp.png">
|
||||
</div>
|
||||
<div class="video-block">
|
||||
<h2>Video title</h2>
|
||||
<p>some random description that's actually really long for some reason</p>
|
||||
<img class="pure-img" src="/img/tmp.png">
|
||||
</div>
|
||||
<div class="video-block">
|
||||
<h2>Video title</h2>
|
||||
<p>some random description that's actually really long for some reason</p>
|
||||
<img class="pure-img" src="/img/tmp.png">
|
||||
</div>
|
||||
<div class="video-block">
|
||||
<h2>Video title</h2>
|
||||
<p>some random description that's actually really long for some reason</p>
|
||||
<img class="pure-img" src="/img/tmp.png">
|
||||
</div>
|
||||
<div class="video-block">
|
||||
<h2>Video title</h2>
|
||||
<p>some random description that's actually really long for some reason</p>
|
||||
<img class="pure-img" src="/img/tmp.png">
|
||||
</div>
|
||||
<div class="video-block">
|
||||
<h2>Video title</h2>
|
||||
<p>some random description that's actually really long for some reason</p>
|
||||
<img class="pure-img" src="/img/tmp.png">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
42
api/static/style.css
Normal file
42
api/static/style.css
Normal file
@@ -0,0 +1,42 @@
|
||||
html, body, div, tag {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
font-size: 100%;
|
||||
vertical-align: baseline;
|
||||
background: #212121;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.content {
|
||||
margin: 0 auto;
|
||||
padding: 0 2em;
|
||||
line-height: 1.6em;
|
||||
color: whitesmoke;
|
||||
}
|
||||
.video-gallery {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.video-block {
|
||||
padding: 1em;
|
||||
width: 400px;
|
||||
line-height: 1em;
|
||||
margin-right: 1em;
|
||||
margin-bottom: 1em;
|
||||
background: #191818;
|
||||
border-radius: 1em;
|
||||
}
|
||||
|
||||
.pure-form {
|
||||
text-align: center;
|
||||
}
|
||||
.pure-img {
|
||||
border-radius: 0.5em;
|
||||
}
|
||||
11
api/store.json
Normal file
11
api/store.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"keys":[
|
||||
{
|
||||
"name": "shockrah",
|
||||
"key": "asdf"
|
||||
}
|
||||
],
|
||||
"videos": {
|
||||
"video": { "name": "cool" }
|
||||
}
|
||||
}
|
||||
3
api/target/CACHEDIR.TAG
Normal file
3
api/target/CACHEDIR.TAG
Normal file
@@ -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/
|
||||
Reference in New Issue
Block a user