From 74a1a4b2421ffb7db8ed90e5c7e81cf90695a1b6 Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 22 Oct 2024 13:33:53 +0300 Subject: [PATCH] reviewed1 --- src/handlers/serve_file.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/handlers/serve_file.rs b/src/handlers/serve_file.rs index f6c2855..fa33cef 100644 --- a/src/handlers/serve_file.rs +++ b/src/handlers/serve_file.rs @@ -11,14 +11,17 @@ pub async fn serve_file(file_path: &str, state: &AppState) -> Result file_path, }; let mut parts = filepath.split('/').collect::>(); // Explicit type annotation - let mut file_fullpath = String::new(); - if let Some(filename) = parts.pop() { - file_fullpath = state.get_path(filename).await.unwrap().unwrap(); + let filename = parts.pop().unwrap_or(""); // Explicit type annotation + let file_fullpath = state.get_path(filename).await?.unwrap_or(String::new()); + + if file_fullpath.is_empty() { + return Err(ErrorInternalServerError("File not found".to_string())); } // Проверяем наличие файла в Storj S3 - if !check_file_exists(&state.storj_client, &state.storj_bucket, &file_fullpath).await? { - return Err(ErrorInternalServerError(format!("File {} not found in Storj", file_fullpath))); + let exists = check_file_exists(&state.storj_client, &state.storj_bucket, &file_fullpath).await?; + if !exists { + return Err(ErrorInternalServerError("File not found in Storj".to_string())); } // Получаем объект из Storj S3