diff --git a/src/lib.rs b/src/lib.rs index 96656cb..1f33025 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ pub mod transform; pub mod logging; pub mod cache; pub mod routes; +pub mod webhooks; //pub mod proxy; pub mod timeout; pub mod headers; diff --git a/src/routes.rs b/src/routes.rs index 6495978..2f2493c 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -9,6 +9,7 @@ use crate::timeout::*; use crate::transform::*; use crate::url::*; use crate::utils::*; +use crate::webhooks; use itertools::Itertools; use moka::notification::RemovalCause; use moka::sync::Cache as MokaCacheSync; @@ -168,7 +169,7 @@ pub fn route() -> Router { ) .push( Router::new() - .path("/webhooks/plex") + .path("/replex/webhooks") .post(webhook_plex), ) .push( @@ -369,8 +370,13 @@ pub async fn webhook_plex( req: &mut Request, res: &mut Response, ) -> Result<(), anyhow::Error> { - let payload = req.form::("payload").await; + dbg!("YOOO"); + let raw = req.form::("payload").await; + let payload: webhooks::Payload = serde_json::from_str(&raw.unwrap())?; + dbg!(&req); dbg!(payload); + + // watchlist(); res.render(()); return Ok(()); } diff --git a/src/schema.gql b/src/schema.gql new file mode 100644 index 0000000..09cd381 --- /dev/null +++ b/src/schema.gql @@ -0,0 +1,181 @@ +schema { + query: Query + # mutation: Mutation +} + +# type Mutation +# type Query { +# popularTitles( +# country: String +# after: String +# offset: Boolean +# after: String +# # filter: $popularTitlesFilter +# sortBy: String # actuall an enum? +# ): # sortRandomSeed: $sortRandomSeed +# PopularTitlesConnection! +# } + +# type PopularTitlesConnection { +# "A list of edges." +# edges: [PopularTitlesEdge] + +# "A list of nodes." +# nodes: [UserContentEdit] + +# "Information to aid in pagination." +# pageInfo: PageInfo! + +# "Identifies the total count of items in the connection." +# totalCount: Int! +# } + +type PageInfo { + startCursor: String + endCursor: String + hasPreviousPage: Boolean + hasNextPage: Boolean + # __typename: String +} + +type User { + id: String + username: String +} + +# type WatchNowOffer { +# id: String +# standardWebURL: String +# retailPrice: String +# retailPriceValue: Float +# lastChangeRetailPriceValue: String +# currency: String +# presentationType: String +# monetizationType: String +# availableTo: String +# # __typename: String +# package: Package +# } + +# type Offers { +# id: String +# standardWebURL: String +# deeplinkURL(platform: Platform): String +# retailPrice: String +# retailPriceValue: Float +# lastChangeRetailPriceValue: Float +# currency: String +# presentationType: String +# monetizationType: String +# availableTo: String +# # __typename: String +# package: Package +# } + +# type Genres { +# translation: String +# # __typename: String +# } + +# type Credits { +# name: String +# personId: Int +# # __typename: String +# } + +# type Scoring { +# imdbVotes: Int +# imdbScore: Float +# tmdbPopularity: Float +# tmdbScore: Float +# # __typename: String +# } + +# type Content { +# title: String +# fullPath: String +# posterUrl: String +# # __typename: String +# isReleased: Boolean +# runtime: Int +# genres: [Genres] +# credits: [Credits] +# backdrops: [String] +# dailymotionClips: [String] +# scoring: Scoring +# externalIds: externalIds +# } + +# type Node { +# id: String +# objectId: Int +# objectType: String +# likelistEntry: String +# dislikelistEntry: String +# watchlistEntry: String +# seenlistEntry: String +# # __typename: String +# # watchNowOffer: WatchNowOffer +# # offers: [Offers] +# offers(country: String, platform: Platform!): [Offers] +# content(country: String, language: Language!): Content! +# } + +# type externalIds { +# tmdbId: String +# imdbId: String +# } + +# interface PopularTitlesEdge { +# cursor: String +# # __typename: String +# node: Node +# } + +# type PopularTitles { +# # sponsoredAd: String +# totalCount: Int +# # __typename: String +# pageInfo: PageInfo +# edges: [PopularTitlesEdge] +# } + +# type Query { +# popularTitles( +# country: Country! +# sortBy: PopularTitlesSorting! +# # language: Language +# after: String! +# first: Int! +# offset: Int +# # filter: $popularTitlesFilter +# ): PopularTitles! +# } + +# enum PopularTitlesSorting { +# ALPHABETICAL +# POPULAR +# } + +# enum Country { +# NL +# BE +# } + +# enum Language { +# nl +# be +# en +# } + +# enum Platform { +# IOS +# TVOS +# ANDROID +# WEB +# } + + +# type AutogeneratedMainType { +# data: Data +# } \ No newline at end of file diff --git a/src/webhooks.rs b/src/webhooks.rs new file mode 100644 index 0000000..d0e5e3c --- /dev/null +++ b/src/webhooks.rs @@ -0,0 +1,78 @@ +// use serde_derive::Deserialize; +// use serde_derive::Serialize; +use serde::{Deserialize, Deserializer, Serialize}; + +pub fn watchlist(payload: Payload) { + +} + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Payload { + pub event: String, + pub user: bool, + pub owner: bool, + #[serde(rename = "Account")] + pub account: Account, + #[serde(rename = "Server")] + pub server: Server, + #[serde(rename = "Player")] + pub player: Player, + #[serde(rename = "Metadata")] + pub metadata: Metadata, +} + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Account { + pub id: i64, + pub thumb: String, + pub title: String, +} + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Server { + pub title: String, + pub uuid: String, +} + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Player { + pub local: bool, + pub public_address: String, + pub title: String, + pub uuid: String, +} + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Metadata { + pub library_section_type: String, + pub rating_key: String, + pub key: String, + pub parent_rating_key: String, + pub grandparent_rating_key: String, + pub guid: String, + #[serde(rename = "librarySectionID")] + pub library_section_id: i64, + #[serde(rename = "type")] + pub type_field: String, + pub title: String, + pub grandparent_key: String, + pub parent_key: String, + pub grandparent_title: Option, + pub parent_title: Option, + pub summary: String, + pub index: i64, + pub parent_index: i64, + pub rating_count: i64, + pub thumb: String, + pub art: String, + pub parent_thumb: String, + pub grandparent_thumb: String, + pub grandparent_art: String, + pub added_at: i64, + pub updated_at: i64, +}