Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
37 changes: 23 additions & 14 deletions common/src/config.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
Expand All @@ -53,7 +53,8 @@ fn variable_placeholder_substitute(mut builder: c::ConfigBuilder<DefaultState>)
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();
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
}
}
90 changes: 0 additions & 90 deletions lunar/src-tauri/config.toml

This file was deleted.

12 changes: 4 additions & 8 deletions lunar/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@ 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");
}

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(())
})
Expand Down
4 changes: 1 addition & 3 deletions lunar/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
"providerShortName": null,
"signingIdentity": null
},
"resources": [
"config.toml"
],
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
Expand Down