diff --git a/.gitmodules b/.gitmodules index 95523bd3c..e7f6d2a70 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "neptune/libs/ztm"] path = neptune/libs/ztm - url = git@github.com:flomesh-io/ztm.git + url = https://github.com/flomesh-io/ztm.git ignore = dirty diff --git a/common/src/config.rs b/common/src/config.rs index 223572ce6..fb1d92c1b 100644 --- a/common/src/config.rs +++ b/common/src/config.rs @@ -1,12 +1,12 @@ -use std::cell::RefCell; -use std::collections::HashMap; use c::{ConfigError, FileFormat}; use config as c; +use config::builder::DefaultState; +use config::{Source, ValueKind}; use serde::{Deserialize, Serialize}; +use std::cell::RefCell; +use std::collections::HashMap; use std::path::PathBuf; use std::rc::Rc; -use config::builder::DefaultState; -use config::{Source, ValueKind}; #[derive(Serialize, Deserialize, Debug, Default, Clone)] pub struct Config { @@ -26,7 +26,7 @@ impl Config { let builder = c::Config::builder() .add_source(c::File::new(path, FileFormat::Toml)) .add_source(c::Environment::with_prefix("mega")); // e.g. MEGA_BASE_DIR == base_dir - // support ${} variable substitution + // support ${} variable substitution let config = variable_placeholder_substitute(builder); Config::from_config(config) @@ -53,7 +53,8 @@ fn variable_placeholder_substitute(mut builder: c::ConfigBuilder) let config = builder.clone().build().unwrap(); // initial config let mut vars = HashMap::new(); // top-level variables - for (k, mut v) in config.collect().unwrap() { // a copy + for (k, mut v) in config.collect().unwrap() { + // a copy if let ValueKind::String(str) = &v.kind { if envsubst::is_templated(str) { let new_str = envsubst::substitute(str, &vars).unwrap(); @@ -101,7 +102,11 @@ fn traverse_config(key: &str, value: &c::Value, f: &impl Fn(&str, &c::Value)) { ValueKind::Table(table) => { for (k, v) in table.iter() { // join keys by '.' - let new_key = if key.is_empty() { k.clone() } else { format!("{}.{}", key, k) }; + let new_key = if key.is_empty() { + k.clone() + } else { + format!("{}.{}", key, k) + }; traverse_config(&new_key, v, f); } } @@ -139,9 +144,9 @@ pub struct DbConfig { impl Default for DbConfig { fn default() -> Self { Self { - db_type: String::new(), - db_path: String::new(), - db_url: String::new(), + db_type: String::from("sqlite"), + db_path: String::from("/tmp/.mega/mega.db"), + db_url: String::from("postgres://mega:mega@localhost:5432/mega"), max_connection: 32, min_connection: 16, sqlx_logging: false, @@ -238,13 +243,17 @@ impl Default for ZTMConfig { } } -#[derive(Serialize, Deserialize, Debug, Clone, Default)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct LFSConfig { pub enable_split: bool, - #[serde(default = "default_split_size")] pub split_size: usize, } -fn default_split_size() -> usize { - 1024 * 1024 * 20 // 20MB +impl Default for LFSConfig { + fn default() -> Self { + Self { + enable_split: true, + split_size: 1024 * 1024 * 1024, + } + } } diff --git a/lunar/src-tauri/config.toml b/lunar/src-tauri/config.toml deleted file mode 100644 index 8f3085d8b..000000000 --- a/lunar/src-tauri/config.toml +++ /dev/null @@ -1,90 +0,0 @@ -# Filling the following environment variables with values you set -## Logging Configuration -[log] -# The path which log file is saved -log_path = "/tmp/.mega/logs" - -# log level -level = "debug" - -# print std log in console, disable it on production for performance -print_std = true - - -[database] -# "sqlite" | "postgres" -# "sqlite" will use `db_path` and ignore `db_url` -db_type = "sqlite" - -# used for sqlite -db_path = "./lunar-mega.db" - -# database connection url -db_url = "postgres://mega:mega@localhost:5432/mega" - -# db max connection, setting it to twice the number of CPU cores would be appropriate. -max_connection = 32 - -# db min connection, setting it to the number of CPU cores would be appropriate. -min_connection = 16 - -# Whether to disabling SQLx Log -sqlx_logging = false - - -[ssh] -ssh_key_path = "/tmp/.mega/ssh" - -[storage] -# raw object stroage type, can be `local` or `remote` -raw_obj_storage_type = "LOCAL" - -## If the object file size exceeds the threshold value, it will be handled by file storage instead of the database, Unit is KB -big_obj_threshold = 1024 - -# set the local path of the project storage -raw_obj_local_path = "/tmp/.mega/objects" - -lfs_obj_local_path = "/tmp/.mega/lfs" - -obs_access_key = "" -obs_secret_key = "" - -# cloud storage region -obs_region = "cn-east-3" - -# Override the endpoint URL used for remote storage services -obs_endpoint = "https://obs.cn-east-3.myhuaweicloud.com" - - -[monorepo] -## Only import directory support multi-branch commit and tag, monorepo only support main branch -## Mega treats files under this directory as import repo and other directories as monorepo -import_dir = "/third-part" - - -[pack] -# The maximum memory used by decode, Unit is GB -pack_decode_mem_size = 4 - -# The location where the object stored when the memory used by decode exceeds the limit -pack_decode_cache_path = "/tmp/.mega/cache" - -clean_cache_after_decode = true - -# The maximum meesage size in channel buffer while decode -channel_message_size = 1_000_000 - - -[ztm] -ca = "http://127.0.0.1:9999" -hub = "http://127.0.0.1:8888" -agent = "http://127.0.0.1:7777" - -[lfs] -## IMPORTANT: The 'enable_split' feature can only be enabled for new databases. Existing databases do not support this feature. -# Enable or disable splitting large files into smaller chunks -enable_split = true # Default is disabled. Set to true to enable file splitting. - -# Size of each file chunk when splitting is enabled, in bytes. Ignored if splitting is disabled. -split_size = 20971520 # Default size is 20MB (20971520 bytes) \ No newline at end of file diff --git a/lunar/src-tauri/src/main.rs b/lunar/src-tauri/src/main.rs index 479b79973..71cbda462 100644 --- a/lunar/src-tauri/src/main.rs +++ b/lunar/src-tauri/src/main.rs @@ -6,8 +6,8 @@ fn hello_string(name: &str) -> String { format!("Hello from Rust, {}!", name) } -fn start_mega(config_path: &str) { - let args_str = format!("-c \"{}\" service http", config_path); +fn start_mega() { + let args_str = "service http".to_string(); let args = args_str.split(' ').collect(); mega::cli::parse(Some(args)).expect("failed to start mega"); } @@ -15,13 +15,9 @@ fn start_mega(config_path: &str) { fn main() { tauri::Builder::default() .invoke_handler(tauri::generate_handler![hello_string]) - .setup(|app| { - let resource_path = app - .path_resolver() - .resolve_resource("config.toml") - .expect("failed to resolve config.toml resource"); + .setup(|_| { std::thread::spawn(move || { - start_mega(resource_path.to_str().unwrap()); + start_mega(); }); Ok(()) }) diff --git a/lunar/src-tauri/tauri.conf.json b/lunar/src-tauri/tauri.conf.json index 72b8bfa65..73a335ed4 100644 --- a/lunar/src-tauri/tauri.conf.json +++ b/lunar/src-tauri/tauri.conf.json @@ -44,9 +44,7 @@ "providerShortName": null, "signingIdentity": null }, - "resources": [ - "config.toml" - ], + "resources": [], "shortDescription": "", "targets": "all", "windows": {