gbserver/src/main.rs

90 lines
2.7 KiB
Rust
Raw Normal View History

use std::sync::Arc;
2025-07-04 10:39:31 -03:00
use actix_cors::Cors;
use actix_web::http::header;
use actix_web::{web, App, HttpServer};
use dotenv::dotenv;
2025-07-04 23:20:48 -03:00
use services::config::*;
use services::email::*;
use services::file::*;
2025-07-04 23:20:48 -03:00
use services::llm::*;
2025-07-19 12:10:16 -03:00
use services::script::*;
use services::state::*;
use sqlx::PgPool;
2025-07-29 21:39:24 -03:00
use crate::services::web_automation::{initialize_browser_pool, BrowserPool};
//use services:: find::*;
mod services;
#[tokio::main(flavor = "multi_thread")]
async fn main() -> std::io::Result<()> {
dotenv().ok();
2025-07-20 15:01:18 -03:00
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
let config = AppConfig::from_env();
let db_url = config.database_url();
let db_custom_url = config.database_custom_url();
let db = PgPool::connect(&db_url).await.unwrap();
let db_custom = PgPool::connect(&db_custom_url).await.unwrap();
let minio_client = init_minio(&config)
.await
.expect("Failed to initialize Minio");
let browser_pool = Arc::new(BrowserPool::new(
"http://localhost:9515".to_string(),
5,
"/usr/bin/brave-browser-beta".to_string(),
));
2025-07-29 21:39:24 -03:00
initialize_browser_pool()
.await
.expect("Failed to initialize browser pool");
let app_state = web::Data::new(AppState {
db: db.into(),
db_custom: db_custom.into(),
config: Some(config.clone()),
minio_client: minio_client.into(),
browser_pool: browser_pool.clone(),
});
2025-07-19 12:10:16 -03:00
let script_service = ScriptService::new(&app_state.clone());
2025-07-20 15:01:18 -03:00
const TEXT: &str = include_str!("prompts/business/data-enrichment.bas");
2025-07-19 12:10:16 -03:00
match script_service.compile(TEXT) {
Ok(ast) => match script_service.run(&ast) {
Ok(result) => println!("Script executed successfully: {:?}", result),
Err(e) => eprintln!("Error executing script: {}", e),
},
Err(e) => eprintln!("Error compiling script: {}", e),
}
// Start HTTP server
HttpServer::new(move || {
2025-07-04 10:39:31 -03:00
let cors = Cors::default()
2025-07-19 12:10:16 -03:00
.send_wildcard()
2025-07-04 10:39:31 -03:00
.allowed_methods(vec!["GET", "POST", "PUT", "DELETE"])
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::CONTENT_TYPE)
.max_age(3600);
2025-07-20 00:03:37 -03:00
App::new()
2025-07-19 12:10:16 -03:00
.wrap(cors)
.app_data(app_state.clone())
.service(upload_file)
.service(list_file)
.service(save_click)
.service(get_emails)
2025-07-04 10:39:31 -03:00
.service(list_emails)
.service(send_email)
2025-07-04 23:20:48 -03:00
.service(chat_stream)
.service(chat)
})
.bind((config.server.host.clone(), config.server.port))?
.run()
.await
}