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