store-uplaoded-path
All checks were successful
deploy / deploy (push) Successful in 1m5s

This commit is contained in:
Untone 2024-10-23 21:41:29 +03:00
parent 4db1ac6ff7
commit a4ea55cf3c
4 changed files with 13 additions and 5 deletions

View File

@ -116,6 +116,14 @@ impl AppState {
Ok(new_path) 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<u64, actix_web::Error> { pub async fn get_or_create_quota(&self, user_id: &str) -> Result<u64, actix_web::Error> {
let mut redis = self.redis.clone(); let mut redis = self.redis.clone();

View File

@ -118,6 +118,7 @@ pub async fn proxy_handler(
error!("cannot upload to storj: {}", e); error!("cannot upload to storj: {}", e);
} else { } else {
warn!("file {} uploaded to storj", filekey); warn!("file {} uploaded to storj", filekey);
state.set_path(&filekey, &filekey).await;
} }
let _ = thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string()) let _ = thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string())
.await; .await;
@ -170,6 +171,7 @@ pub async fn proxy_handler(
warn!("cannot upload to storj: {}", e); warn!("cannot upload to storj: {}", e);
} else { } else {
warn!("file {} uploaded to storj", filekey); warn!("file {} uploaded to storj", filekey);
state.set_path(&filekey, &filepath).await;
} }
Ok(HttpResponse::Ok().content_type(content_type).body(filedata)) Ok(HttpResponse::Ok().content_type(content_type).body(filedata))
}, },

View File

@ -72,10 +72,10 @@ pub async fn upload_handler(
warn!("cannot upload to storj: {}", e); warn!("cannot upload to storj: {}", e);
} else { } else {
warn!("file {} uploaded to storj", body); warn!("file {} uploaded to storj", body);
}
// Сохраняем информацию о загруженном файле для пользователя // Сохраняем информацию о загруженном файле для пользователя
user_added_file(&mut state.redis.clone(), &user_id, &body).await?; user_added_file(&mut state.redis.clone(), &user_id, &body).await?;
state.set_path(&body, &body).await;
}
} }
} }
Ok(HttpResponse::Ok().body(body)) Ok(HttpResponse::Ok().body(body))

View File

@ -159,8 +159,6 @@ pub async fn thumbdata_save(
.await .await
{ {
warn!("cannot load thumb {}: {}", thumb_filename, e); warn!("cannot load thumb {}: {}", thumb_filename, e);
} else {
warn!("thumb {} uploaded to storj", thumb_filename);
} }
} }
} }