diff --git a/runtimes/dummy/src/main.rs b/runtimes/dummy/src/main.rs index 62b1fd5..f66756b 100644 --- a/runtimes/dummy/src/main.rs +++ b/runtimes/dummy/src/main.rs @@ -19,17 +19,28 @@ async fn healthcheck(_req: HttpRequest) -> impl Responder { HttpResponse::Ok() } +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +struct Text2ImageBody { + pub width: Option, + pub height: Option, +} + #[post("/sdapi/v1/txt2img")] -async fn text2img(_req: HttpRequest) -> impl Responder { +async fn text2img(params: web::Json) -> impl Responder { log::info!("Endpoint: sdapi/v1/txt2img"); let mut bytes: Vec = Vec::new(); - match fractal(800, 800).write_to(&mut Cursor::new(&mut bytes), image::ImageFormat::Png) { + + let params = params.into_inner(); + let width = params.width.unwrap_or(800); + let height = params.height.unwrap_or(800); + + match fractal(width, height).write_to(&mut Cursor::new(&mut bytes), image::ImageFormat::Png) { Ok(_) => HttpResponse::Ok().json(json!({ "images": [BASE64_STANDARD.encode(bytes)] })), Err(e) => { log::error!("Error generating image: {e}"); - return HttpResponse::InternalServerError() - .body(format!("Error generating image: {e}")); + HttpResponse::InternalServerError().body(format!("Error generating image: {e}")) } } }