.
This commit is contained in:
@@ -21,6 +21,7 @@ serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
common = { path = "../common" }
|
||||
uuid = { version = "1", features = ["v4", "serde"] }
|
||||
rust-s3 = "0.32.3"
|
||||
|
||||
[dependencies.mongodb]
|
||||
version = "2.2.0"
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod photos_api;
|
||||
pub mod user_api;
|
||||
|
||||
@@ -2,10 +2,15 @@ mod api;
|
||||
mod models;
|
||||
mod repository;
|
||||
|
||||
use api::photos_api::get_presigned_post_urls;
|
||||
use api::user_api::{create_user, delete_user, get_user, is_logged_in, login, update_user};
|
||||
use common::OutputPicture;
|
||||
use repository::mongodb_repo::MongoRepo;
|
||||
|
||||
use s3::bucket::Bucket;
|
||||
use s3::creds::Credentials;
|
||||
use s3::region::Region;
|
||||
|
||||
use actix_cors::Cors;
|
||||
use actix_session::{
|
||||
config::CookieContentSecurity, storage::CookieSessionStore, SessionMiddleware,
|
||||
@@ -63,7 +68,27 @@ async fn main() -> std::io::Result<()> {
|
||||
log::info!("starting HTTP server at http://{}:{}", host, port);
|
||||
|
||||
let db = MongoRepo::init().await;
|
||||
let db_data = Data::new(db);
|
||||
let db = Data::new(db);
|
||||
|
||||
let bucket_name = "photos";
|
||||
let region = Region::Custom {
|
||||
region: "minio".parse().unwrap(),
|
||||
endpoint: "http://127.0.0.1:9000".to_owned(),
|
||||
};
|
||||
let credentials = Credentials {
|
||||
access_key: Some("OPyibtgH1RISFIPs".to_owned()),
|
||||
secret_key: Some("LesNB0p5oZEcJy3rACHEloityS1Y6nYc".to_owned()),
|
||||
security_token: None,
|
||||
session_token: None,
|
||||
expiration: None,
|
||||
};
|
||||
let bucket = if let Ok(mut bucket) = Bucket::new(bucket_name, region, credentials) {
|
||||
bucket.set_path_style();
|
||||
bucket
|
||||
} else {
|
||||
panic!("Could not create bucket");
|
||||
};
|
||||
let bucket = Data::new(bucket);
|
||||
|
||||
HttpServer::new(move || {
|
||||
let cors = Cors::default()
|
||||
@@ -75,7 +100,6 @@ async fn main() -> std::io::Result<()> {
|
||||
.max_age(3600);
|
||||
|
||||
App::new()
|
||||
// .app_data(web::Data::new(pool.clone()))
|
||||
.wrap(cors)
|
||||
.wrap(
|
||||
SessionMiddleware::builder(
|
||||
@@ -85,10 +109,11 @@ async fn main() -> std::io::Result<()> {
|
||||
.cookie_content_security(CookieContentSecurity::Private)
|
||||
.build(),
|
||||
)
|
||||
.app_data(db_data.clone())
|
||||
.app_data(db.clone())
|
||||
.app_data(bucket.clone())
|
||||
.wrap(middleware::Logger::default())
|
||||
.service(get_presigned_post_urls)
|
||||
.service(get_pictures)
|
||||
// .service(fs::Files::new("/api/pictures/", "./pictures/"))
|
||||
.service(is_logged_in)
|
||||
.service(login)
|
||||
.service(create_user)
|
||||
|
||||
Reference in New Issue
Block a user