diff --git a/src/app_state.rs b/src/app_state.rs index c0b5d6f..20895fb 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::warn; +use log::info; use crate::s3_utils::get_s3_filelist; @@ -89,7 +89,7 @@ impl AppState { /// Кэширует список файлов из Storj S3 в Redis. pub async fn cache_filelist(&self) { - warn!("caching AWS filelist..."); + info!("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)); } - warn!("cached {} files", filelist.len()); + info!("cached {} files", filelist.len()); } /// Получает путь из ключа (имени файла) в Redis. diff --git a/src/handlers/proxy.rs b/src/handlers/proxy.rs index b920b01..aa84480 100644 --- a/src/handlers/proxy.rs +++ b/src/handlers/proxy.rs @@ -1,6 +1,6 @@ use actix_web::error::ErrorNotFound; use actix_web::{error::ErrorInternalServerError, web, HttpRequest, HttpResponse, Result}; -use log::{error, warn}; +use log::{error, info}; use crate::app_state::AppState; use crate::handlers::serve_file::serve_file; @@ -13,7 +13,7 @@ pub async fn proxy_handler( requested_res: web::Path, state: web::Data, ) -> Result { - warn!("\t>>>\tGET {}", requested_res); + info!("\t>>>\tGET {}", requested_res); let normalized_path = if requested_res.ends_with("/webp") { requested_res.replace("/webp", "") } else { @@ -22,13 +22,13 @@ pub async fn proxy_handler( // парсим GET запрос let (base_filename, requested_width, extension) = parse_file_path(&normalized_path); - warn!("detected file extension: {}", extension); - warn!("base_filename: {}", base_filename); - warn!("requested width: {}", requested_width); + info!("detected file extension: {}", extension); + info!("base_filename: {}", base_filename); + info!("requested width: {}", requested_width); let ext = extension.as_str().to_lowercase(); - warn!("normalized to lowercase: {}", ext); + info!("normalized to lowercase: {}", ext); let filekey = format!("{}.{}", base_filename, &ext); - warn!("filekey: {}", filekey); + info!("filekey: {}", filekey); let content_type = match ext.as_str() { "jpg" | "jpeg" => "image/jpeg", "png" => "image/png", @@ -47,7 +47,7 @@ pub async fn proxy_handler( } }; - warn!("content_type: {}", content_type); + info!("content_type: {}", content_type); let shout_id = match req.query_string().contains("s=") { true => req @@ -61,16 +61,16 @@ pub async fn proxy_handler( return match state.get_path(&filekey).await { Ok(Some(stored_path)) => { - warn!("stored_path: {}", stored_path); + info!("stored_path: {}", stored_path); // Проверяем, существует ли файл в Storj if check_file_exists(&state.storj_client, &state.bucket, &stored_path).await? { if content_type.starts_with("image") { if requested_width == 0 { return serve_file(&stored_path, &state, shout_id).await; } - warn!("base_filename: {}", base_filename); - warn!("requested width: {}", requested_width); - warn!("extension: {}", extension); + info!("base_filename: {}", base_filename); + info!("requested width: {}", requested_width); + info!("extension: {}", extension); // Получаем оригинальное изображение для проверки размера let original_key = format!("{}.{}", base_filename, extension); if let Ok(original_data) = @@ -79,7 +79,7 @@ pub async fn proxy_handler( if let Ok(img) = image::load_from_memory(&original_data) { // Если запрошенная ширина больше оригинала, возвращаем оригинал if requested_width >= img.width() { - warn!( + info!( "requested width {} >= original width {}, serving original", requested_width, img.width() @@ -89,7 +89,7 @@ pub async fn proxy_handler( // Находим ближайшую поддерживаемую ширину let target_width = find_closest_width(requested_width); - warn!("normalized requested width {} to closest supported width {}", requested_width, target_width); + info!("normalized requested width {} to closest supported width {}", requested_width, target_width); // Проверяем/генерируем миниатюру let thumb_filename = @@ -103,7 +103,7 @@ pub async fn proxy_handler( .await { Ok(true) => { - warn!("serve existed thumb file: {}", thumb_filename); + info!("serve existed thumb file: {}", thumb_filename); return serve_file(&thumb_filename, &state, shout_id).await; } Ok(false) => { @@ -115,8 +115,8 @@ pub async fn proxy_handler( ) .await { - warn!("generate new thumb files: {}", stored_path); - warn!("{} bytes", filedata.len()); + info!("generate new thumb files: {}", stored_path); + info!("{} bytes", filedata.len()); // Генерируем миниатюру и сохраняем if let Ok(_) = thumbdata_save( @@ -127,7 +127,7 @@ pub async fn proxy_handler( ) .await { - warn!("serve new thumb file: {}", thumb_filename); + info!("serve new thumb file: {}", thumb_filename); return serve_file(&thumb_filename, &state, shout_id) .await; } else { @@ -154,13 +154,13 @@ pub async fn proxy_handler( } } // Если файл не изображение, продолжаем обработку - warn!("file is not an image"); + info!("file is not an image"); } // we need to download what stored_path keeping in aws return match load_file_from_s3(&state.aws_client, &state.bucket, &stored_path).await { Ok(filedata) => { - warn!("download stored_path from aws: {:?}", stored_path); + info!("download stored_path from aws: {:?}", stored_path); if let Err(e) = upload_to_s3( &state.storj_client, &state.bucket, @@ -172,7 +172,7 @@ pub async fn proxy_handler( { error!("cannot upload to storj: {}", e); } else { - warn!("file {} uploaded to storj", filekey); + info!("file {} uploaded to storj", filekey); state.set_path(&filekey, &filekey).await; } let _ = thumbdata_save( @@ -192,7 +192,7 @@ pub async fn proxy_handler( }; } Ok(None) => { - warn!("cannot find stored path for: {}", filekey); + info!("cannot find stored path for: {}", filekey); let ct_parts = content_type.split("/").collect::>(); let filepath = format!("production/{}/{}.{}", ct_parts[0], base_filename, extension); // NOTE: original ext @@ -200,7 +200,7 @@ pub async fn proxy_handler( check_file_exists(&state.storj_client, &state.bucket, &filepath).await?; if exists_in_storj { - warn!( + info!( "file {} exists in storj, try to generate thumbnails", filepath ); @@ -221,7 +221,7 @@ pub async fn proxy_handler( } } } else { - warn!("file {} does not exist in storj", filepath); + info!("file {} does not exist in storj", filepath); } let exists_in_aws = @@ -245,9 +245,9 @@ pub async fn proxy_handler( ) .await { - warn!("cannot upload to storj: {}", e); + info!("cannot upload to storj: {}", e); } else { - warn!("file {} uploaded to storj", filekey); + info!("file {} uploaded to storj", filekey); state.set_path(&filekey, &filepath).await; } Ok(HttpResponse::Ok().content_type(content_type).body(filedata)) diff --git a/src/handlers/upload.rs b/src/handlers/upload.rs index ecbf647..024a4ee 100644 --- a/src/handlers/upload.rs +++ b/src/handlers/upload.rs @@ -1,6 +1,6 @@ use actix_multipart::Multipart; use actix_web::{web, HttpRequest, HttpResponse, Result}; -use log::warn; +use log::info; use crate::app_state::AppState; use crate::auth::{get_id_by_token, user_added_file}; @@ -69,9 +69,9 @@ pub async fn upload_handler( &content_type, ) .await { - warn!("cannot upload to storj: {}", e); + info!("cannot upload to storj: {}", e); } else { - warn!("file {} uploaded to storj", body); + info!("file {} uploaded to storj", body); // Сохраняем информацию о загруженном файле для пользователя user_added_file(&mut state.redis.clone(), &user_id, &body).await?; state.set_path(&body, &body).await; diff --git a/src/main.rs b/src/main.rs index 7c78c0d..72f466f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ mod overlay; use actix_web::{middleware::Logger, web, App, HttpServer}; use app_state::AppState; use handlers::{proxy_handler, upload_handler}; -use log::warn; +use log::info; use tokio::task::spawn_blocking; use std::env; use env_logger; @@ -17,7 +17,7 @@ use env_logger; #[actix_web::main] async fn main() -> std::io::Result<()> { env_logger::init(); - warn!("Started"); + info!("Started"); let port = env::var("PORT").unwrap_or_else(|_| "8080".to_string()); let addr = format!("0.0.0.0:{}", port); diff --git a/src/overlay.rs b/src/overlay.rs index a4f991c..2702107 100644 --- a/src/overlay.rs +++ b/src/overlay.rs @@ -1,6 +1,6 @@ use std::{error::Error, io::Cursor}; use actix_web::web::Bytes; -use log::warn; +use log::info; use image::Rgba; use imageproc::drawing::{draw_text_mut, draw_filled_rect_mut}; use imageproc::rect::Rect; @@ -86,7 +86,7 @@ pub async fn generate_overlay<'a>(shout_id: &'a str, filedata: Bytes) -> Result< Ok(Bytes::from(buffer)) }, Err(e) => { - warn!("Error getting shout: {}", e); + info!("Error getting shout: {}", e); Ok(filedata) } } diff --git a/src/thumbnail.rs b/src/thumbnail.rs index 5a488d2..043842c 100644 --- a/src/thumbnail.rs +++ b/src/thumbnail.rs @@ -1,6 +1,6 @@ use actix_web::error::ErrorInternalServerError; use image::{imageops::FilterType, DynamicImage, ImageFormat}; -use log::{warn, error}; +use log::{info, error}; use std::{collections::HashMap, io::Cursor}; use crate::{app_state::AppState, s3_utils::upload_to_s3}; @@ -69,13 +69,13 @@ pub async fn generate_thumbnails( // Генерируем миниатюры только для размеров меньше оригинала for &width in THUMB_WIDTHS.iter().filter(|&&w| w < original_width) { - warn!("[THUMB] Generating thumbnail width: {}", width); + info!("[THUMB] Generating thumbnail width: {}", width); let thumbnail = image.resize(width, u32::MAX, FilterType::Lanczos3); let mut buffer = Vec::new(); match thumbnail.write_to(&mut Cursor::new(&mut buffer), format) { Ok(_) => { - warn!("[THUMB] Successfully generated thumbnail: {}x{}", width, thumbnail.height()); + info!("[THUMB] Successfully generated thumbnail: {}x{}", width, thumbnail.height()); thumbnails.insert(width, buffer); }, Err(e) => { @@ -86,9 +86,9 @@ pub async fn generate_thumbnails( } if thumbnails.is_empty() { - warn!("[THUMB] No thumbnails generated, image width: {}", original_width); + info!("[THUMB] No thumbnails generated, image width: {}", original_width); } else { - warn!("[THUMB] Generated {} thumbnails", thumbnails.len()); + info!("[THUMB] Generated {} thumbnails", thumbnails.len()); } Ok(thumbnails) @@ -121,17 +121,17 @@ pub async fn thumbdata_save( content_type: String, ) -> Result<(), actix_web::Error> { if content_type.starts_with("image") { - warn!("[THUMB] Processing image: {}", original_filename); + info!("[THUMB] Processing image: {}", original_filename); let (base_filename, _, extension) = parse_file_path(&original_filename); - warn!("[THUMB] Parsed: base={}, ext={}", base_filename, extension); + info!("[THUMB] Parsed: base={}, ext={}", base_filename, extension); let ext = extension.to_lowercase(); let filename = format!("{}.{}", base_filename, ext); - warn!("[THUMB] Normalized filename: {}", filename); + info!("[THUMB] Normalized filename: {}", filename); let img = match image::load_from_memory(&original_data) { Ok(img) => { - warn!("[THUMB] Successfully loaded image from memory, size: {}x{}", + info!("[THUMB] Successfully loaded image from memory, size: {}x{}", img.width(), img.height()); img }, @@ -143,7 +143,7 @@ pub async fn thumbdata_save( let format = match determine_image_format(&ext) { Ok(f) => { - warn!("[THUMB] Using format: {:?}", f); + info!("[THUMB] Using format: {:?}", f); f }, Err(e) => { @@ -154,11 +154,11 @@ pub async fn thumbdata_save( match generate_thumbnails(&img, format).await { Ok(thumbnails_bytes) => { - warn!("[THUMB] Generated {} thumbnails", thumbnails_bytes.len()); + info!("[THUMB] Generated {} thumbnails", thumbnails_bytes.len()); for (thumb_width, thumbnail) in thumbnails_bytes { let thumb_filename = format!("{}_{}.{}", base_filename, thumb_width, ext); - warn!("[THUMB] Saving thumbnail: {}", thumb_filename); + info!("[THUMB] Saving thumbnail: {}", thumb_filename); match upload_to_s3( &state.storj_client, @@ -168,10 +168,10 @@ pub async fn thumbdata_save( &content_type, ).await { Ok(_) => { - warn!("[THUMB] Successfully saved thumbnail: {}", thumb_filename); + info!("[THUMB] Successfully saved thumbnail: {}", thumb_filename); // Сохраняем путь к миниатюре в Redis state.set_path(&thumb_filename, &thumb_filename).await; - warn!("[THUMB] Cached path in Redis: {}", thumb_filename); + info!("[THUMB] Cached path in Redis: {}", thumb_filename); }, Err(e) => { error!("[THUMB] Failed to save thumbnail {}: {}", thumb_filename, e); @@ -186,7 +186,7 @@ pub async fn thumbdata_save( } } } else { - warn!("[THUMB] Skipping non-image content type: {}", content_type); + info!("[THUMB] Skipping non-image content type: {}", content_type); Ok(()) } }