Use local minio

This commit is contained in:
2024-04-15 23:33:11 +02:00
parent 177e3585c1
commit 12cbe1b4d1
3 changed files with 25 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ pub struct Config {
pub api_key: String, pub api_key: String,
pub minio_host: String, pub minio_host: String,
pub internal_minio_host: String,
pub minio_bucket: String, pub minio_bucket: String,
pub minio_access_key: String, pub minio_access_key: String,
pub minio_secret_key: String, pub minio_secret_key: String,
@@ -29,6 +30,7 @@ impl Config {
api_key: get_env("API_KEY"), api_key: get_env("API_KEY"),
minio_host: get_env("MINIO_HOST"), minio_host: get_env("MINIO_HOST"),
internal_minio_host: get_env("INTERNAL_MINIO_HOST"),
minio_bucket: get_env("MINIO_BUCKET"), minio_bucket: get_env("MINIO_BUCKET"),
minio_access_key: get_env("MINIO_ACCESS_KEY"), minio_access_key: get_env("MINIO_ACCESS_KEY"),
minio_secret_key: get_env("MINIO_SECRET_KEY"), minio_secret_key: get_env("MINIO_SECRET_KEY"),

View File

@@ -16,3 +16,18 @@ pub fn get_minio() -> Minio {
.build() .build()
.unwrap() .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()
}

View File

@@ -20,6 +20,7 @@ use crate::{
use super::{ use super::{
library_client::{get_author_books, get_sequence_books, get_translator_books, Book, Page}, library_client::{get_author_books, get_sequence_books, get_translator_books, Book, Page},
minio::get_internal_minio,
utils::get_key, utils::get_key,
}; };
@@ -98,9 +99,13 @@ pub async fn upload_to_minio(
) -> Result<(String, u64), Box<dyn std::error::Error + Send + Sync>> { ) -> Result<(String, u64), Box<dyn std::error::Error + Send + Sync>> {
let full_filename = format!("{}/{}", folder_name, filename); let full_filename = format!("{}/{}", folder_name, filename);
let internal_minio = get_internal_minio();
let minio = get_minio(); let minio = get_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, Ok(v) => v,
Err(err) => return Err(Box::new(err)), Err(err) => return Err(Box::new(err)),
}; };
@@ -111,7 +116,7 @@ pub async fn upload_to_minio(
let data_stream = get_stream(Box::new(archive)); let data_stream = get_stream(Box::new(archive));
if let Err(err) = minio if let Err(err) = internal_minio
.put_object_stream( .put_object_stream(
&config::CONFIG.minio_bucket, &config::CONFIG.minio_bucket,
full_filename.clone(), full_filename.clone(),
@@ -136,7 +141,7 @@ pub async fn upload_to_minio(
} }
}; };
let obj_size = match minio let obj_size = match internal_minio
.stat_object(&config::CONFIG.minio_bucket, full_filename.clone()) .stat_object(&config::CONFIG.minio_bucket, full_filename.clone())
.await .await
{ {