This commit is contained in:
parent
b0d7162460
commit
0d4f21c79b
|
@ -1,3 +1,4 @@
|
|||
use actix_web::error::ErrorNotFound;
|
||||
use actix_web::{error::ErrorInternalServerError, web, HttpRequest, HttpResponse, Result};
|
||||
use log::{error, warn};
|
||||
|
||||
|
@ -142,46 +143,52 @@ pub async fn proxy_handler(
|
|||
let ct_parts = content_type.split("/").collect::<Vec<&str>>();
|
||||
let filepath = format!("production/{}/{}.{}", ct_parts[0], base_filename, extension); // NOTE: original ext
|
||||
|
||||
match check_file_exists(&state.storj_client, &state.bucket, &filepath).await? {
|
||||
true => {
|
||||
warn!("file {} exists in storj", filepath);
|
||||
}
|
||||
false => {
|
||||
warn!("file {} does not exist in storj", filepath);
|
||||
}
|
||||
}
|
||||
let exists_in_storj = check_file_exists(&state.storj_client, &state.bucket, &filepath).await?;
|
||||
|
||||
match check_file_exists(&state.aws_client, &state.bucket, &filepath).await? {
|
||||
true => {
|
||||
warn!("file {} exists in aws", filepath);
|
||||
}
|
||||
false => {
|
||||
warn!("file {} does not exist in aws", filepath);
|
||||
}
|
||||
}
|
||||
if exists_in_storj {
|
||||
warn!("file {} exists in storj, try to generate thumbnails", filepath);
|
||||
|
||||
match load_file_from_s3(&state.aws_client, &state.bucket, &filepath).await {
|
||||
Ok(filedata) => {
|
||||
let _ = thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string())
|
||||
.await;
|
||||
if let Err(e) = upload_to_s3(
|
||||
&state.storj_client,
|
||||
&state.bucket,
|
||||
&filekey,
|
||||
filedata.clone(),
|
||||
content_type,
|
||||
)
|
||||
.await {
|
||||
warn!("cannot upload to storj: {}", e);
|
||||
} else {
|
||||
warn!("file {} uploaded to storj", filekey);
|
||||
match load_file_from_s3(&state.aws_client, &state.bucket, &filepath).await {
|
||||
Ok(filedata) => {
|
||||
let _ = thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string()).await;
|
||||
}
|
||||
Ok(HttpResponse::Ok().content_type(content_type).body(filedata))
|
||||
},
|
||||
Err(e) => {
|
||||
error!("cannot download {} from aws: {}", filepath, e);
|
||||
Err(ErrorInternalServerError(e))
|
||||
},
|
||||
Err(e) => {
|
||||
error!("cannot download {} from storj: {}", filekey, e);
|
||||
return Err(ErrorInternalServerError(e));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warn!("file {} does not exist in storj", filepath);
|
||||
}
|
||||
|
||||
let exists_in_aws = check_file_exists(&state.aws_client, &state.bucket, &filepath).await?;
|
||||
if exists_in_aws {
|
||||
match load_file_from_s3(&state.aws_client, &state.bucket, &filepath).await {
|
||||
Ok(filedata) => {
|
||||
let _ = thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string())
|
||||
.await;
|
||||
if let Err(e) = upload_to_s3(
|
||||
&state.storj_client,
|
||||
&state.bucket,
|
||||
&filekey,
|
||||
filedata.clone(),
|
||||
content_type,
|
||||
)
|
||||
.await {
|
||||
warn!("cannot upload to storj: {}", e);
|
||||
} else {
|
||||
warn!("file {} uploaded to storj", filekey);
|
||||
}
|
||||
Ok(HttpResponse::Ok().content_type(content_type).body(filedata))
|
||||
},
|
||||
Err(e) => {
|
||||
error!("cannot download {} from aws: {}", filepath, e);
|
||||
Err(ErrorInternalServerError(e))
|
||||
},
|
||||
}
|
||||
} else {
|
||||
error!("file {} does not exist in aws", filepath);
|
||||
Err(ErrorNotFound("file does not exist"))
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user