debloat-logs
This commit is contained in:
parent
74b1be650f
commit
1385f64824
|
@ -189,8 +189,8 @@ impl AppState {
|
|||
let parts: Vec<&str> = key.split('.').collect();
|
||||
let storj_filekey = parts.first().and_then(|s| s.split('/').last()).unwrap_or(parts.first().unwrap());
|
||||
|
||||
if storj_filekey.is_empty() && !storj_filekey.ends_with("/") {
|
||||
eprint!("[ERROR] empty filename: {}\n", key);
|
||||
if storj_filekey.is_empty() && !storj_filekey.ends_with('/') {
|
||||
eprint!("empty filename: {}\n", key);
|
||||
} else {
|
||||
// Проверяем, существует ли файл на Storj S3
|
||||
match check_file_exists(&self.storj_client, &self.storj_bucket, &storj_filekey).await
|
||||
|
@ -200,7 +200,7 @@ impl AppState {
|
|||
if let Err(e) =
|
||||
self.save_aws2storj_mapping(&key, &storj_filekey).await
|
||||
{
|
||||
eprintln!("[ERROR] save {}: {:?}", key, e);
|
||||
eprintln!("save {}: {:?}", key, e);
|
||||
} else {
|
||||
println!("[ok] {}", key);
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ impl AppState {
|
|||
}
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"[ERROR] check {}: {:?}",
|
||||
"check {}: {:?}",
|
||||
storj_filekey, e
|
||||
);
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ impl AppState {
|
|||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("[ERROR] get AWS S3 file list: {:?}", e);
|
||||
eprintln!("get AWS S3 file list: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user