noaws
Some checks failed
deploy / deploy (push) Failing after 52s

This commit is contained in:
2024-10-22 12:24:47 +03:00
parent ca97ecf128
commit fd3f8371cc
4 changed files with 71 additions and 127 deletions

View File

@@ -5,13 +5,23 @@ use crate::app_state::AppState;
use crate::s3_utils::check_file_exists;
/// Функция для обслуживания файла по заданному пути.
pub async fn serve_file(file_key: &str, state: &AppState) -> Result<HttpResponse, actix_web::Error> {
// Проверяем наличие файла в Storj S3
if !check_file_exists(&state.storj_client, &state.storj_bucket, &file_key).await? {
return Err(ErrorInternalServerError(format!("File {} not found in Storj", file_key)));
}
pub async fn serve_file(file_path: &str, state: &AppState) -> Result<HttpResponse, actix_web::Error> {
let filepath = match file_path.ends_with("/webp") {
true => &file_path.replace("/webp", ""),
false => file_path,
};
let mut parts = filepath.split('/').collect::<Vec<&str>>(); // Explicit type annotation
let filename = parts.pop().unwrap();
let mut filename_parts = filename.split('.').collect::<Vec<&str>>();
let _ext = filename_parts.pop().unwrap();
let filekey = filename_parts.pop().unwrap();
let file_path_in_storj = state.get_path(file_key).await.unwrap().unwrap();
let file_path_in_storj = state.get_path(filekey).await.unwrap().unwrap();
// Проверяем наличие файла в Storj S3
if !check_file_exists(&state.storj_client, &state.storj_bucket, &file_path_in_storj).await? {
return Err(ErrorInternalServerError(format!("File {} not found in Storj", file_path_in_storj)));
}
// Получаем объект из Storj S3
let get_object_output = state