Skip to content

Commit

Permalink
feat(backend): jellyfin payload structure for movies
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Jul 18, 2023
1 parent 30c4872 commit fceb2ca
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
15 changes: 12 additions & 3 deletions apps/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,18 @@ async fn export(
async fn jellyfin_webhook(
Path(integration_slug): Path<String>,
Extension(media_service): Extension<Arc<MiscellaneousService>>,
) -> Result<Json<serde_json::Value>, (StatusCode, Json<serde_json::Value>)> {
dbg!(&integration_slug);
todo!()
// DEV: jellyfin does not send the `Content-Type: application/json` header,
// so we consume the body as a string
payload: String,
) -> std::result::Result<StatusCode, StatusCode> {
media_service
.process_jellyfin_event(payload, integration_slug)
.await
.map_err(|e| {
tracing::error!("{:?}", e);
StatusCode::UNPROCESSABLE_ENTITY
})?;
Ok(StatusCode::OK)
}

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down
36 changes: 35 additions & 1 deletion apps/backend/src/miscellaneous/resolver.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use std::{collections::HashSet, sync::Arc};
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};

use anyhow::Result as AnyhowResult;
use apalis::{prelude::Storage as ApalisStorage, sqlite::SqliteStorage};
use argon2::{Argon2, PasswordHash, PasswordVerifier};
use async_graphql::{Context, Enum, Error, InputObject, Object, Result, SimpleObject, Union};
Expand Down Expand Up @@ -3503,6 +3507,36 @@ impl MiscellaneousService {
Ok(false)
}
}

pub async fn process_jellyfin_event(
&self,
payload: String,
integration_slug: String,
) -> AnyhowResult<()> {
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "PascalCase")]
struct JellyfinWebhookItemUserDataPayload {
played_percentage: Option<Decimal>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "PascalCase")]
struct JellyfinWebhookItemPayload {
#[serde(rename = "Type")]
item_type: String,
provider_ids: HashMap<String, String>,
user_data: JellyfinWebhookItemUserDataPayload,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "PascalCase")]
struct JellyfinWebhookPayload {
event: Option<String>,
item: JellyfinWebhookItemPayload,
}

let payload = serde_json::from_str::<JellyfinWebhookPayload>(&payload)?;
dbg!(&payload, &integration_slug);
Ok(())
}
}

fn modify_seen_elements(all_seen: &mut [seen::Model]) {
Expand Down

0 comments on commit fceb2ca

Please sign in to comment.