From b8895fbae922225f2364fa176227331fb90adb38 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sat, 11 Apr 2026 20:19:54 -0400 Subject: [PATCH] begin to extract contents --- .../parse_webhook_inner_payload.rs | 19 ++++++++++-- .../payload/webhook_inner_payload.rs | 29 +++++++++++++++++++ .../webhooks/success/images_payload_1.json | 26 +++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 crates/api_clients/fal_client/test_data/webhooks/success/images_payload_1.json diff --git a/crates/api_clients/fal_client/src/webhook_api/parse_webhook_inner_payload.rs b/crates/api_clients/fal_client/src/webhook_api/parse_webhook_inner_payload.rs index 85554dab35..8231e1a710 100644 --- a/crates/api_clients/fal_client/src/webhook_api/parse_webhook_inner_payload.rs +++ b/crates/api_clients/fal_client/src/webhook_api/parse_webhook_inner_payload.rs @@ -1,7 +1,7 @@ use serde_json::Value; use crate::webhook_api::payload::webhook_error_type::WebhookErrorType; -use crate::webhook_api::payload::webhook_inner_payload::{ErrorData, PayloadErrorData, SuccessData, WebhookInnerPayload}; +use crate::webhook_api::payload::webhook_inner_payload::{ErrorData, ExtractedContents, PayloadErrorData, SuccessData, WebhookInnerPayload}; use crate::webhook_api::payload::webhook_payload::{WebhookPayload, WebhookStatus}; /// Parse the inner payload of a FAL webhook into one of three cases. @@ -20,7 +20,7 @@ pub fn parse_webhook_inner_payload(webhook: &WebhookPayload) -> WebhookInnerPayl }) } WebhookStatus::Ok => { - // Check for payload_error case: status=OK but no payload, has payload_error. + // Check for `payload_error` case: status=OK but no payload, has payload_error. if webhook.payload.is_none() { if let Some(ref payload_error) = webhook.payload_error { return WebhookInnerPayload::PayloadError(PayloadErrorData { @@ -28,9 +28,22 @@ pub fn parse_webhook_inner_payload(webhook: &WebhookPayload) -> WebhookInnerPayl }); } } + + let value = webhook.payload + .clone() + .unwrap_or(Value::Null); + + let mut extracted_contents = ExtractedContents { + image: None, + images: None, + video: None, + model_glb: None, + model_mesh: None, + }; WebhookInnerPayload::Success(SuccessData { - payload: webhook.payload.clone().unwrap_or(Value::Null), + payload: value, + extracted_contents, }) } } diff --git a/crates/api_clients/fal_client/src/webhook_api/payload/webhook_inner_payload.rs b/crates/api_clients/fal_client/src/webhook_api/payload/webhook_inner_payload.rs index 6cc94e5ddb..c0c4c26dd6 100644 --- a/crates/api_clients/fal_client/src/webhook_api/payload/webhook_inner_payload.rs +++ b/crates/api_clients/fal_client/src/webhook_api/payload/webhook_inner_payload.rs @@ -22,7 +22,36 @@ pub enum WebhookInnerPayload { pub struct SuccessData { /// The success data is polymorphic, so we're returning a JSON `Value` for now. /// This will allow for downstream handlers to parse the payload as needed. + /// This is the entire raw success payload. pub payload: Value, + + /// If there are any extracted sub-payload contents, such as "images" or "video", + /// then they are included here. This may not be fully inclusive of future + /// payload types. + pub extracted_contents: ExtractedContents, +} + +#[derive(Debug)] +pub struct ExtractedContents { + /// If the `payload` is a JSON object with the key `image`, + /// then the data in `['payload']['image']` is represented here: + pub image: Option, + + /// If the `payload` is a JSON object with the key `images`, + /// then the data in `['payload']['images']` is represented here: + pub images: Option, + + /// If the `payload` is a JSON object with the key `video`, + /// then the data in `['payload']['video']` is represented here: + pub video: Option, + + /// If the `payload` is a JSON object with the key `model_glb`, + /// then the data in `['payload']['model_glb']` is represented here: + pub model_glb: Option, + + /// If the `payload` is a JSON object with the key `model_mesh`, + /// then the data in `['payload']['model_mesh']` is represented here: + pub model_mesh: Option, } #[derive(Debug)] diff --git a/crates/api_clients/fal_client/test_data/webhooks/success/images_payload_1.json b/crates/api_clients/fal_client/test_data/webhooks/success/images_payload_1.json new file mode 100644 index 0000000000..3d4fdea8f7 --- /dev/null +++ b/crates/api_clients/fal_client/test_data/webhooks/success/images_payload_1.json @@ -0,0 +1,26 @@ +{ + "error": null, + "gateway_request_id": "11111111-2222-3333-4444-555555555555", + "payload": { + "images": [ + { + "content_type": "image/png", + "file_name": "name1.png", + "file_size": 11500002, + "height": null, + "url": "https://v3b.fal.media/files/b/01234567/name1.png", + "width": null + }, + { + "content_type": "image/png", + "file_name": "name2.png", + "file_size": 13499999, + "height": null, + "url": "https://v3b.fal.media/files/b/01234567/name2.png", + "width": null + } + ] + }, + "request_id": "11111111-2222-3333-4444-555555555555", + "status": "OK" +} \ No newline at end of file