2023-10-25 13:27:15 +02:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
use std::sync::{Arc, Mutex};
|
2023-10-09 00:17:54 +02:00
|
|
|
use actix_web::web;
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
2023-10-26 21:19:56 +02:00
|
|
|
use crate::model::api_proxy::{ApiProxyConfig};
|
2023-11-05 20:19:37 +01:00
|
|
|
use crate::model::config::{Config, ConfigTargetOptions, ConfigRename, ConfigSort, InputType, ProcessTargets, TargetOutput, VideoConfig};
|
2023-10-25 09:57:44 +02:00
|
|
|
use crate::model::model_config::{default_as_empty_str, ProcessingOrder};
|
2023-10-09 00:17:54 +02:00
|
|
|
|
|
|
|
|
pub(crate) struct AppState {
|
2023-10-19 18:56:08 +02:00
|
|
|
pub config: Arc<Config>,
|
|
|
|
|
pub targets: Arc<ProcessTargets>,
|
2023-10-25 13:27:15 +02:00
|
|
|
pub downloads: Arc<Mutex<HashMap<String, u64>>>
|
2023-10-09 00:17:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
|
pub(crate) struct XtreamUserInfo {
|
2023-10-26 19:50:35 +02:00
|
|
|
pub active_cons: String,
|
2023-10-09 00:17:54 +02:00
|
|
|
pub allowed_output_formats: Vec<String>, //["ts"],
|
|
|
|
|
pub auth: u16, // 0 | 1
|
|
|
|
|
pub created_at: i64, //1623429679,
|
|
|
|
|
pub exp_date: i64, //1628755200,
|
2023-10-26 19:50:35 +02:00
|
|
|
pub is_trial: String, // 0 | 1
|
|
|
|
|
pub max_connections: String,
|
2023-10-09 00:17:54 +02:00
|
|
|
pub message: String,
|
|
|
|
|
pub password: String,
|
|
|
|
|
pub username: String,
|
|
|
|
|
pub status: String, // "Active"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
|
pub(crate) struct XtreamServerInfo {
|
|
|
|
|
pub url: String,
|
2023-10-26 19:50:35 +02:00
|
|
|
pub port: String,
|
|
|
|
|
pub https_port: String,
|
2023-10-09 00:17:54 +02:00
|
|
|
pub server_protocol: String, // http, https
|
2023-10-26 19:50:35 +02:00
|
|
|
pub rtmp_port: String,
|
2023-10-09 00:17:54 +02:00
|
|
|
pub timezone:String,
|
|
|
|
|
pub timestamp_now:i64,
|
|
|
|
|
pub time_now: String, //"2021-06-28 17:07:37"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
|
pub(crate) struct XtreamAuthorizationResponse {
|
|
|
|
|
pub user_info: XtreamUserInfo,
|
|
|
|
|
pub server_info: XtreamServerInfo,
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-23 09:58:36 +02:00
|
|
|
|
2023-10-25 21:07:38 +02:00
|
|
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
2023-10-23 09:58:36 +02:00
|
|
|
pub(crate) struct UserApiRequest {
|
|
|
|
|
#[serde(default = "default_as_empty_str")]
|
|
|
|
|
pub username: String,
|
|
|
|
|
#[serde(default = "default_as_empty_str")]
|
|
|
|
|
pub password: String,
|
|
|
|
|
#[serde(default = "default_as_empty_str")]
|
|
|
|
|
pub token: String,
|
|
|
|
|
#[serde(default = "default_as_empty_str")]
|
|
|
|
|
pub action: String,
|
2023-10-25 09:57:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
|
|
|
|
pub(crate) struct ServerInputConfig {
|
|
|
|
|
pub id: u16,
|
|
|
|
|
pub input_type: InputType,
|
|
|
|
|
pub url: String,
|
|
|
|
|
pub username: Option<String>,
|
|
|
|
|
pub password: Option<String>,
|
|
|
|
|
pub persist: Option<String>,
|
|
|
|
|
pub name: Option<String>,
|
|
|
|
|
pub enabled: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
|
|
|
|
pub(crate) struct ServerTargetConfig {
|
|
|
|
|
pub id: u16,
|
|
|
|
|
pub enabled: bool,
|
|
|
|
|
pub name: String,
|
2023-11-05 20:19:37 +01:00
|
|
|
pub options: Option<ConfigTargetOptions>,
|
2023-10-25 09:57:44 +02:00
|
|
|
pub sort: Option<ConfigSort>,
|
|
|
|
|
pub filter: String,
|
|
|
|
|
#[serde(alias = "type")]
|
|
|
|
|
pub output: Vec<TargetOutput>,
|
|
|
|
|
pub rename: Option<Vec<ConfigRename>>,
|
|
|
|
|
pub mapping: Option<Vec<String>>,
|
|
|
|
|
pub processing_order: ProcessingOrder,
|
|
|
|
|
pub watch: Option<Vec<String>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
|
|
|
|
pub(crate) struct ServerSourceConfig {
|
|
|
|
|
pub inputs: Vec<ServerInputConfig>,
|
|
|
|
|
pub targets: Vec<ServerTargetConfig>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
|
|
|
|
pub(crate) struct ServerConfig {
|
|
|
|
|
pub sources: Vec<ServerSourceConfig>,
|
|
|
|
|
pub video: Option<VideoConfig>,
|
2023-10-26 21:19:56 +02:00
|
|
|
pub api_proxy: Option<ApiProxyConfig>
|
2023-10-25 09:57:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
|
|
|
|
pub(crate) struct PlaylistRequest {
|
|
|
|
|
pub url: Option<String>,
|
|
|
|
|
pub input_id: Option<u16>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<web::Json<PlaylistRequest>> for PlaylistRequest {
|
|
|
|
|
fn from(req: web::Json<PlaylistRequest>) -> Self {
|
|
|
|
|
req.clone()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
|
|
|
|
pub(crate) struct FileDownloadRequest {
|
|
|
|
|
pub url: String,
|
|
|
|
|
pub filename: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<web::Json<FileDownloadRequest>> for FileDownloadRequest {
|
|
|
|
|
fn from(req: web::Json<FileDownloadRequest>) -> Self {
|
|
|
|
|
req.clone()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|