mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-11-04 09:34:04 +00:00 
			
		
		
		
	Start to update main function
This commit is contained in:
		@@ -43,6 +43,7 @@ pub struct Config {
 | 
			
		||||
    pub terms_url: String,
 | 
			
		||||
    pub privacy_policy_url: String,
 | 
			
		||||
    pub contact_email: String,
 | 
			
		||||
    pub password_reset_url: String,
 | 
			
		||||
    pub play_store_url: String,
 | 
			
		||||
    pub android_direct_download_url: String,
 | 
			
		||||
    pub proxy: Option<String>,
 | 
			
		||||
@@ -133,6 +134,7 @@ impl Config {
 | 
			
		||||
            privacy_policy_url: Config::yaml_str(parsed, "privacy-policy-url"),
 | 
			
		||||
 | 
			
		||||
            contact_email: Config::yaml_str(parsed, "contact-email"),
 | 
			
		||||
            password_reset_url: Config::yaml_str(parsed, "password-reset-url"),
 | 
			
		||||
 | 
			
		||||
            play_store_url: Config::yaml_str(parsed, "play-store-url"),
 | 
			
		||||
            android_direct_download_url: Config::yaml_str(parsed, "android-direct-download-url"),
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										79
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										79
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -1,11 +1,23 @@
 | 
			
		||||
use std::future::Future;
 | 
			
		||||
 | 
			
		||||
use comunic_server::{cleanup_thread, server};
 | 
			
		||||
use comunic_server::data::config::{conf, Config};
 | 
			
		||||
use comunic_server::helpers::database;
 | 
			
		||||
 | 
			
		||||
type MainActionFunction = Box<dyn Future<Output=std::io::Result<()>>>;
 | 
			
		||||
 | 
			
		||||
struct Action {
 | 
			
		||||
    name: String,
 | 
			
		||||
    description: String,
 | 
			
		||||
    arguments: Vec<String>,
 | 
			
		||||
    function: Box<dyn FnOnce() -> MainActionFunction>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[actix_rt::main]
 | 
			
		||||
async fn main() -> std::io::Result<()> {
 | 
			
		||||
    let conf_file = match std::env::args().skip(1).next() {
 | 
			
		||||
        Some(el) => el,
 | 
			
		||||
    let args: Vec<String> = std::env::args().collect();
 | 
			
		||||
    let conf_file = match args.get(1) {
 | 
			
		||||
        Some(el) => el.to_string(),
 | 
			
		||||
        None => "config.yaml".to_string(),
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
@@ -15,9 +27,64 @@ async fn main() -> std::io::Result<()> {
 | 
			
		||||
    // Connect to the database
 | 
			
		||||
    database::connect(&conf().database).expect("Could not connect to database!");
 | 
			
		||||
 | 
			
		||||
    // Start cleanup thread
 | 
			
		||||
    cleanup_thread::start().expect("Failed to start cleanup thread!");
 | 
			
		||||
    // Get selected action
 | 
			
		||||
    let action = args
 | 
			
		||||
        .get(2)
 | 
			
		||||
        .map(|a| a.as_str())
 | 
			
		||||
        .unwrap_or("serve")
 | 
			
		||||
        .to_string();
 | 
			
		||||
 | 
			
		||||
    // Start the server
 | 
			
		||||
    server::start_server(conf()).await
 | 
			
		||||
    /* let actions = vec![
 | 
			
		||||
         Action {
 | 
			
		||||
             name: "serve".to_string(),
 | 
			
		||||
             description: "Start the Comunic Server (default action)".to_string(),
 | 
			
		||||
             arguments: vec![],
 | 
			
		||||
             function: Box::new(serve),
 | 
			
		||||
         }
 | 
			
		||||
     ];
 | 
			
		||||
 | 
			
		||||
     let selected_action = actions
 | 
			
		||||
         .iter()
 | 
			
		||||
         .filter(|p|p.name.eq(&action))
 | 
			
		||||
         .next();
 | 
			
		||||
 | 
			
		||||
     let selected_action = match selected_action {
 | 
			
		||||
         None => {
 | 
			
		||||
             eprintln!("Action {} invalid! For more information try 'help'!", action);
 | 
			
		||||
             std::process::exit(-1);
 | 
			
		||||
         }
 | 
			
		||||
         Some(a) => a
 | 
			
		||||
     };
 | 
			
		||||
 | 
			
		||||
     if selected_action.arguments.len() != args.len() - 2 {
 | 
			
		||||
         eprintln!("Invalid number of arguments!");
 | 
			
		||||
         std::process::exit(-2);
 | 
			
		||||
     }
 | 
			
		||||
 | 
			
		||||
     let func =  (selected_action.function)();
 | 
			
		||||
     func.await*/
 | 
			
		||||
    serve()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Start Comunic Server (main action)
 | 
			
		||||
fn serve() -> std::io::Result<()> {
 | 
			
		||||
    let t = std::thread::spawn(|| {
 | 
			
		||||
        let sys = actix::System::new("sys");
 | 
			
		||||
 | 
			
		||||
        let promise = async {
 | 
			
		||||
            // Start cleanup thread
 | 
			
		||||
            cleanup_thread::start().expect("Failed to start cleanup thread!");
 | 
			
		||||
 | 
			
		||||
            // Start the server
 | 
			
		||||
            server::start_server(conf()).await
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        tokio::runtime::Runtime::new().unwrap().block_on(promise)
 | 
			
		||||
            .expect("Failed to start server!");
 | 
			
		||||
 | 
			
		||||
        let _ = sys.run();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    t.join().unwrap();
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user