begin to extract contents

This commit is contained in:
Brandon Thomas committed 2026-04-11 20:19:54 -04:00
1 parent ebbc9af5ed
commit b8895fbae9
3 files changed
+71 -3

No files matched your search

@@ -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,
})
}
}
@@ -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<Value>,
/// If the `payload` is a JSON object with the key `images`,
/// then the data in `['payload']['images']` is represented here:
pub images: Option<Value>,
/// If the `payload` is a JSON object with the key `video`,
/// then the data in `['payload']['video']` is represented here:
pub video: Option<Value>,
/// 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<Value>,
/// 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<Value>,
}
#[derive(Debug)]
@@ -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"
}