write playout config
This commit is contained in:
parent
b97f30c2b4
commit
c6f81fa8a3
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -667,7 +667,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ffplayout-engine"
|
||||
version = "0.9.8"
|
||||
version = "0.9.9"
|
||||
dependencies = [
|
||||
"actix-web",
|
||||
"actix-web-grants",
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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<T> {
|
||||
@ -26,37 +26,6 @@ struct ResponseObj<T> {
|
||||
data: Option<T>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Clone)]
|
||||
struct ResponsePlayoutConfig {
|
||||
general: Option<playout_config::General>,
|
||||
rpc_server: Option<playout_config::RpcServer>,
|
||||
mail: Option<playout_config::Mail>,
|
||||
logging: Option<playout_config::Logging>,
|
||||
processing: Option<playout_config::Processing>,
|
||||
ingest: Option<playout_config::Ingest>,
|
||||
playlist: Option<playout_config::Playlist>,
|
||||
storage: Option<playout_config::Storage>,
|
||||
text: Option<playout_config::Text>,
|
||||
out: Option<playout_config::Out>,
|
||||
}
|
||||
|
||||
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 <TOKEN>"
|
||||
#[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<i64>,
|
||||
details: AuthDetails<Role>,
|
||||
_details: AuthDetails<Role>,
|
||||
) -> Result<impl Responder, ServiceError> {
|
||||
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 { <CONFIG DATA> } --header 'Authorization: <TOKEN>'
|
||||
#[put("/playout/config/{id}")]
|
||||
#[has_any_role("Role::Admin", type = "Role")]
|
||||
async fn update_playout_config(
|
||||
id: web::Path<i64>,
|
||||
data: web::Json<PlayoutConfig>,
|
||||
) -> Result<impl Responder, ServiceError> {
|
||||
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": "<EMAIL>", "password": "<PASS>"}' --header 'Authorization: <TOKEN>'
|
||||
#[put("/user/{id}")]
|
||||
|
@ -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<Servi
|
||||
req.extensions_mut()
|
||||
.insert(LoginUser::new(claims.id, claims.username));
|
||||
|
||||
println!("{:#?}", req);
|
||||
Ok(req)
|
||||
}
|
||||
|
||||
@ -72,6 +74,7 @@ async fn main() -> 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),
|
||||
|
@ -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<Vec<String>>,
|
||||
|
||||
#[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<Vec<String>>,
|
||||
}
|
||||
|
||||
#[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<Vec<String>>,
|
||||
}
|
||||
|
||||
#[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<f64>,
|
||||
|
||||
pub length: String,
|
||||
|
||||
#[serde(skip_serializing, skip_deserializing)]
|
||||
pub length_sec: Option<f64>,
|
||||
|
||||
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<String>,
|
||||
@ -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<Vec<String>>,
|
||||
output_param: String,
|
||||
|
||||
pub output_param: String,
|
||||
|
||||
#[serde(skip_serializing, skip_deserializing)]
|
||||
pub output_cmd: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user