diff --git a/Cargo.lock b/Cargo.lock index dddebab0..e928f6bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -667,7 +667,7 @@ dependencies = [ [[package]] name = "ffplayout-engine" -version = "0.9.8" +version = "0.9.9" dependencies = [ "actix-web", "actix-web-grants", diff --git a/Cargo.toml b/Cargo.toml index 70c5ecff..f7fd7617 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ description = "24/7 playout based on rust and ffmpeg" license = "GPL-3.0" authors = ["Jonathan Baecker jonbae77@gmail.com"] readme = "README.md" -version = "0.9.8" +version = "0.9.9" edition = "2021" default-run = "ffplayout" diff --git a/src/api/routes.rs b/src/api/routes.rs index 82cd7a54..bb31379b 100644 --- a/src/api/routes.rs +++ b/src/api/routes.rs @@ -17,7 +17,7 @@ use crate::api::{ utils::{read_playout_config, Role}, }; -use crate::utils::playout_config; +use crate::utils::PlayoutConfig; #[derive(Serialize)] struct ResponseObj { @@ -26,37 +26,6 @@ struct ResponseObj { data: Option, } -#[derive(Debug, Serialize, Clone)] -struct ResponsePlayoutConfig { - general: Option, - rpc_server: Option, - mail: Option, - logging: Option, - processing: Option, - ingest: Option, - playlist: Option, - storage: Option, - text: Option, - out: Option, -} - -impl ResponsePlayoutConfig { - fn new() -> Self { - Self { - general: None, - rpc_server: None, - mail: None, - logging: None, - processing: None, - ingest: None, - playlist: None, - storage: None, - text: None, - out: None, - } - } -} - /// curl -X GET http://127.0.0.1:8080/api/settings/1 -H "Authorization: Bearer " #[get("/settings/{id}")] #[has_any_role("Role::Admin", "Role::User", type = "Role")] @@ -94,35 +63,42 @@ async fn patch_settings( #[has_any_role("Role::Admin", "Role::User", type = "Role")] async fn get_playout_config( id: web::Path, - details: AuthDetails, + _details: AuthDetails, ) -> Result { if let Ok(settings) = db_get_settings(&id).await { if let Ok(config) = read_playout_config(&settings.config_path) { - let mut playout_cfg = ResponsePlayoutConfig::new(); - - playout_cfg.playlist = Some(config.playlist); - playout_cfg.storage = Some(config.storage); - playout_cfg.text = Some(config.text); - - if details.has_role(&Role::Admin) { - playout_cfg.general = Some(config.general); - playout_cfg.rpc_server = Some(config.rpc_server); - playout_cfg.mail = Some(config.mail); - playout_cfg.logging = Some(config.logging); - playout_cfg.processing = Some(config.processing); - playout_cfg.ingest = Some(config.ingest); - playout_cfg.out = Some(config.out); - - return Ok(web::Json(playout_cfg)); - } - - return Ok(web::Json(playout_cfg)); + return Ok(web::Json(config)); } }; Err(ServiceError::InternalServerError) } +/// curl -X PUT http://localhost:8080/api/playout/config/1 -H "Content-Type: application/json" \ +/// --data { } --header 'Authorization: ' +#[put("/playout/config/{id}")] +#[has_any_role("Role::Admin", type = "Role")] +async fn update_playout_config( + id: web::Path, + data: web::Json, +) -> Result { + if let Ok(settings) = db_get_settings(&id).await { + if let Ok(f) = std::fs::OpenOptions::new() + .write(true) + .truncate(true) + .open(&settings.config_path) + { + serde_yaml::to_writer(f, &data).unwrap(); + + return Ok("Update playout config success."); + } else { + return Err(ServiceError::InternalServerError); + }; + }; + + Err(ServiceError::InternalServerError) +} + /// curl -X PUT http://localhost:8080/api/user/1 --header 'Content-Type: application/json' \ /// --data '{"email": "", "password": ""}' --header 'Authorization: ' #[put("/user/{id}")] diff --git a/src/bin/ffpapi.rs b/src/bin/ffpapi.rs index 007b4bcb..a24d7574 100644 --- a/src/bin/ffpapi.rs +++ b/src/bin/ffpapi.rs @@ -13,7 +13,10 @@ use ffplayout_engine::{ args_parse::Args, auth, models::LoginUser, - routes::{add_user, get_playout_config, get_settings, login, patch_settings, update_user}, + routes::{ + add_user, get_playout_config, get_settings, login, patch_settings, + update_playout_config, update_user, + }, utils::{db_path, init_config, run_args, Role}, }, utils::{init_logging, PlayoutConfig}, @@ -27,7 +30,6 @@ async fn validator(req: ServiceRequest, credentials: BearerAuth) -> Result std::io::Result<()> { .wrap(auth) .service(add_user) .service(get_playout_config) + .service(update_playout_config) .service(get_settings) .service(patch_settings) .service(update_user), diff --git a/src/utils/config.rs b/src/utils/config.rs index 950cb48b..b6991ab8 100644 --- a/src/utils/config.rs +++ b/src/utils/config.rs @@ -30,7 +30,10 @@ pub struct PlayoutConfig { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct General { + pub help_text: String, pub stop_threshold: f64, + + #[serde(skip_serializing, skip_deserializing)] pub generate: Option>, #[serde(skip_serializing, skip_deserializing)] @@ -39,6 +42,7 @@ pub struct General { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct RpcServer { + pub help_text: String, pub enable: bool, pub address: String, pub authorization: String, @@ -46,6 +50,7 @@ pub struct RpcServer { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Mail { + pub help_text: String, pub subject: String, pub smtp_server: String, pub starttls: bool, @@ -58,6 +63,7 @@ pub struct Mail { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Logging { + pub help_text: String, pub log_to_file: bool, pub backup_count: usize, pub local_time: bool, @@ -69,6 +75,7 @@ pub struct Logging { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Processing { + pub help_text: String, pub mode: String, pub width: i64, pub height: i64, @@ -85,28 +92,41 @@ pub struct Processing { pub loud_tp: f32, pub loud_lra: f32, pub volume: f64, + + #[serde(skip_serializing, skip_deserializing)] pub settings: Option>, } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Ingest { + pub help_text: String, pub enable: bool, input_param: String, + + #[serde(skip_serializing, skip_deserializing)] pub input_cmd: Option>, } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Playlist { + pub help_text: String, pub path: String, pub day_start: String, + + #[serde(skip_serializing, skip_deserializing)] pub start_sec: Option, + pub length: String, + + #[serde(skip_serializing, skip_deserializing)] pub length_sec: Option, + pub infinit: bool, } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Storage { + pub help_text: String, pub path: String, pub filler_clip: String, pub extensions: Vec, @@ -115,6 +135,7 @@ pub struct Storage { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Text { + pub help_text: String, pub add_text: bool, pub over_pre: bool, pub bind_address: String, @@ -126,11 +147,17 @@ pub struct Text { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Out { + pub help_text: String, pub mode: String, pub preview: bool, - preview_param: String, + pub preview_param: String, + + #[serde(skip_serializing, skip_deserializing)] pub preview_cmd: Option>, - output_param: String, + + pub output_param: String, + + #[serde(skip_serializing, skip_deserializing)] pub output_cmd: Option>, }