This commit is contained in:
parent
406902d481
commit
84130d411a
|
@ -13,9 +13,10 @@ pub async fn proxy_handler(
|
|||
state: web::Data<AppState>,
|
||||
) -> Result<HttpResponse, actix_web::Error> {
|
||||
warn!("\t>>>\tGET {}", requested_res);
|
||||
let normalized_path = match requested_res.ends_with("/webp") {
|
||||
true => requested_res.replace("/webp", ""),
|
||||
false => requested_res.to_string(),
|
||||
let normalized_path = if requested_res.ends_with("/webp") {
|
||||
requested_res.replace("/webp", "")
|
||||
} else {
|
||||
requested_res.to_string()
|
||||
};
|
||||
|
||||
// парсим GET запрос
|
||||
|
@ -123,15 +124,36 @@ pub async fn proxy_handler(
|
|||
Err(err) => Err(ErrorInternalServerError(err)),
|
||||
};
|
||||
}
|
||||
Ok(None) => Err(ErrorInternalServerError(
|
||||
"requested file path was not found",
|
||||
)),
|
||||
Ok(None) => {
|
||||
// download from aws to storj
|
||||
match load_file_from_s3(&state.aws_client, &state.bucket, &requested_res).await {
|
||||
Ok(filedata) => {
|
||||
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) => Err(ErrorInternalServerError(e)),
|
||||
}
|
||||
},
|
||||
Err(e) => Err(ErrorInternalServerError(e))
|
||||
};
|
||||
}
|
||||
|
||||
Err(ErrorInternalServerError("invalid file key"))
|
||||
}
|
||||
|
||||
async fn thumbdata_save(
|
||||
original_data: Vec<u8>,
|
||||
state: &AppState,
|
||||
|
|
Loading…
Reference in New Issue
Block a user