rush_sync_server/server/
types.rs

1// Updated src/server/types.rs
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4use std::sync::{Arc, RwLock};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ServerInfo {
8    pub id: String,
9    pub name: String,
10    pub port: u16,
11    pub status: ServerStatus,
12    pub created_at: String,
13    pub created_timestamp: u64,
14}
15
16impl Default for ServerInfo {
17    fn default() -> Self {
18        let now = std::time::SystemTime::now()
19            .duration_since(std::time::UNIX_EPOCH)
20            .unwrap_or_default()
21            .as_secs();
22
23        Self {
24            id: String::new(),
25            name: String::new(),
26            port: 0,
27            status: ServerStatus::Stopped,
28            created_at: chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string(),
29            created_timestamp: now,
30        }
31    }
32}
33
34#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
35pub enum ServerStatus {
36    Stopped,
37    Running,
38    Failed,
39}
40
41impl std::fmt::Display for ServerStatus {
42    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43        match self {
44            ServerStatus::Stopped => write!(f, "STOPPED"),
45            ServerStatus::Running => write!(f, "RUNNING"),
46            ServerStatus::Failed => write!(f, "FAILED"),
47        }
48    }
49}
50
51#[derive(Debug, Clone)]
52pub struct ServerData {
53    pub id: String,
54    pub port: u16,
55    pub name: String,
56}
57
58pub type ServerMap = Arc<RwLock<HashMap<String, ServerInfo>>>;
59pub type ServerHandles = Arc<RwLock<HashMap<String, actix_web::dev::ServerHandle>>>;
60
61// Updated ServerContext - removed hardcoded port_range_start
62#[derive(Debug, Clone)]
63pub struct ServerContext {
64    pub servers: ServerMap,
65    pub handles: ServerHandles,
66    // Removed port_range_start - now comes from Config
67}
68
69impl Default for ServerContext {
70    fn default() -> Self {
71        Self {
72            servers: Arc::new(RwLock::new(HashMap::new())),
73            handles: Arc::new(RwLock::new(HashMap::new())),
74        }
75    }
76}