(
State(state): State<DashboardState>,
Json(patch): Json<Value>,
)
| 49 | } |
| 50 | |
| 51 | pub(crate) async fn patch_project_settings( |
| 52 | State(state): State<DashboardState>, |
| 53 | Json(patch): Json<Value>, |
| 54 | ) -> ApiResult { |
| 55 | let patch = serde_json::from_value::<ProjectSettingsPatch>(patch) |
| 56 | .map_err(|err| patch_shape_error("project settings", &err))?; |
| 57 | |
| 58 | let mut errors = Vec::new(); |
| 59 | if let Some(globs) = &patch.include { |
| 60 | validate_globs("include", globs, &mut errors); |
| 61 | } |
| 62 | if let Some(globs) = &patch.exclude { |
| 63 | validate_globs("exclude", globs, &mut errors); |
| 64 | } |
| 65 | if patch.max_file_size == Some(0) { |
| 66 | errors.push(validation_error( |
| 67 | "max_file_size", |
| 68 | "max_file_size must be at least 1 byte", |
| 69 | )); |
| 70 | } |
| 71 | if !errors.is_empty() { |
| 72 | return Err(validation_failed(&errors)); |
| 73 | } |
| 74 | |
| 75 | let current = load_config(&state.project_root).map_err(|err| internal_error(&err))?; |
| 76 | let updated = TraceDecayConfig { |
| 77 | include: patch.include.unwrap_or_else(|| current.include.clone()), |
| 78 | exclude: patch.exclude.unwrap_or_else(|| current.exclude.clone()), |
| 79 | max_file_size: patch.max_file_size.unwrap_or(current.max_file_size), |
| 80 | extract_docstrings: patch |
| 81 | .extract_docstrings |
| 82 | .unwrap_or(current.extract_docstrings), |
| 83 | track_call_sites: patch.track_call_sites.unwrap_or(current.track_call_sites), |
| 84 | git_ignore: patch.git_ignore.unwrap_or(current.git_ignore), |
| 85 | ..current.clone() |
| 86 | }; |
| 87 | let resync_recommended = updated != current; |
| 88 | if resync_recommended { |
| 89 | save_config(&state.project_root, &updated).map_err(|err| internal_error(&err))?; |
| 90 | } |
| 91 | |
| 92 | let mut payload = settings_payload(&state).await?; |
| 93 | payload["resync_recommended"] = json!(resync_recommended); |
| 94 | Ok(Json(payload)) |
| 95 | } |
| 96 | |
| 97 | pub(crate) async fn patch_user_settings( |
| 98 | State(state): State<DashboardState>, |
nothing calls this directly
no test coverage detected