| 106 | } |
| 107 | |
| 108 | async fn reload(&self) -> Result<(), ApiError> { |
| 109 | // Load map index |
| 110 | let index_path = self.maps_dir.join("index.json"); |
| 111 | if index_path.exists() { |
| 112 | let json = tokio::fs::read_to_string(&index_path).await?; |
| 113 | let index: MapIndex = serde_json::from_str(&json)?; |
| 114 | |
| 115 | let mut maps = self.maps.write().await; |
| 116 | maps.clear(); |
| 117 | |
| 118 | for entry in index.maps { |
| 119 | let manifest_path = self.maps_dir.join(&entry.name).join("manifest.json"); |
| 120 | if manifest_path.exists() { |
| 121 | let json = tokio::fs::read_to_string(&manifest_path).await?; |
| 122 | let manifest: MapManifest = serde_json::from_str(&json)?; |
| 123 | maps.insert(manifest.id, manifest); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | info!("Loaded {} maps", maps.len()); |
| 128 | } |
| 129 | |
| 130 | // Load sessions |
| 131 | let sessions_path = self.maps_dir.join("sessions.json"); |
| 132 | if sessions_path.exists() { |
| 133 | let json = tokio::fs::read_to_string(&sessions_path).await?; |
| 134 | let sessions_vec: Vec<Session> = serde_json::from_str(&json)?; |
| 135 | |
| 136 | let mut sessions = self.sessions.write().await; |
| 137 | sessions.clear(); |
| 138 | |
| 139 | for session in sessions_vec { |
| 140 | sessions.insert(session.id, session); |
| 141 | } |
| 142 | |
| 143 | info!("Loaded {} sessions", sessions.len()); |
| 144 | } |
| 145 | |
| 146 | Ok(()) |
| 147 | } |
| 148 | |
| 149 | fn get_map_dir(&self, map_name: &str) -> PathBuf { |
| 150 | self.maps_dir.join(map_name) |