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