This commit is contained in:
@@ -13,11 +13,14 @@ pub async fn proxy_handler(
|
||||
state: web::Data<AppState>,
|
||||
) -> Result<HttpResponse, actix_web::Error> {
|
||||
info!("req.path: {}", req.path());
|
||||
let requested_path = requested_res.replace("/webp", "");
|
||||
let parts = requested_path.split('/').collect::<Vec<&str>>(); // Explicit type annotation
|
||||
let filename = parts[parts.len()-1];
|
||||
|
||||
let requested_path = match state.get_path(&requested_res).await {
|
||||
let requested_path = match state.get_path(&filename).await {
|
||||
Ok(Some(path)) => path,
|
||||
Ok(None) => {
|
||||
warn!("wrong request: {}", req.path());
|
||||
warn!("wrong filename: {}", filename);
|
||||
return Ok(HttpResponse::NotFound().finish());
|
||||
}
|
||||
Err(e) => {
|
||||
@@ -35,12 +38,12 @@ pub async fn proxy_handler(
|
||||
|
||||
// Находим ближайший подходящий размер
|
||||
let closest_width = find_closest_width(requested_width);
|
||||
let thumb_filekey = format!("{}_{}", base_filename, closest_width);
|
||||
info!("closest width: {}, thumb_filekey: {}", closest_width, thumb_filekey);
|
||||
let thumb_filename = format!("{}_{}.jpg", base_filename, closest_width);
|
||||
info!("closest width: {}, thumb_filename: {}", closest_width, thumb_filename);
|
||||
|
||||
// Проверяем наличие миниатюры в кэше
|
||||
let cached_files = state.get_cached_file_list().await;
|
||||
if !cached_files.contains(&thumb_filekey) {
|
||||
if !cached_files.contains(&thumb_filename) {
|
||||
info!("no thumb found");
|
||||
if cached_files.contains(&base_filename) {
|
||||
info!("no original file found");
|
||||
@@ -60,7 +63,7 @@ pub async fn proxy_handler(
|
||||
upload_to_s3(
|
||||
&state.storj_client,
|
||||
&state.storj_bucket,
|
||||
&thumb_filekey,
|
||||
&thumb_filename,
|
||||
thumbnail_bytes.clone(),
|
||||
"image/jpeg",
|
||||
)
|
||||
@@ -74,7 +77,7 @@ pub async fn proxy_handler(
|
||||
}
|
||||
} else {
|
||||
info!("thumb was found");
|
||||
return serve_file(&thumb_filekey, &state).await;
|
||||
return serve_file(&thumb_filename, &state).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user