diff --git a/src/handlers/proxy.rs b/src/handlers/proxy.rs index 0a8134c..7ca9c7e 100644 --- a/src/handlers/proxy.rs +++ b/src/handlers/proxy.rs @@ -112,30 +112,41 @@ pub async fn proxy_handler( } else { 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); + let aws_paths = vec![ + stored_path.clone(), + format!("production/{}", stored_path) + ]; + + for path in aws_paths { + warn!("Trying AWS path: {}", path); + match load_file_from_s3(&state.aws_client, &state.bucket, &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); + } + + return Ok(HttpResponse::Ok().content_type(content_type).body(filedata)); + } + Err(err) => { + warn!("Failed to load from AWS path {}: {:?}", path, err); + continue; } - - Ok(HttpResponse::Ok().content_type(content_type).body(filedata)) } - Err(err) => { - error!("Failed to load from AWS: {} - Full error: {:?}", stored_path, err); - Err(ErrorInternalServerError(err)) - } - }; + } + + error!("Failed to load from any AWS path for: {}", stored_path); + Err(ErrorInternalServerError("Failed to load file from AWS")) } } Ok(None) => {