From 9fb7df027627425c338acb5ea23457fa6bee22d9 Mon Sep 17 00:00:00 2001 From: Xin Liu Date: Fri, 8 Nov 2024 17:20:33 +0800 Subject: [PATCH] refactor: update `files_handler` Signed-off-by: Xin Liu --- src/backend/sd.rs | 50 ++--------------------------------------------- src/main.rs | 2 +- 2 files changed, 3 insertions(+), 49 deletions(-) diff --git a/src/backend/sd.rs b/src/backend/sd.rs index 8562d67..1411714 100644 --- a/src/backend/sd.rs +++ b/src/backend/sd.rs @@ -2051,9 +2051,8 @@ pub(crate) async fn image_variation_handler(req: Request) -> Response) -> Response { // log info!(target: "stdout", "Handling the coming files request"); - let res = if req.method() == Method::POST { - match llama_core::files::upload_file(req).await { - Ok(fo) => { - // serialize chat completion object - let s = match serde_json::to_string(&fo) { - Ok(s) => s, - Err(e) => { - let err_msg = format!("Failed to serialize file object. {}", e); - - // log - error!(target: "stdout", "{}", &err_msg); - - return error::internal_server_error(err_msg); - } - }; - - // return response - let result = Response::builder() - .header("Access-Control-Allow-Origin", "*") - .header("Access-Control-Allow-Methods", "*") - .header("Access-Control-Allow-Headers", "*") - .header("Content-Type", "application/json") - .body(Body::from(s)); - - match result { - Ok(response) => response, - Err(e) => { - let err_msg = e.to_string(); - - // log - error!(target: "stdout", "{}", &err_msg); - - error::internal_server_error(err_msg) - } - } - } - Err(e) => { - let err_msg = format!("{}", e); - - // log - error!(target: "stdout", "{}", &err_msg); - - error::internal_server_error(err_msg) - } - } - } else if req.method() == Method::GET { + let res = if req.method() == Method::GET { let uri_path = req.uri().path().trim_end_matches('/').to_lowercase(); // Split the path into segments diff --git a/src/main.rs b/src/main.rs index 484b93e..1330dae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ type Error = Box; // default port const DEFAULT_PORT: &str = "8080"; -// server info +// socket address pub(crate) static SOCKET_ADDRESS: OnceCell = OnceCell::new(); #[derive(Debug, Parser)]