thumbfix7
This commit is contained in:
parent
8cde63383e
commit
30f591a34e
|
@ -25,9 +25,7 @@ pub struct ShoutAuthor {
|
|||
pub struct Shout {
|
||||
pub title: String,
|
||||
pub created_at: String,
|
||||
pub created_by: i32,
|
||||
pub main_topic: String,
|
||||
pub topics: Vec<ShoutTopic>,
|
||||
pub main_topic: ShoutTopic,
|
||||
pub authors: Vec<ShoutAuthor>,
|
||||
pub layout: String,
|
||||
}
|
||||
|
@ -42,7 +40,7 @@ pub async fn get_shout_by_id(shout_id: i32) -> Result<Shout, Box<dyn Error>> {
|
|||
}
|
||||
|
||||
let gql = json!({
|
||||
"query": format!("query {}($slug: String, $shout_id: Int) {{ {}(slug: $slug, shout_id: $shout_id) {{ title created_at created_by topics {{ title slug }} authors {{ id name }} }} }}", operation, query_name),
|
||||
"query": format!("query {}($slug: String, $shout_id: Int) {{ {}(slug: $slug, shout_id: $shout_id) {{ title created_at main_topic {{ title slug }} authors {{ id name }} }} }}", operation, query_name),
|
||||
"operationName": operation,
|
||||
"variables": variables
|
||||
});
|
||||
|
|
|
@ -73,23 +73,25 @@ pub async fn proxy_handler(
|
|||
return serve_file(thumb_filename, &state, shout_id).await;
|
||||
},
|
||||
Ok(false) => {
|
||||
// Миниатюра не существует, создаем и загружаем её
|
||||
if let Ok(filedata) = load_file_from_s3(&state.storj_client, &state.bucket, &stored_path).await {
|
||||
warn!("generate new thumb files: {}", stored_path);
|
||||
warn!("{} bytes", filedata.len());
|
||||
// Миниатюра не существует, возвращаем оригинал и запускаем генерацию миниатюры
|
||||
let original_file = serve_file(&stored_path, &state, shout_id).await?;
|
||||
|
||||
// Запускаем асинхронную задачу для генерации миниатюры
|
||||
let state_clone = state.clone();
|
||||
let stored_path_clone = stored_path.clone();
|
||||
let filekey_clone = filekey.clone();
|
||||
let content_type_clone = content_type.to_string();
|
||||
|
||||
// Генерируем миниатюру и сохраняем
|
||||
if let Ok(_) = thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string()).await {
|
||||
warn!("serve new thumb file: {}", thumb_filename);
|
||||
return serve_file(thumb_filename, &state, shout_id).await;
|
||||
} else {
|
||||
error!("cannot generate thumbnail");
|
||||
return Err(ErrorInternalServerError("cannot generate thumbnail"));
|
||||
actix_web::rt::spawn(async move {
|
||||
if let Ok(filedata) = load_file_from_s3(&state_clone.storj_client, &state_clone.bucket, &stored_path_clone).await {
|
||||
warn!("generate new thumb files: {}", stored_path_clone);
|
||||
if let Err(e) = thumbdata_save(filedata, &state_clone, &filekey_clone, content_type_clone).await {
|
||||
error!("Failed to generate thumbnail: {}", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error!("cannot load file from Storj to generate thumbnail");
|
||||
return Err(ErrorInternalServerError("cannot generate thumbnail"));
|
||||
}
|
||||
});
|
||||
|
||||
return Ok(original_file);
|
||||
}
|
||||
Err(e) => {
|
||||
error!("ошибка при проверке существования миниатюры: {}", e);
|
||||
|
|
Loading…
Reference in New Issue
Block a user