diff --git a/Makefile b/Makefile index d62d852..0869a49 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ run: REPLEX_ENABLE_CONSOLE=0 \ REPLEX_CACHE_TTL=0 \ REPLEX_NTF_WATCHLIST_FORCE=1 \ - RUST_LOG="info,replex=debug" \ + RUST_LOG="info,replex=info" \ RUSTFLAGS=-Awarnings \ cargo watch -x run diff --git a/src/models.rs b/src/models.rs index ea5c766..5a2d8b9 100644 --- a/src/models.rs +++ b/src/models.rs @@ -126,6 +126,8 @@ pub struct PlexContext { #[serde(default="default_platform")] #[salvo(extract(rename = "X-Plex-Platform"))] pub platform: Platform, + #[salvo(extract(rename = "X-Plex-Username"))] + pub username: Option, #[serde(default, deserialize_with = "deserialize_screen_resolution")] #[salvo(extract(rename = "X-Plex-Device-Screen-Resolution"))] pub screen_resolution: Vec, @@ -1180,7 +1182,7 @@ pub struct MetaData { #[serde(rename = "Guid", default, skip_serializing_if = "Vec::is_empty")] #[yaserde(rename = "Guid", default, child)] pub guids: Vec, - #[yaserde(attribute, rename = "userState")] + #[yaserde(attribute, rename = "State")] #[serde(skip_serializing_if = "Option::is_none")] pub user_state: Option, #[serde(rename = "Image", default, skip_serializing_if = "Vec::is_empty")] diff --git a/src/routes.rs b/src/routes.rs index f6f7c82..991f3f3 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -323,22 +323,28 @@ async fn ntf_watchlist_force( res: &mut Response, ctrl: &mut FlowCtrl, ) { - let params: PlexContext = req.extract().await.unwrap(); - tokio::spawn(async move { - let url = format!("https://notifications.plex.tv/api/v1/notifications/settings?X-Plex-Client-Identifier={}&X-Plex-Token={}", params.clone().client_identifier.unwrap(),params.clone().token.unwrap()); - let json_data = r#"{"enabled": true,"libraries": [],"identifier": "tv.plex.notification.library.new"}"#; - let client = reqwest::Client::new(); - let response = client - .post(url) - .header("Content-Type", "application/json") - .body(json_data.to_owned()) - .send() - .await - .unwrap(); - - //println!("Status: {}", response.status()); - }); + let params: PlexContext = req.extract().await.unwrap(); + if params.clone().client_identifier.is_some() && params.clone().token.is_some() { + tokio::spawn(async move { + let url = format!("https://notifications.plex.tv/api/v1/notifications/settings?X-Plex-Client-Identifier={}&X-Plex-Token={}", params.clone().client_identifier.unwrap(),params.clone().token.unwrap()); + let json_data = r#"{"enabled": true,"libraries": [],"identifier": "tv.plex.notification.library.new"}"#; + let client = reqwest::Client::new(); + + let response = client + .post(url) + .header("Content-Type", "application/json") + .body(json_data.to_owned()) + .send() + .await + .unwrap(); + + println!("Set watchlist for user: {} platform: {}", + params.clone().username.unwrap_or_default(), + params.clone().platform + ); + }); + } } #[handler]