mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-20 03:22:05 +00:00
fix(ohos): expose valid config enum values
Return protobuf enum values through the OHRS schema API and keep the share-link test on the public config repository module.
This commit is contained in:
@@ -119,7 +119,11 @@ fn enum_options(kind: Kind) -> Vec<FieldOption> {
|
||||
.values()
|
||||
.map(|value| FieldOption {
|
||||
label: value.name().to_string(),
|
||||
value: value.number().to_string(),
|
||||
// protobuf JSON uses enum names rather than their numeric wire values.
|
||||
// Returning the number here made ArkTS write (for example) `1`, while
|
||||
// NetworkConfig deserialization expects `"None"`, so field-level saves
|
||||
// were rejected by the repository validation step.
|
||||
value: value.name().to_string(),
|
||||
})
|
||||
.collect(),
|
||||
_ => Vec::new(),
|
||||
@@ -410,5 +414,17 @@ mod tests {
|
||||
.iter()
|
||||
.any(|option| option.label == "PublicServer")
|
||||
);
|
||||
|
||||
let data_compress_algo = schema
|
||||
.children
|
||||
.iter()
|
||||
.find(|field| field.name == "data_compress_algo")
|
||||
.expect("data_compress_algo field");
|
||||
let none = data_compress_algo
|
||||
.enum_options
|
||||
.iter()
|
||||
.find(|option| option.label == "None")
|
||||
.expect("compression None option");
|
||||
assert_eq!(none.value, "None");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ pub fn import_config_share_link(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::config_repo::{create_config_record, init_config_store};
|
||||
use crate::config::repository::{create_config_record, init_config_store};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
fn test_root() -> String {
|
||||
|
||||
@@ -63,6 +63,7 @@ use easytier::common::{
|
||||
use easytier::instance::factory::{NativeInstanceManager, native_instance_manager_with_runtime};
|
||||
use easytier::proto::api::manage::NetworkConfig;
|
||||
use easytier::proto::api::manage::NetworkingMethod;
|
||||
use easytier::proto::common::CompressionAlgoPb;
|
||||
use easytier::web_client::{WebClient, WebClientHooks, run_web_client};
|
||||
use kernel_bridge::{
|
||||
start_local_socket_server as start_local_socket_server_inner,
|
||||
@@ -669,8 +670,11 @@ fn resolve_instance_id_inner(instance_name: &str) -> Option<String> {
|
||||
}
|
||||
|
||||
pub(crate) fn build_default_network_config_json() -> Result<String, String> {
|
||||
let config = NetworkConfig::new_from_config(TomlConfigLoader::default())
|
||||
let mut config = NetworkConfig::new_from_config(TomlConfigLoader::default())
|
||||
.map_err(|e| format!("default_network_config failed {}", e))?;
|
||||
// HarmonyOS 的配置编辑页将压缩算法作为显式选项展示。新建实例默认
|
||||
// 使用 NONE,避免在用户没有主动选择时增加压缩开销。
|
||||
config.data_compress_algo = Some(CompressionAlgoPb::None as i32);
|
||||
serde_json::to_string(&config).map_err(|e| format!("default_network_config failed {}", e))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user