This commit is contained in:
parent
6e90529420
commit
4db1ac6ff7
|
@ -56,62 +56,49 @@ pub async fn proxy_handler(
|
||||||
return match state.get_path(&filekey).await {
|
return match state.get_path(&filekey).await {
|
||||||
Ok(Some(stored_path)) => {
|
Ok(Some(stored_path)) => {
|
||||||
warn!("stored_path: {}", stored_path);
|
warn!("stored_path: {}", stored_path);
|
||||||
// we have stored file path in storj
|
// Проверяем, существует ли файл в Storj
|
||||||
if check_file_exists(&state.storj_client, &state.bucket, &stored_path).await? {
|
if check_file_exists(&state.storj_client, &state.bucket, &stored_path).await? {
|
||||||
if content_type.starts_with("image") {
|
if content_type.starts_with("image") {
|
||||||
return match requested_width == 0 {
|
if requested_width == 0 {
|
||||||
true => serve_file(&stored_path, &state, shout_id).await,
|
return serve_file(&stored_path, &state, shout_id).await;
|
||||||
false => {
|
} else {
|
||||||
// find closest thumb width
|
// Находим ближайшую ширину для миниатюры
|
||||||
let closest: u32 = find_closest_width(requested_width as u32);
|
let closest: u32 = find_closest_width(requested_width as u32);
|
||||||
let thumb_filename =
|
let thumb_filename = &format!("{}_{}.{}", base_filename, closest, ext);
|
||||||
&format!("{}_{}.{}", base_filename, closest, ext);
|
|
||||||
|
|
||||||
return match check_file_exists(
|
// Проверяем, существует ли уже миниатюра в Storj
|
||||||
&state.storj_client,
|
match check_file_exists(&state.storj_client, &state.bucket, thumb_filename).await {
|
||||||
&state.bucket,
|
Ok(true) => {
|
||||||
thumb_filename,
|
warn!("serve existed thumb file: {}", thumb_filename);
|
||||||
)
|
return serve_file(thumb_filename, &state, shout_id).await;
|
||||||
.await
|
},
|
||||||
{
|
Ok(false) => {
|
||||||
Ok(true) => {
|
// Миниатюра не существует, создаем и загружаем её
|
||||||
warn!("serve existed thumb file: {}", thumb_filename);
|
if let Ok(filedata) = load_file_from_s3(&state.storj_client, &state.bucket, &stored_path).await {
|
||||||
serve_file(thumb_filename, &state, shout_id).await
|
warn!("generate new thumb files: {}", stored_path);
|
||||||
},
|
warn!("{} bytes", filedata.len());
|
||||||
Ok(false) => {
|
|
||||||
if let Ok(filedata) = load_file_from_s3(
|
// Генерируем миниатюру и сохраняем
|
||||||
&state.storj_client,
|
if let Ok(_) = thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string()).await {
|
||||||
&state.bucket,
|
|
||||||
&stored_path,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
warn!("generate new thumb files: {}", stored_path);
|
|
||||||
warn!("{} bytes", filedata.len());
|
|
||||||
let _ = thumbdata_save(
|
|
||||||
filedata.clone(),
|
|
||||||
&state,
|
|
||||||
&filekey,
|
|
||||||
content_type.to_string(),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
warn!("serve new thumb file: {}", thumb_filename);
|
warn!("serve new thumb file: {}", thumb_filename);
|
||||||
serve_file(thumb_filename, &state, shout_id).await
|
return serve_file(thumb_filename, &state, shout_id).await;
|
||||||
} else {
|
} else {
|
||||||
error!("cannot generate thumbnail");
|
error!("cannot generate thumbnail");
|
||||||
Err(ErrorInternalServerError(
|
return Err(ErrorInternalServerError("cannot generate thumbnail"));
|
||||||
"cannot generate thumbnail",
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
error!("cannot load file from Storj to generate thumbnail");
|
||||||
|
return Err(ErrorInternalServerError("cannot generate thumbnail"));
|
||||||
}
|
}
|
||||||
Err(_) => {
|
}
|
||||||
Err(ErrorInternalServerError("failed to load thumbnail"))
|
Err(e) => {
|
||||||
}
|
error!("ошибка при проверке существования миниатюры: {}", e);
|
||||||
};
|
return Err(ErrorInternalServerError("failed to load thumbnail"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
// not image passing thumb generation
|
// Если файл не изображение, продолжаем обработку
|
||||||
warn!("file is not an image");
|
warn!("file is not an image");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user