fix(minio): small minio fix
This commit is contained in:
parent
2a1b4f8014
commit
dc2d283ec1
2 changed files with 30 additions and 16 deletions
30
src/main.rs
30
src/main.rs
|
|
@ -1,8 +1,13 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
|
use std::sync::Arc;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use dotenvy::dotenv;
|
use dotenvy::dotenv;
|
||||||
use juniper::{EmptyMutation, EmptySubscription};
|
use juniper::{EmptyMutation, EmptySubscription};
|
||||||
|
use minio::s3::ClientBuilder;
|
||||||
|
use minio::s3::creds::StaticProvider;
|
||||||
|
use minio::s3::http::BaseUrl;
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use rocket::fairing::AdHoc;
|
use rocket::fairing::AdHoc;
|
||||||
use rocket::http::{ContentType, Header, Status};
|
use rocket::http::{ContentType, Header, Status};
|
||||||
use rocket::{catch, catchers, routes, Request};
|
use rocket::{catch, catchers, routes, Request};
|
||||||
|
|
@ -11,6 +16,7 @@ use sqlx::Postgres;
|
||||||
use sqlx::postgres::PgPoolOptions;
|
use sqlx::postgres::PgPoolOptions;
|
||||||
use tonic::transport::Server;
|
use tonic::transport::Server;
|
||||||
use crate::graphql::{Query, Schema};
|
use crate::graphql::{Query, Schema};
|
||||||
|
use crate::nnid::people::S3ClientState;
|
||||||
|
|
||||||
mod xml;
|
mod xml;
|
||||||
mod conntest;
|
mod conntest;
|
||||||
|
|
@ -96,8 +102,32 @@ async fn launch() -> _ {
|
||||||
.connect(&act_database_url).await
|
.connect(&act_database_url).await
|
||||||
.expect("unable to create pool");
|
.expect("unable to create pool");
|
||||||
|
|
||||||
|
static S3_URL_STRING: Lazy<Box<str>> = Lazy::new(||
|
||||||
|
env::var("S3_URL").expect("S3_URL not specified").into_boxed_str()
|
||||||
|
);
|
||||||
|
|
||||||
|
static S3_URL: Lazy<BaseUrl> = Lazy::new(||
|
||||||
|
S3_URL_STRING.parse().unwrap()
|
||||||
|
);
|
||||||
|
|
||||||
|
static S3_USER: Lazy<Box<str>> = Lazy::new(||
|
||||||
|
env::var("S3_USER").expect("S3_USER not specified").into_boxed_str()
|
||||||
|
);
|
||||||
|
|
||||||
|
static S3_PASSWD: Lazy<Box<str>> = Lazy::new(||
|
||||||
|
env::var("S3_PASSWD").expect("S3_PASSWD not specified").into_boxed_str()
|
||||||
|
);
|
||||||
|
|
||||||
|
let s3_client = ClientBuilder::new(S3_URL.clone())
|
||||||
|
.provider(Some(Box::new(StaticProvider::new(&S3_USER, &S3_PASSWD, None))))
|
||||||
|
.build()
|
||||||
|
.expect("failed to create s3 client");
|
||||||
|
|
||||||
rocket::build()
|
rocket::build()
|
||||||
.manage(pool)
|
.manage(pool)
|
||||||
|
.manage(S3ClientState {
|
||||||
|
client: Arc::new(s3_client),
|
||||||
|
})
|
||||||
.manage(graphql::Context(graph_pool))
|
.manage(graphql::Context(graph_pool))
|
||||||
.manage(Schema::new(
|
.manage(Schema::new(
|
||||||
Query,
|
Query,
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,6 @@ use minio::s3::client::Client;
|
||||||
use minio::s3::args::PutObjectArgs;
|
use minio::s3::args::PutObjectArgs;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
static S3_URL_STRING: Lazy<Box<str>> = Lazy::new(||
|
|
||||||
env::var("S3_URL").expect("S3_URL not specified").into_boxed_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
const DATABASE_ERROR: Errors = Errors{
|
const DATABASE_ERROR: Errors = Errors{
|
||||||
error: &[
|
error: &[
|
||||||
Error{
|
Error{
|
||||||
|
|
@ -35,18 +31,6 @@ const DATABASE_ERROR: Errors = Errors{
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
static S3_URL: Lazy<BaseUrl> = Lazy::new(||
|
|
||||||
S3_URL_STRING.parse().unwrap()
|
|
||||||
);
|
|
||||||
|
|
||||||
static S3_USER: Lazy<Box<str>> = Lazy::new(||
|
|
||||||
env::var("S3_USER").expect("S3_USER not specified").into_boxed_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
static S3_PASSWD: Lazy<Box<str>> = Lazy::new(||
|
|
||||||
env::var("S3_PASSWD").expect("S3_PASSWD not specified").into_boxed_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
fn get_mii_img_url_path(pid: i32, format: &str) -> String{
|
fn get_mii_img_url_path(pid: i32, format: &str) -> String{
|
||||||
format!("mii/{}/main.{}", pid, format)
|
format!("mii/{}/main.{}", pid, format)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue