mirror of
https://github.com/flibusta-apps/telegram_files_cache_server.git
synced 2025-12-06 06:35:38 +01:00
Fix
This commit is contained in:
@@ -10,6 +10,7 @@ pub struct Config {
|
||||
pub postgres_db: String,
|
||||
|
||||
pub minio_host: String,
|
||||
pub internal_minio_host: String,
|
||||
pub minio_bucket: String,
|
||||
pub minio_access_key: String,
|
||||
pub minio_secret_key: String,
|
||||
@@ -42,6 +43,7 @@ impl Config {
|
||||
postgres_db: get_env("POSTGRES_DB"),
|
||||
|
||||
minio_host: get_env("MINIO_HOST"),
|
||||
internal_minio_host: get_env("INTERNAL_MINIO_HOST"),
|
||||
minio_bucket: get_env("MINIO_BUCKET"),
|
||||
minio_access_key: get_env("MINIO_ACCESS_KEY"),
|
||||
minio_secret_key: get_env("MINIO_SECRET_KEY"),
|
||||
|
||||
@@ -17,6 +17,21 @@ pub fn get_minio() -> Minio {
|
||||
Minio::builder()
|
||||
.endpoint(&config::CONFIG.minio_host)
|
||||
.provider(provider)
|
||||
.secure(true)
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn get_internal_minio() -> Minio {
|
||||
let provider = StaticProvider::new(
|
||||
&config::CONFIG.minio_access_key,
|
||||
&config::CONFIG.minio_secret_key,
|
||||
None,
|
||||
);
|
||||
|
||||
Minio::builder()
|
||||
.endpoint(&config::CONFIG.internal_minio_host)
|
||||
.provider(provider)
|
||||
.secure(false)
|
||||
.build()
|
||||
.unwrap()
|
||||
@@ -42,20 +57,25 @@ pub async fn upload_to_minio(
|
||||
archive: SpooledTempFile,
|
||||
filename: String,
|
||||
) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let minio = get_minio();
|
||||
let internal_minio = get_internal_minio();
|
||||
|
||||
let is_bucket_exist = match minio.bucket_exists(&config::CONFIG.minio_bucket).await {
|
||||
let is_bucket_exist = match internal_minio
|
||||
.bucket_exists(&config::CONFIG.minio_bucket)
|
||||
.await
|
||||
{
|
||||
Ok(v) => v,
|
||||
Err(err) => return Err(Box::new(err)),
|
||||
};
|
||||
|
||||
if !is_bucket_exist {
|
||||
let _ = minio.make_bucket(&config::CONFIG.minio_bucket, false).await;
|
||||
let _ = internal_minio
|
||||
.make_bucket(&config::CONFIG.minio_bucket, false)
|
||||
.await;
|
||||
}
|
||||
|
||||
let data_stream = get_stream(Box::new(archive));
|
||||
|
||||
if let Err(err) = minio
|
||||
if let Err(err) = internal_minio
|
||||
.put_object_stream(
|
||||
&config::CONFIG.minio_bucket,
|
||||
filename.clone(),
|
||||
@@ -67,6 +87,8 @@ pub async fn upload_to_minio(
|
||||
return Err(Box::new(err));
|
||||
}
|
||||
|
||||
let minio = get_minio();
|
||||
|
||||
let link = match minio
|
||||
.presigned_get_object(PresignedArgs::new(&config::CONFIG.minio_bucket, filename))
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user