This commit is contained in:
parent
5c84875dd9
commit
a4c913eedc
@ -9,7 +9,10 @@ use rocket::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::DBPool;
|
use crate::DBPool;
|
||||||
use crate::{utils::ApiResponse, ASender, Action, DBConn};
|
use crate::{
|
||||||
|
utils::{ApiResponse, ApiResponseActiveList},
|
||||||
|
AReceiver, ASender, Action, DBConn, RenderMessage,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
@ -457,7 +460,6 @@ pub fn get_animation(name: &str, db: &State<DBPool>) -> Result<Option<Animation>
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
println!("got here 2");
|
println!("got here 2");
|
||||||
|
|
||||||
let mut animation = next.unwrap()?;
|
let mut animation = next.unwrap()?;
|
||||||
@ -482,7 +484,6 @@ pub fn get_animation(name: &str, db: &State<DBPool>) -> Result<Option<Animation>
|
|||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
||||||
println!("got here 4");
|
println!("got here 4");
|
||||||
|
|
||||||
while let Some(key_frame_id) = map.next() {
|
while let Some(key_frame_id) = map.next() {
|
||||||
@ -511,7 +512,6 @@ pub fn get_animation(name: &str, db: &State<DBPool>) -> Result<Option<Animation>
|
|||||||
animation.animation.key_frames.push(key_frame_id.keyframe);
|
animation.animation.key_frames.push(key_frame_id.keyframe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
println!("got here 6");
|
println!("got here 6");
|
||||||
|
|
||||||
Ok(Some(animation.animation))
|
Ok(Some(animation.animation))
|
||||||
@ -550,3 +550,45 @@ pub fn remove_animation(name: &str, db: &State<DBPool>) -> Result<(), Box<dyn Er
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/active")]
|
||||||
|
pub async fn get_active(
|
||||||
|
action: &State<ASender<Action>>,
|
||||||
|
messages: &State<AReceiver<RenderMessage>>,
|
||||||
|
) -> String {
|
||||||
|
println!("Getting active");
|
||||||
|
|
||||||
|
let send = action.lock().unwrap().send(Action::GetActiveList);
|
||||||
|
|
||||||
|
if send.is_err() || send.ok().is_none() {
|
||||||
|
return json!(ApiResponse {
|
||||||
|
code: 500,
|
||||||
|
message: "Failed to get list".to_string()
|
||||||
|
})
|
||||||
|
.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = messages.lock().unwrap().recv();
|
||||||
|
|
||||||
|
if data.is_err() || data.as_ref().ok().is_none() {
|
||||||
|
return json!(ApiResponse {
|
||||||
|
code: 500,
|
||||||
|
message: "Failed to get list".to_string()
|
||||||
|
})
|
||||||
|
.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
if let RenderMessage::ActiveList(list) = data.ok().unwrap() {
|
||||||
|
return json!(ApiResponseActiveList {
|
||||||
|
code: 200,
|
||||||
|
active_animations: list
|
||||||
|
})
|
||||||
|
.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
return json!(ApiResponse {
|
||||||
|
code: 500,
|
||||||
|
message: "Failed to get list".to_string()
|
||||||
|
})
|
||||||
|
.to_string();
|
||||||
|
}
|
||||||
|
53
src/main.rs
53
src/main.rs
@ -5,15 +5,15 @@ use ::std::sync::Arc;
|
|||||||
|
|
||||||
mod animations;
|
mod animations;
|
||||||
mod configure;
|
mod configure;
|
||||||
|
mod db;
|
||||||
mod render;
|
mod render;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod db;
|
|
||||||
|
|
||||||
use animations::Animation;
|
use animations::Animation;
|
||||||
use r2d2::PooledConnection;
|
use r2d2::PooledConnection;
|
||||||
use utils::{ApiResponse, ApiResponseActiveList};
|
use utils::ApiResponse;
|
||||||
|
|
||||||
use rocket::{serde::json::{serde_json::json, self}, State};
|
use rocket::{serde::json::serde_json::json, State};
|
||||||
|
|
||||||
use r2d2_sqlite::SqliteConnectionManager;
|
use r2d2_sqlite::SqliteConnectionManager;
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ pub enum Action {
|
|||||||
pub enum RenderMessage {
|
pub enum RenderMessage {
|
||||||
ActiveList(Vec<String>),
|
ActiveList(Vec<String>),
|
||||||
// TODO remove none where other are added
|
// TODO remove none where other are added
|
||||||
None
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/quit")]
|
#[get("/quit")]
|
||||||
@ -97,42 +97,6 @@ async fn reload(action: &State<ASender<Action>>) -> String {
|
|||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/active")]
|
|
||||||
async fn get_active(action: &State<ASender<Action>>, messages: &State<AReceiver<RenderMessage>>) -> String {
|
|
||||||
println!("Getting active");
|
|
||||||
|
|
||||||
let send = action.lock().unwrap().send(Action::GetActiveList);
|
|
||||||
|
|
||||||
if send.is_err() || send.ok().is_none() {
|
|
||||||
return json!(ApiResponse{
|
|
||||||
code: 500,
|
|
||||||
message: "Failed to get list".to_string()
|
|
||||||
}).to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
let data = messages.lock().unwrap().recv();
|
|
||||||
|
|
||||||
if data.is_err() || data.as_ref().ok().is_none() {
|
|
||||||
return json!(ApiResponse {
|
|
||||||
code: 500,
|
|
||||||
message: "Failed to get list".to_string()
|
|
||||||
}).to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let RenderMessage::ActiveList(list) = data.ok().unwrap() {
|
|
||||||
return json!(ApiResponseActiveList {
|
|
||||||
code: 200,
|
|
||||||
active_animations: list
|
|
||||||
}).to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
return json!(ApiResponse {
|
|
||||||
code: 500,
|
|
||||||
message: "Failed to get list".to_string()
|
|
||||||
}).to_string();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ligth_controll(
|
fn ligth_controll(
|
||||||
pool: DBPool,
|
pool: DBPool,
|
||||||
action: Receiver<Action>,
|
action: Receiver<Action>,
|
||||||
@ -171,7 +135,10 @@ fn ligth_controll(
|
|||||||
break 'mainloop;
|
break 'mainloop;
|
||||||
}
|
}
|
||||||
Action::GetActiveList => {
|
Action::GetActiveList => {
|
||||||
if message_server.send(RenderMessage::ActiveList(render.get_active_animations())).is_err() {
|
if message_server
|
||||||
|
.send(RenderMessage::ActiveList(render.get_active_animations()))
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
println!("Failed to send message ups");
|
println!("Failed to send message ups");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,7 +166,6 @@ fn ligth_controll(
|
|||||||
println!("stoped main loop");
|
println!("stoped main loop");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::main]
|
||||||
async fn main() -> GResult {
|
async fn main() -> GResult {
|
||||||
println!("Program start");
|
println!("Program start");
|
||||||
@ -235,7 +201,7 @@ async fn main() -> GResult {
|
|||||||
action_receiver,
|
action_receiver,
|
||||||
start_animation_receiver,
|
start_animation_receiver,
|
||||||
stop_animation_receiver,
|
stop_animation_receiver,
|
||||||
messager_sender
|
messager_sender,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -251,6 +217,7 @@ async fn main() -> GResult {
|
|||||||
quit,
|
quit,
|
||||||
reload,
|
reload,
|
||||||
configure::configure,
|
configure::configure,
|
||||||
|
animations::get_active,
|
||||||
animations::animation,
|
animations::animation,
|
||||||
animations::start_animation,
|
animations::start_animation,
|
||||||
animations::stop_animation,
|
animations::stop_animation,
|
||||||
|
Loading…
Reference in New Issue
Block a user