mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
use response wrapper for enqueue image gen
This commit is contained in:
1 parent
803d207a49
commit
8984452e1c
2 files changed
+26
-5
No files matched your search
@@ -26,6 +26,9 @@ pub struct CommandSuccessResponseWrapper<T: Serialize> {
|
||||
/// Both "success" and "error" types have a `status` field for the frontend.
|
||||
pub status: CommandSuccessStatus,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub success_message: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub payload: Option<T>,
|
||||
}
|
||||
@@ -36,7 +39,10 @@ pub struct CommandErrorResponseWrapper<T: Serialize> {
|
||||
pub status: CommandErrorStatus,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error: Option<T>,
|
||||
pub error_message: Option<String>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error_details: Option<T>,
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +50,7 @@ impl CommandSuccessResponseWrapper<()> {
|
||||
pub fn empty() -> Self {
|
||||
CommandSuccessResponseWrapper {
|
||||
status: CommandSuccessStatus::Success,
|
||||
success_message: None,
|
||||
payload: None,
|
||||
}
|
||||
}
|
||||
@@ -61,6 +68,7 @@ impl From<()> for CommandSuccessResponseWrapper<()> {
|
||||
fn from(_: ()) -> Self {
|
||||
CommandSuccessResponseWrapper {
|
||||
status: CommandSuccessStatus::Success,
|
||||
success_message: None,
|
||||
payload: None,
|
||||
}
|
||||
}
|
||||
@@ -72,16 +80,28 @@ impl <T> From<T> for CommandSuccessResponseWrapper<T> where T: Serialize + Seria
|
||||
fn from(val: T) -> Self {
|
||||
CommandSuccessResponseWrapper {
|
||||
status: CommandSuccessStatus::Success,
|
||||
success_message: None,
|
||||
payload: Some(val),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for CommandSuccessResponseWrapper<String> {
|
||||
fn from(msg: &str) -> Self {
|
||||
CommandSuccessResponseWrapper {
|
||||
status: CommandSuccessStatus::Success,
|
||||
success_message: Some(msg.to_string()),
|
||||
payload: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for CommandErrorResponseWrapper<String> {
|
||||
fn from(value: &str) -> Self {
|
||||
CommandErrorResponseWrapper {
|
||||
status: CommandErrorStatus::BadRequest, // NB: Default to 500 error.
|
||||
error: Some(value.to_string()),
|
||||
error_message: Some(value.to_string()),
|
||||
error_details: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::commands::command_response_wrapper::CommandResult;
|
||||
use crate::events::sendable_event_trait::SendableEvent;
|
||||
use crate::events::sora::sora_image_enqueue_failure_event::SoraImageEnqueueFailureEvent;
|
||||
use crate::events::sora::sora_image_enqueue_success_event::SoraImageEnqueueSuccessEvent;
|
||||
@@ -56,7 +57,7 @@ pub async fn sora_image_remix_command(
|
||||
app_data_root: State<'_, AppDataRoot>,
|
||||
sora_creds_manager: State<'_, SoraCredentialManager>,
|
||||
sora_task_queue: State<'_, SoraTaskQueue>,
|
||||
) -> Result<String, String> {
|
||||
) -> CommandResult<(), String> {
|
||||
|
||||
info!("image_generation_command called; scene media token: {:?}, additional images: {:?}",
|
||||
request.snapshot_media_token, request.maybe_additional_images);
|
||||
@@ -75,7 +76,7 @@ pub async fn sora_image_remix_command(
|
||||
error!("Failed to emit event: {:?}", err);
|
||||
}
|
||||
|
||||
return Err("there was an error".to_string());
|
||||
return Err("there was an error".into());
|
||||
}
|
||||
|
||||
let event = SoraImageEnqueueSuccessEvent {};
|
||||
@@ -85,7 +86,7 @@ pub async fn sora_image_remix_command(
|
||||
error!("Failed to emit event: {:?}", err);
|
||||
}
|
||||
|
||||
Ok("success".to_string())
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
pub async fn generate_image(
|
||||
|
||||
Reference in new issue
Block a user