This commit is contained in:
parent
5e47423eaf
commit
46e485c71f
|
@ -58,8 +58,7 @@ pub async fn proxy_handler(
|
|||
return match state.get_path(&filekey).await {
|
||||
Ok(Some(stored_path)) => {
|
||||
warn!("Found stored path in DB: {}", stored_path);
|
||||
// Проверяем, существует ли файл в Storj
|
||||
warn!("Checking if file exists in Storj: {}", stored_path);
|
||||
warn!("Checking Storj path - bucket: {}, path: {}", state.bucket, stored_path);
|
||||
if check_file_exists(&state.storj_client, &state.bucket, &stored_path).await? {
|
||||
warn!("File exists in Storj: {}", stored_path);
|
||||
if content_type.starts_with("image") {
|
||||
|
@ -109,43 +108,39 @@ pub async fn proxy_handler(
|
|||
}
|
||||
warn!("File is not an image, proceeding with normal serving");
|
||||
} else {
|
||||
warn!("File does not exist in Storj: {}", stored_path);
|
||||
}
|
||||
|
||||
// we need to download what stored_path keeping in aws
|
||||
return match load_file_from_s3(&state.aws_client, &state.bucket, &stored_path).await
|
||||
{
|
||||
Ok(filedata) => {
|
||||
warn!("download stored_path from aws: {:?}", stored_path);
|
||||
if let Err(e) = upload_to_s3(
|
||||
&state.storj_client,
|
||||
&state.bucket,
|
||||
&filekey,
|
||||
filedata.clone(),
|
||||
content_type,
|
||||
)
|
||||
.await {
|
||||
error!("cannot upload to storj: {}", e);
|
||||
} else {
|
||||
warn!("file {} uploaded to storj", filekey);
|
||||
state.set_path(&filekey, &filekey).await;
|
||||
warn!("Attempting to load from AWS - bucket: {}, path: {}", state.bucket, stored_path);
|
||||
|
||||
return match load_file_from_s3(&state.aws_client, &state.bucket, &stored_path).await {
|
||||
Ok(filedata) => {
|
||||
warn!("Successfully loaded file from AWS, size: {} bytes", filedata.len());
|
||||
warn!("Attempting to upload to Storj with key: {}", filekey);
|
||||
|
||||
if let Err(e) = upload_to_s3(
|
||||
&state.storj_client,
|
||||
&state.bucket,
|
||||
&filekey,
|
||||
filedata.clone(),
|
||||
content_type,
|
||||
).await {
|
||||
error!("Failed to upload to Storj: {} - Error: {}", filekey, e);
|
||||
} else {
|
||||
warn!("Successfully uploaded to Storj: {}", filekey);
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().content_type(content_type).body(filedata))
|
||||
}
|
||||
let _ = thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string())
|
||||
.await;
|
||||
|
||||
Ok(HttpResponse::Ok().content_type(content_type).body(filedata))
|
||||
}
|
||||
Err(err) => {
|
||||
error!("cannot download {} from aws: {}", stored_path, err);
|
||||
Err(ErrorInternalServerError(err))
|
||||
},
|
||||
};
|
||||
Err(err) => {
|
||||
error!("Failed to load from AWS: {} - Full error: {:?}", stored_path, err);
|
||||
Err(ErrorInternalServerError(err))
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Ok(None) => {
|
||||
warn!("No stored path found in DB for: {}", filekey);
|
||||
let ct_parts = content_type.split("/").collect::<Vec<&str>>();
|
||||
let filepath = format!("production/{}/{}.{}", ct_parts[0], base_filename, extension);
|
||||
warn!("Generated filepath for lookup: {}", filepath);
|
||||
warn!("Looking up file with path: {} in bucket: {}", filepath, state.bucket);
|
||||
|
||||
let exists_in_storj = check_file_exists(&state.storj_client, &state.bucket, &filepath).await?;
|
||||
warn!("Checking existence in Storj: {}", exists_in_storj);
|
||||
|
@ -202,7 +197,7 @@ pub async fn proxy_handler(
|
|||
}
|
||||
},
|
||||
Err(e) => {
|
||||
error!("Database error while getting path: {}", e);
|
||||
error!("Database error while getting path: {} - Full error: {:?}", filekey, e);
|
||||
Err(ErrorInternalServerError(e))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user