mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
decode image
This commit is contained in:
1 parent
c8c857e3d0
commit
9e32196ca2
3 files changed
+58
-4
No files matched your search
+28
-3
@@ -1,17 +1,32 @@
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::http_server::endpoints::webhooks::handle_image_payload::handle_image_payload;
|
||||
use crate::state::server_state::ServerState;
|
||||
use actix_web::error::ResponseError;
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::web::Json;
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use log::info;
|
||||
use anyhow::Error;
|
||||
use errors::AnyhowResult;
|
||||
use http_server_common::response::response_success_helpers::SimpleGenericJsonSuccess;
|
||||
use http_server_common::response::serialize_as_json_error::serialize_as_json_error;
|
||||
use log::info;
|
||||
use serde_json::Value;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
// 1. tauri --> hit endpoint to enqueue
|
||||
//
|
||||
// 2. webhook
|
||||
// - upload media file
|
||||
// - update job record with media token + status
|
||||
//
|
||||
// 3. tauri --> storyteller jobs endpoint polls
|
||||
// - alert frontend of completion
|
||||
//
|
||||
// 4. javascript polls tauri (backend removal)
|
||||
|
||||
// TODO(bt, 2025-06-03): Handle webhook crypto authentication
|
||||
#[derive(Debug, Deserialize, ToSchema)]
|
||||
pub struct FalWebhookRequest {
|
||||
pub status: FalWebhookStatus,
|
||||
@@ -65,6 +80,13 @@ impl fmt::Display for FalWebhookError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<anyhow::Error> for FalWebhookError {
|
||||
fn from(value: Error) -> Self {
|
||||
info!("Converting anyhow::Error to FalWebhookError: {:?}", value);
|
||||
FalWebhookError::ServerError
|
||||
}
|
||||
}
|
||||
|
||||
// =============== Handler ===============
|
||||
|
||||
/// Fal webhook
|
||||
@@ -85,13 +107,16 @@ impl fmt::Display for FalWebhookError {
|
||||
pub async fn fal_webhook_handler(
|
||||
http_request: HttpRequest,
|
||||
server_state: web::Data<Arc<ServerState>>,
|
||||
//request_body: web::Bytes
|
||||
request: Json<FalWebhookRequest>,
|
||||
) -> Result<Json<SimpleGenericJsonSuccess>, FalWebhookError> {
|
||||
|
||||
|
||||
info!("Received FAL webhook body: {:?}", request);
|
||||
|
||||
if let Some(payload) = request.payload.as_ref() {
|
||||
if let Some(payload_obj) = payload.as_object() {
|
||||
handle_image_payload(payload_obj).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(SimpleGenericJsonSuccess::wrapped(true))
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
use anyhow::anyhow;
|
||||
use log::info;
|
||||
use serde_json::{Map, Value};
|
||||
use errors::AnyhowResult;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct FalWebhookImage {
|
||||
pub content_type: Option<String>,
|
||||
pub file_name: Option<String>,
|
||||
pub file_size: Option<usize>,
|
||||
pub height: Option<usize>,
|
||||
pub width: Option<usize>,
|
||||
pub url: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn handle_image_payload(
|
||||
payload: &Map<String, Value>,
|
||||
) -> AnyhowResult<()> {
|
||||
|
||||
let image_value = payload.get("image")
|
||||
.ok_or_else(|| anyhow!("no `image` key in payload"))?;
|
||||
|
||||
let image: FalWebhookImage = serde_json::from_value(image_value.clone())?;
|
||||
|
||||
info!("Image payload received: {:?}", image);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod fal_webhook_handler;
|
||||
pub mod fal_webhook_handler;
|
||||
pub mod handle_image_payload;
|
||||
Reference in new issue
Block a user