mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-19 12:46:39 +08:00
fix(config): 完成生产配置向 config.toml 的迁移
This commit is contained in:
@@ -7302,9 +7302,6 @@ fn parse_args_with_env(
|
||||
if let Some(config_file) = config_file {
|
||||
config_file.apply_to_options(&mut options)?;
|
||||
}
|
||||
if env_lookup("BAT_SKIP_ENV_FILE").is_some() {
|
||||
terminal_output::print_deprecated_env_file_warning();
|
||||
}
|
||||
// `BAT_*` 环境变量先作为默认值写入,不标记 explicit;命令行参数随后解析,
|
||||
// 逐字段覆盖。工具/代理的"非默认"判断以 config.toml + 环境变量后的基线为准,
|
||||
// 保证 status/stop/logs 在用户已配置默认值时不误判为显式传了同步参数。
|
||||
|
||||
@@ -75,6 +75,31 @@ lease_seconds = 300
|
||||
retry_backoff_seconds = 5
|
||||
max_tasks = ''
|
||||
worker_id = ''
|
||||
|
||||
# Go bat-api consumes this shared section. Rust bat ignores it.
|
||||
[api]
|
||||
listen = ':18080'
|
||||
public_base_url = 'http://127.0.0.1:18080'
|
||||
state_dir = '/tmp/bat-pid'
|
||||
socket_path = ''
|
||||
resource_root = ''
|
||||
server_info_file = ''
|
||||
require_indexed = true
|
||||
verify_size = true
|
||||
rpc_timeout = '30s'
|
||||
refresh_interval = '1m'
|
||||
auth_token = ''
|
||||
auth_query_param = 'bat_token'
|
||||
auth_exempt_paths = []
|
||||
trust_proxy_headers = false
|
||||
access_log = false
|
||||
rate_limit_rps = 0
|
||||
rate_limit_burst = 0
|
||||
max_resource_page_limit = 1000
|
||||
database_url = ''
|
||||
database_password = ''
|
||||
redis_url = ''
|
||||
redis_password = ''
|
||||
"#;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
@@ -164,6 +189,7 @@ struct TranslationWorkerSection {
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum SectionPath {
|
||||
Api,
|
||||
Runtime,
|
||||
Resource,
|
||||
ResourceServerInfo,
|
||||
@@ -405,6 +431,9 @@ impl BatConfigFile {
|
||||
value: &str,
|
||||
line_number: usize,
|
||||
) -> anyhow::Result<()> {
|
||||
if section == SectionPath::Api {
|
||||
return Ok(());
|
||||
}
|
||||
match (section, key) {
|
||||
(SectionPath::Runtime, "state_dir") => {
|
||||
self.runtime.state_dir = Some(parse_required_path(
|
||||
@@ -708,6 +737,7 @@ fn parse_section_header(line: &str, line_number: usize) -> anyhow::Result<Sectio
|
||||
}
|
||||
}
|
||||
match parts.as_slice() {
|
||||
["api"] => Ok(SectionPath::Api),
|
||||
["runtime"] => Ok(SectionPath::Runtime),
|
||||
["resource"] => Ok(SectionPath::Resource),
|
||||
["resource", "server_info"] => Ok(SectionPath::ResourceServerInfo),
|
||||
@@ -1071,6 +1101,21 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_api_section_is_ignored_by_bat() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
write_private_config(
|
||||
&temp.path().join(CONFIG_FILE_NAME),
|
||||
"[api]\nunknown_api_key = 'owned-by-go'\n[resource]\noutput_root = '/srv/resources'\n",
|
||||
);
|
||||
|
||||
let loaded = load_from_binary_dir(temp.path()).unwrap().unwrap();
|
||||
assert_eq!(
|
||||
loaded.resource.output_root,
|
||||
Some(PathBuf::from("/srv/resources"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn example_config_is_never_loaded_as_actual_config() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
|
||||
@@ -85,10 +85,6 @@ pub(super) fn print_config_template_warning(path: &Path, error: impl std::fmt::D
|
||||
);
|
||||
}
|
||||
|
||||
pub(super) fn print_deprecated_env_file_warning() {
|
||||
eprintln!("警告:BAT_SKIP_ENV_FILE 已废弃且不再影响启动,已忽略");
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(super) struct ProgressLogger {
|
||||
enabled: bool,
|
||||
|
||||
Reference in New Issue
Block a user