diff --git a/src/app_state.rs b/src/app_state.rs index 35c7100..c0b5d6f 100644 --- a/src/app_state.rs +++ b/src/app_state.rs @@ -116,6 +116,14 @@ impl AppState { Ok(new_path) } + pub async fn set_path(&self, filename: &str, filepath: &str) { + let mut redis = self.redis.clone(); + let _: () = redis + .hset(PATH_MAPPING_KEY, filename, filepath) + .await + .expect(&format!("Failed to cache file {} in Redis", filename)); + } + /// создает или получает текущее значение квоты пользователя pub async fn get_or_create_quota(&self, user_id: &str) -> Result { let mut redis = self.redis.clone(); diff --git a/src/handlers/proxy.rs b/src/handlers/proxy.rs index c291adf..96b8d3b 100644 --- a/src/handlers/proxy.rs +++ b/src/handlers/proxy.rs @@ -118,6 +118,7 @@ pub async fn proxy_handler( error!("cannot upload to storj: {}", e); } else { warn!("file {} uploaded to storj", filekey); + state.set_path(&filekey, &filekey).await; } let _ = thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string()) .await; @@ -170,6 +171,7 @@ pub async fn proxy_handler( warn!("cannot upload to storj: {}", e); } else { warn!("file {} uploaded to storj", filekey); + state.set_path(&filekey, &filepath).await; } Ok(HttpResponse::Ok().content_type(content_type).body(filedata)) }, diff --git a/src/handlers/upload.rs b/src/handlers/upload.rs index 7edfb59..ecbf647 100644 --- a/src/handlers/upload.rs +++ b/src/handlers/upload.rs @@ -72,10 +72,10 @@ pub async fn upload_handler( warn!("cannot upload to storj: {}", e); } else { warn!("file {} uploaded to storj", body); + // Сохраняем информацию о загруженном файле для пользователя + user_added_file(&mut state.redis.clone(), &user_id, &body).await?; + state.set_path(&body, &body).await; } - - // Сохраняем информацию о загруженном файле для пользователя - user_added_file(&mut state.redis.clone(), &user_id, &body).await?; } } Ok(HttpResponse::Ok().body(body)) diff --git a/src/thumbnail.rs b/src/thumbnail.rs index 109d1cd..b510903 100644 --- a/src/thumbnail.rs +++ b/src/thumbnail.rs @@ -159,8 +159,6 @@ pub async fn thumbdata_save( .await { warn!("cannot load thumb {}: {}", thumb_filename, e); - } else { - warn!("thumb {} uploaded to storj", thumb_filename); } } }