0.1.0-overlay

This commit is contained in:
2024-10-23 20:06:34 +03:00
parent 0d4f21c79b
commit 6e90529420
9 changed files with 556 additions and 237 deletions

View File

@@ -9,7 +9,7 @@ use crate::thumbnail::{find_closest_width, parse_file_path, thumbdata_save};
/// Обработчик для скачивания файла и генерации миниатюры, если она недоступна.
pub async fn proxy_handler(
_req: HttpRequest,
req: HttpRequest,
requested_res: web::Path<String>,
state: web::Data<AppState>,
) -> Result<HttpResponse, actix_web::Error> {
@@ -48,6 +48,11 @@ pub async fn proxy_handler(
warn!("content_type: {}", content_type);
let shout_id = match req.query_string().contains("s=") {
true => req.query_string().split("s=").collect::<Vec<&str>>().pop().unwrap_or(""),
false => ""
};
return match state.get_path(&filekey).await {
Ok(Some(stored_path)) => {
warn!("stored_path: {}", stored_path);
@@ -55,7 +60,7 @@ pub async fn proxy_handler(
if check_file_exists(&state.storj_client, &state.bucket, &stored_path).await? {
if content_type.starts_with("image") {
return match requested_width == 0 {
true => serve_file(&stored_path, &state).await,
true => serve_file(&stored_path, &state, shout_id).await,
false => {
// find closest thumb width
let closest: u32 = find_closest_width(requested_width as u32);
@@ -71,7 +76,7 @@ pub async fn proxy_handler(
{
Ok(true) => {
warn!("serve existed thumb file: {}", thumb_filename);
serve_file(thumb_filename, &state).await
serve_file(thumb_filename, &state, shout_id).await
},
Ok(false) => {
if let Ok(filedata) = load_file_from_s3(
@@ -91,7 +96,7 @@ pub async fn proxy_handler(
)
.await;
warn!("serve new thumb file: {}", thumb_filename);
serve_file(thumb_filename, &state).await
serve_file(thumb_filename, &state, shout_id).await
} else {
error!("cannot generate thumbnail");
Err(ErrorInternalServerError(