| 3290 | } |
| 3291 | |
| 3292 | async fn current_project_info() -> Result<ProjectInfo> { |
| 3293 | let cwd = std::env::current_dir() |
| 3294 | .map_err(|e| ApiError::BadRequest(format!("Failed to resolve current directory: {}", e)))?; |
| 3295 | let canonical = cwd |
| 3296 | .canonicalize() |
| 3297 | .map_err(|e| ApiError::BadRequest(format!("Failed to resolve project path: {}", e)))?; |
| 3298 | let project_id = canonical.to_string_lossy().to_string(); |
| 3299 | let project_path = canonical.to_string_lossy().to_string(); |
| 3300 | let default_name = canonical |
| 3301 | .file_name() |
| 3302 | .map(|name| name.to_string_lossy().to_string()) |
| 3303 | .filter(|name| !name.is_empty()) |
| 3304 | .unwrap_or_else(|| "project".to_string()); |
| 3305 | |
| 3306 | let metadata = PROJECT_METADATA.read().await; |
| 3307 | let name = metadata |
| 3308 | .get(&project_id) |
| 3309 | .and_then(|m| m.name.clone()) |
| 3310 | .unwrap_or(default_name); |
| 3311 | let _icon = metadata.get(&project_id).and_then(|m| m.icon.clone()); |
| 3312 | |
| 3313 | Ok(ProjectInfo { |
| 3314 | id: project_id, |
| 3315 | name, |
| 3316 | path: project_path, |
| 3317 | vcs: is_git_repository(&canonical), |
| 3318 | }) |
| 3319 | } |
| 3320 | |
| 3321 | async fn list_projects() -> Result<Json<Vec<ProjectInfo>>> { |
| 3322 | Ok(Json(vec![current_project_info().await?])) |