rush_sync_server/server/
mod.rs1pub mod config;
6pub mod instance;
7pub mod manager;
8pub mod middleware;
9pub mod routes;
10
11use chrono::{DateTime, Utc};
12pub use config::{ServerConfig, ServerMode};
13pub use instance::ServerInstance;
14pub use manager::ServerManager;
15use sha2::{Digest, Sha256};
16use uuid::Uuid;
17
18#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
20pub enum ServerStatus {
21 Stopped,
22 Starting,
23 Running,
24 Stopping,
25 Error(String),
26}
27
28#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
30pub struct ServerInfo {
31 pub id: String,
32 pub hash: String,
33 pub port: u16,
34 pub mode: ServerMode,
35 pub status: ServerStatus,
36 pub working_dir: std::path::PathBuf,
37 pub created_at: DateTime<Utc>,
38 pub last_modified: Option<DateTime<Utc>>,
39}
40
41impl ServerInfo {
42 pub fn new(port: u16, mode: ServerMode) -> Self {
44 let id = Uuid::new_v4().to_string();
45 let hash = format!("{:x}", Sha256::digest(id.as_bytes()))[..8].to_string();
46
47 let working_dir = std::path::PathBuf::from(format!("servers/server_{hash}"));
49
50 Self {
51 id, hash, port,
54 mode,
55 status: ServerStatus::Stopped,
56 working_dir, created_at: Utc::now(),
58 last_modified: None,
59 }
60 }
61
62 pub fn debug_info(&self) -> String {
64 format!(
65 "🖥️ Server {} ({})\n Port: {}\n Mode: {:?}\n Status: {:?}\n Dir: {}",
66 self.id[..8].to_uppercase(),
67 self.hash,
68 self.port,
69 self.mode,
70 self.status,
71 self.working_dir.display()
72 )
73 }
74}