2025-06-30 11:15:14 -03:00
|
|
|
use actix_web::{web, App, HttpServer};
|
2025-06-19 23:16:57 -03:00
|
|
|
use dotenv::dotenv;
|
2025-06-30 10:14:25 -03:00
|
|
|
use sqlx::PgPool;
|
2025-06-19 23:16:57 -03:00
|
|
|
|
2025-06-20 21:34:48 -03:00
|
|
|
use services::config::*;
|
2025-06-30 11:15:14 -03:00
|
|
|
use services::email::*;
|
2025-06-20 22:11:45 -03:00
|
|
|
use services::file::*;
|
|
|
|
use services::state::*;
|
2025-06-30 10:14:25 -03:00
|
|
|
|
2025-06-20 21:34:48 -03:00
|
|
|
mod services;
|
|
|
|
|
2025-06-19 23:16:57 -03:00
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
dotenv().ok();
|
2025-06-30 10:14:25 -03:00
|
|
|
let config = AppConfig::from_env();
|
2025-06-19 23:16:57 -03:00
|
|
|
|
2025-06-30 11:15:14 -03:00
|
|
|
let db_url = config.database_url();
|
|
|
|
let db = PgPool::connect(&db_url).await.unwrap();
|
2025-06-19 23:16:57 -03:00
|
|
|
|
2025-06-30 10:14:25 -03:00
|
|
|
let minio_client = init_minio(&config)
|
|
|
|
.await
|
|
|
|
.expect("Failed to initialize Minio");
|
2025-06-19 23:16:57 -03:00
|
|
|
|
|
|
|
let app_state = web::Data::new(AppState {
|
2025-06-30 10:14:25 -03:00
|
|
|
db: Some(db.clone()),
|
2025-06-19 23:16:57 -03:00
|
|
|
config: Some(config.clone()),
|
|
|
|
minio_client: Some(minio_client),
|
|
|
|
});
|
|
|
|
|
|
|
|
// Start HTTP server
|
|
|
|
HttpServer::new(move || {
|
|
|
|
App::new()
|
|
|
|
.app_data(app_state.clone())
|
2025-06-20 22:11:45 -03:00
|
|
|
.service(upload_file)
|
2025-06-30 10:14:25 -03:00
|
|
|
.service(list_file)
|
|
|
|
.service(save_click)
|
|
|
|
.service(get_emails)
|
|
|
|
})
|
2025-06-19 23:16:57 -03:00
|
|
|
.bind((config.server.host.clone(), config.server.port))?
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
}
|