From b0713662adca46797ff9c6f3758d1ef30f2963ef Mon Sep 17 00:00:00 2001 From: euzu Date: Thu, 25 Apr 2024 11:01:52 +0200 Subject: [PATCH] when rewriting m3u paylist, if index files are missing, the original file will be served. --- Cargo.toml | 2 +- frontend/src/config.ts | 2 +- src/api/api_model.rs | 43 +++++++++++++++++++++++++++++++- src/api/m3u_api.rs | 2 ++ src/api/v1_api.rs | 2 +- src/repository/m3u_repository.rs | 11 ++++++-- 6 files changed, 56 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2a8379142..527555414 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ panic = 'abort' # Abort on panic [dependencies] serde = { version = "1.0", features = ["derive", "rc"] } -serde_yaml = "0" +serde_yaml = "0.9.1" serde_json = "1" serde-xml-rs = "0" quick-xml = { version = "0", features = ["serialize"] } diff --git a/frontend/src/config.ts b/frontend/src/config.ts index c42b68c12..dea3a7092 100644 --- a/frontend/src/config.ts +++ b/frontend/src/config.ts @@ -5,7 +5,7 @@ const dev = { version: process.env.REACT_APP_VERSION, }, api: { - serverUrl: 'http://10.41.41.41:8901/api/v1/', + serverUrl: 'http://localhost:8901/api/v1/', } }; diff --git a/src/api/api_model.rs b/src/api/api_model.rs index af9553f23..f73d3e843 100644 --- a/src/api/api_model.rs +++ b/src/api/api_model.rs @@ -133,7 +133,7 @@ impl SharedLocks { } } let mut lock = self.shared_locks.write().unwrap(); - let file = Arc::new(RwLock::new(key.to_string() )); + let file = Arc::new(RwLock::new(key.to_string())); lock.insert(key.to_string(), file.clone()); file } @@ -192,6 +192,47 @@ pub(crate) struct XtreamAuthorizationResponse { pub server_info: XtreamServerInfo, } +// macro_rules! create_user_api { +// ($name:ident { $($field:ident : $field_type:ty),* $(,)? }) => { +// #[derive(Debug, serde::Serialize, serde::Deserialize)] +// pub(crate) struct $name { +// $( +// #[serde(default = "default_as_empty_str")] +// pub $field : $field_type +// ),* +// } +// +// impl $name { +// pub fn from_map(map: &HashMap) -> Self { +// let mut fields = HashMap::new(); +// $( +// if let Some(value) = map.get(stringify!($field)) { +// fields.insert(stringify!($field).to_string(), value.clone()); +// } +// )* +// Self { +// $( +// $field: fields.remove(stringify!($field)).unwrap_or_default(), +// )* +// } +// } +// } +// }; +// } +// +// create_user_api!( +// UserApiRequest { +// username: String, +// password: String, +// token: String, +// action: String, +// series_id: String, +// vod_id: String, +// stream_id: String, +// category_id: String, +// limit: String, +// }); + #[derive(Debug, serde::Serialize, serde::Deserialize)] pub(crate) struct UserApiRequest { diff --git a/src/api/m3u_api.rs b/src/api/m3u_api.rs index 0d3ccf26b..99df4b2a3 100644 --- a/src/api/m3u_api.rs +++ b/src/api/m3u_api.rs @@ -9,9 +9,11 @@ use crate::repository::m3u_repository::{get_m3u_file_paths, get_m3u_url_for_stre async fn m3u_api( api_req: web::Query, + //_api_req: web::Query>, req: HttpRequest, app_state: web::Data, ) -> HttpResponse { + //let api_req = UserApiRequest::from_map(&_api_req); match get_user_target(&api_req, &app_state) { Some((user, target)) => { let filename = target.get_m3u_filename(); diff --git a/src/api/v1_api.rs b/src/api/v1_api.rs index 72d343f7e..5b5b868b5 100644 --- a/src/api/v1_api.rs +++ b/src/api/v1_api.rs @@ -35,7 +35,7 @@ fn _save_config_main(file_path: &str, backup_dir: &str, cfg: &ConfigDto) -> Opti } pub(crate) async fn save_config_api_proxy_user( - mut req: web::Json>, + req: web::Json>, app_state: web::Data, ) -> HttpResponse { let mut users = req.0; diff --git a/src/repository/m3u_repository.rs b/src/repository/m3u_repository.rs index 852bdcb1d..41df264ba 100644 --- a/src/repository/m3u_repository.rs +++ b/src/repository/m3u_repository.rs @@ -240,7 +240,6 @@ pub(crate) fn write_strm_playlist(target: &ConfigTarget, cfg: &Config, new_playl Ok(()) } - pub(crate) fn rewrite_m3u_playlist(cfg: &Config, target: &ConfigTarget, user: &UserCredentials) -> Option { let filename = target.get_m3u_filename(); if filename.is_some() { @@ -265,7 +264,15 @@ pub(crate) fn rewrite_m3u_playlist(cfg: &Config, target: &ConfigTarget, user: &U } } return Some(result.join("\n")); - }; + } else if m3u_path.exists() { + match std::fs::read_to_string(&m3u_path) { + Ok(result) => return Some(result), + Err(err) => { + error!("Could not open file {}: {}", &m3u_path.to_str().unwrap(), err); + return None; + } + } + } } } None