mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-21 11:42:09 +08:00
refactor: structure config validation outcomes
- Replace boolean/string validation results with structured ValidationOutcome values across config validation, profile switching, DNS validation, and script validation. Callers can now distinguish valid, invalid, skipped, and busy states, with invalid results carrying an error kind and message. - Route core config updates through structured outcomes and checked forced updates. Generation and validation failures now discard runtime drafts and surface validation failures instead of relying on empty success messages. - Preserve existing frontend ergonomics by keeping boolean service wrappers where callers only need success, while direct DNS and script validation consumers receive ValidationOutcome. Failed profile editor saves reload the backend-restored file content and synchronize Monaco models so reopened editors show the restored state.
This commit is contained in:
@@ -4,20 +4,17 @@ use super::use_lowercase;
|
||||
use serde_yaml_ng::{self, Mapping, Value};
|
||||
|
||||
fn deep_merge(a: &mut Value, b: Value) {
|
||||
let mut stack: Vec<(*mut Value, Value)> = vec![(a as *mut Value, b)];
|
||||
|
||||
while let Some((a_ptr, b)) = stack.pop() {
|
||||
let a = unsafe { &mut *a_ptr };
|
||||
|
||||
match (a, b) {
|
||||
(Value::Mapping(a_map), Value::Mapping(b_map)) => {
|
||||
for (k, v) in b_map {
|
||||
let child = a_map.entry(k).or_insert(Value::Null);
|
||||
stack.push((child as *mut Value, v));
|
||||
match (a, b) {
|
||||
(Value::Mapping(a_map), Value::Mapping(b_map)) => {
|
||||
for (key, value) in b_map {
|
||||
if let Some(existing) = a_map.get_mut(&key) {
|
||||
deep_merge(existing, value);
|
||||
} else {
|
||||
a_map.insert(key, value);
|
||||
}
|
||||
}
|
||||
(a, b) => *a = b,
|
||||
}
|
||||
(a, b) => *a = b,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user