From 5e47423eaf062b44eb7916dfd39215641c0d5b47 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 11 Nov 2024 14:03:20 +0300 Subject: [PATCH] debuglogs --- src/handlers/proxy.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/handlers/proxy.rs b/src/handlers/proxy.rs index a67470d..04ed386 100644 --- a/src/handlers/proxy.rs +++ b/src/handlers/proxy.rs @@ -13,8 +13,9 @@ pub async fn proxy_handler( requested_res: web::Path, state: web::Data, ) -> Result { - warn!("\t>>>\tGET {}", requested_res); + warn!("\t>>>\tGET {} [START]", requested_res); let normalized_path = if requested_res.ends_with("/webp") { + warn!("Removing /webp suffix from path"); requested_res.replace("/webp", "") } else { requested_res.to_string() @@ -56,16 +57,21 @@ pub async fn proxy_handler( return match state.get_path(&filekey).await { Ok(Some(stored_path)) => { - warn!("stored_path: {}", stored_path); + warn!("Found stored path in DB: {}", stored_path); // Проверяем, существует ли файл в Storj + warn!("Checking if file exists in Storj: {}", stored_path); if check_file_exists(&state.storj_client, &state.bucket, &stored_path).await? { + warn!("File exists in Storj: {}", stored_path); if content_type.starts_with("image") { + warn!("Processing image file with width: {}", requested_width); if requested_width == 0 { + warn!("Serving original file without resizing"); return serve_file(&stored_path, &state, shout_id).await; } else { - // Находим ближайшую ширину для миниатюры let closest: u32 = find_closest_width(requested_width as u32); + warn!("Calculated closest width: {} for requested: {}", closest, requested_width); let thumb_filename = &format!("{}_{}.{}", base_filename, closest, ext); + warn!("Generated thumbnail filename: {}", thumb_filename); // Проверяем, существует ли уже миниатюра в Storj match check_file_exists(&state.storj_client, &state.bucket, thumb_filename).await { @@ -101,8 +107,9 @@ pub async fn proxy_handler( } } } - // Если файл не изображение, продолжаем обработку - warn!("file is not an image"); + warn!("File is not an image, proceeding with normal serving"); + } else { + warn!("File does not exist in Storj: {}", stored_path); } // we need to download what stored_path keeping in aws @@ -135,9 +142,10 @@ pub async fn proxy_handler( }; } Ok(None) => { - warn!("cannot find stored path for: {}", filekey); + warn!("No stored path found in DB for: {}", filekey); let ct_parts = content_type.split("/").collect::>(); - let filepath = format!("production/{}/{}.{}", ct_parts[0], base_filename, extension); // NOTE: original ext + let filepath = format!("production/{}/{}.{}", ct_parts[0], base_filename, extension); + warn!("Generated filepath for lookup: {}", filepath); let exists_in_storj = check_file_exists(&state.storj_client, &state.bucket, &filepath).await?; warn!("Checking existence in Storj: {}", exists_in_storj); @@ -162,8 +170,10 @@ pub async fn proxy_handler( warn!("Checking existence in AWS: {}", exists_in_aws); if exists_in_aws { + warn!("File found in AWS, attempting to download: {}", filepath); match load_file_from_s3(&state.aws_client, &state.bucket, &filepath).await { Ok(filedata) => { + warn!("Successfully downloaded file from AWS, size: {} bytes", filedata.len()); let _ = thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string()) .await; if let Err(e) = upload_to_s3( @@ -182,17 +192,17 @@ pub async fn proxy_handler( Ok(HttpResponse::Ok().content_type(content_type).body(filedata)) }, Err(e) => { - error!("cannot download {} from aws: {}", filepath, e); + error!("Failed to download from AWS: {} - Error: {}", filepath, e); Err(ErrorInternalServerError(e)) }, } } else { - error!("file {} does not exist in aws", filepath); + error!("File not found in either Storj or AWS: {}", filepath); Err(ErrorNotFound("file does not exist")) } }, Err(e) => { - error!("cannot get path from aws: {}", e); + error!("Database error while getting path: {}", e); Err(ErrorInternalServerError(e)) } }