diff --git a/src/app_state.rs b/src/app_state.rs index 02eb0a1..35c7100 100644 --- a/src/app_state.rs +++ b/src/app_state.rs @@ -3,7 +3,7 @@ use aws_config::BehaviorVersion; use aws_sdk_s3::{config::Credentials, Client as S3Client}; use redis::{aio::MultiplexedConnection, AsyncCommands, Client as RedisClient}; use std::env; -use log::info; +use log::warn; use crate::s3_utils::get_s3_filelist; @@ -89,7 +89,7 @@ impl AppState { /// Кэширует список файлов из Storj S3 в Redis. pub async fn cache_filelist(&self) { - info!("caching storj filelist..."); + warn!("caching AWS filelist..."); let mut redis = self.redis.clone(); // Запрашиваем список файлов из Storj S3 @@ -103,7 +103,7 @@ impl AppState { .expect(&format!("Failed to cache file {} in Redis", filename)); } - info!("cached {} files", filelist.len()); + warn!("cached {} files", filelist.len()); } /// Получает путь из ключа (имени файла) в Redis. diff --git a/src/handlers/proxy.rs b/src/handlers/proxy.rs index 9e39110..b40c485 100644 --- a/src/handlers/proxy.rs +++ b/src/handlers/proxy.rs @@ -138,8 +138,27 @@ pub async fn proxy_handler( } Ok(None) => { warn!("cannot find stored path for: {}", filekey); - let filepath = format!("unsafe/production/{}", filekey); - // download from aws to storj + let ct_parts = content_type.split("/").collect::>(); + let filepath = format!("unsafe/production/{}/{}", ct_parts[0], filekey); + + match check_file_exists(&state.storj_client, &state.bucket, &filepath).await? { + true => { + warn!("file {} exists in storj", filepath); + } + false => { + warn!("file {} does not exist in storj", filepath); + } + } + + match check_file_exists(&state.aws_client, &state.bucket, &filepath).await? { + true => { + warn!("file {} exists in aws", filepath); + } + false => { + warn!("file {} does not exist in aws", filepath); + } + } + match load_file_from_s3(&state.aws_client, &state.bucket, &filepath).await { Ok(filedata) => { thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string())