debloat-logs
This commit is contained in:
@@ -12,38 +12,38 @@ pub async fn proxy_handler(
|
||||
requested_res: web::Path<String>,
|
||||
state: web::Data<AppState>,
|
||||
) -> Result<HttpResponse, actix_web::Error> {
|
||||
info!("[proxy_handler] req.path: {}", req.path());
|
||||
info!("req.path: {}", req.path());
|
||||
|
||||
let requested_path = match state.get_path(&requested_res).await {
|
||||
Ok(Some(path)) => path,
|
||||
Ok(None) => {
|
||||
warn!("[proxy_handler] wrong request: {}", req.path());
|
||||
warn!("wrong request: {}", req.path());
|
||||
return Ok(HttpResponse::NotFound().finish());
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("[proxy_handler] error: {}", e);
|
||||
warn!("error: {}", e);
|
||||
return Ok(HttpResponse::InternalServerError().finish());
|
||||
}
|
||||
};
|
||||
info!("[proxy_handler] requested path: {}", requested_path);
|
||||
info!("requested path: {}", requested_path);
|
||||
|
||||
// Проверяем, запрошена ли миниатюра
|
||||
if let Some((base_filename, requested_width, extension)) =
|
||||
parse_thumbnail_request(&requested_res)
|
||||
{
|
||||
info!("[proxy_handler] thumbnail requested: {} width: {}, ext: {}", base_filename, requested_width, extension);
|
||||
info!("thumbnail requested: {} width: {}, ext: {}", base_filename, requested_width, extension);
|
||||
|
||||
// Находим ближайший подходящий размер
|
||||
let closest_width = find_closest_width(requested_width);
|
||||
let thumb_filekey = format!("{}_{}", base_filename, closest_width);
|
||||
info!("[proxy_handler] closest width: {}, thumb_filekey: {}", closest_width, thumb_filekey);
|
||||
info!("closest width: {}, thumb_filekey: {}", closest_width, thumb_filekey);
|
||||
|
||||
// Проверяем наличие миниатюры в кэше
|
||||
let cached_files = state.get_cached_file_list().await;
|
||||
if !cached_files.contains(&thumb_filekey) {
|
||||
info!("[proxy_handler] no thumb found");
|
||||
info!("no thumb found");
|
||||
if cached_files.contains(&base_filename) {
|
||||
info!("[proxy_handler] no original file found");
|
||||
info!("no original file found");
|
||||
// Загружаем оригинальный файл из S3
|
||||
let original_data: Vec<u8> =
|
||||
load_file_from_s3(&state.storj_client, &state.storj_bucket, &base_filename).await?;
|
||||
@@ -65,25 +65,25 @@ pub async fn proxy_handler(
|
||||
"image/jpeg",
|
||||
)
|
||||
.await?;
|
||||
info!("[proxy_handler] thumb was saved in storj");
|
||||
info!("thumb was saved in storj");
|
||||
return Ok(HttpResponse::Ok()
|
||||
.content_type("image/jpeg")
|
||||
.body(thumbnail_bytes));
|
||||
} else {
|
||||
warn!("[proxy_handler] original was not found");
|
||||
warn!("original was not found");
|
||||
}
|
||||
} else {
|
||||
info!("[proxy_handler] thumb was found");
|
||||
info!("thumb was found");
|
||||
return serve_file(&thumb_filekey, &state).await;
|
||||
}
|
||||
}
|
||||
|
||||
// Если запрошен целый файл
|
||||
info!("[proxy_handler] serving full file: {}", requested_path);
|
||||
info!("serving full file: {}", requested_path);
|
||||
match serve_file(&requested_path, &state).await {
|
||||
Ok(response) => Ok(response),
|
||||
Err(e) => {
|
||||
error!("[proxy_handler] error: {}", e);
|
||||
error!("error: {}", e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user