This commit is contained in:
Daniel Løvbrøtte Olsen
2020-03-25 22:30:22 +01:00
parent a1512e6889
commit a4ab569437
4 changed files with 393 additions and 28 deletions

View File

@@ -1,23 +1,70 @@
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
use rocket::State;
use rocket::response::status::NotFound;
use rocket_contrib::json::Json;
use serde_json::Value;
use std::path::PathBuf;
use std::sync::Mutex;
mod workunit;
use workunit::WUnit;
const VERSION: &str = "0.1.0";
#[derive(Default, Debug)]
struct SharedState {
list: Mutex<Vec<WUnit>>
}
#[get("/")]
fn index() -> &'static str {
"Welcome to the AV1 Encoder Master Server"
}
#[get("/get_work/<max_length>")]
fn getJobs(max_length: u32, ) -> Result<String, std::io::Error> {
let mut work = WUnit::default();
Ok(format!("{:#?}", work))
#[get("/version")]
fn version() -> &'static str {
"0.1.0"
}
#[get("/get_jobs")]
fn getJobs(shared: State<SharedState>) -> Json<Value> {
// let shared_data: &SharedState = shared.inner();
let list = shared.list.lock().unwrap();
println!("get jobs blah");
// println!("{:#?}", Json(list));
Json(serde_json::to_value(&list[..]).unwrap())
}
#[get("/get_job/<id>")]
fn getJob(id: usize, shared: State<SharedState>) -> Result<String, NotFound<String>> {
let shared_data: &SharedState = shared.inner();
let list = shared_data.list.lock().unwrap();
let job = list.get(id).ok_or(NotFound(format!("Job not Found: {id}", id = id)));
match job {
Ok(j) => Ok(format!("{:#?}", j)),
Err(e) => Err(e)
}
}
#[get("/add_job")]
fn addJob(shared: State<SharedState>) -> Result<String, std::io::Error> {
let shared_data: &SharedState = shared.inner();
shared_data.list.lock().unwrap().push(WUnit::default());
Ok(format!("{:#?}", shared_data))
}
fn main() {
rocket::ignite().mount("/", routes![index, getJobs]).launch();
rocket::ignite()
.manage(SharedState::default())
.mount("/", routes![index, version, getJobs, getJob, addJob])
.launch();
}

View File

@@ -1,6 +1,7 @@
use std::path::PathBuf;
use serde::{Serialize, Deserialize};
#[derive(Default, Debug)]
#[derive(Default, Debug, Serialize, Deserialize)]
pub struct WUnit {
file_name: PathBuf,
priority: u16,
@@ -10,7 +11,7 @@ pub struct WUnit {
}
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
struct EOptions {
mode: EMode,
resolution: Resolution,
@@ -36,7 +37,7 @@ impl Default for EOptions {
}
}
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
enum EMode {
// Quality (CRF), Constrained Quality, Variable Bitrate, Constant Bitrate
Q(u8),
@@ -50,13 +51,13 @@ impl Default for EMode {
}
}
#[derive(Default, Debug)]
#[derive(Default, Debug, Serialize, Deserialize)]
struct Resolution {
width: Option<u16>,
height: Option<u16>
}
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
enum EColorDepth {
Eight = 8,
Ten = 10,
@@ -68,7 +69,7 @@ impl Default for EColorDepth {
}
}
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
enum EStatus {
Queued,
Reserved,