debuglogs-more
Some checks failed
deploy / deploy (push) Failing after 5s

This commit is contained in:
Untone 2024-11-11 14:05:21 +03:00
parent 5e47423eaf
commit 46e485c71f

View File

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