mirror of
https://github.com/flibusta-apps/batch_downloader.git
synced 2025-12-06 14:25:36 +01:00
Use local minio
This commit is contained in:
@@ -8,6 +8,7 @@ pub struct Config {
|
||||
pub api_key: String,
|
||||
|
||||
pub minio_host: String,
|
||||
pub internal_minio_host: String,
|
||||
pub minio_bucket: String,
|
||||
pub minio_access_key: String,
|
||||
pub minio_secret_key: String,
|
||||
@@ -29,6 +30,7 @@ impl Config {
|
||||
api_key: get_env("API_KEY"),
|
||||
|
||||
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"),
|
||||
|
||||
@@ -16,3 +16,18 @@ pub fn get_minio() -> Minio {
|
||||
.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()
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ use crate::{
|
||||
|
||||
use super::{
|
||||
library_client::{get_author_books, get_sequence_books, get_translator_books, Book, Page},
|
||||
minio::get_internal_minio,
|
||||
utils::get_key,
|
||||
};
|
||||
|
||||
@@ -98,9 +99,13 @@ pub async fn upload_to_minio(
|
||||
) -> Result<(String, u64), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let full_filename = format!("{}/{}", folder_name, filename);
|
||||
|
||||
let internal_minio = get_internal_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,
|
||||
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));
|
||||
|
||||
if let Err(err) = minio
|
||||
if let Err(err) = internal_minio
|
||||
.put_object_stream(
|
||||
&config::CONFIG.minio_bucket,
|
||||
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())
|
||||
.await
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user