1
This commit is contained in:
@@ -937,15 +937,41 @@ impl AdminRuntime {
|
||||
}
|
||||
|
||||
fn build_oss_client(config: &AppConfig) -> Result<Option<OssClient>, AppStateInitError> {
|
||||
let has_any_oss_field = config.oss_bucket.is_some()
|
||||
|| config.oss_endpoint.is_some()
|
||||
|| config.oss_access_key_id.is_some()
|
||||
|| config.oss_access_key_secret.is_some();
|
||||
let oss_fields = [
|
||||
("ALIYUN_OSS_BUCKET", config.oss_bucket.as_deref()),
|
||||
("ALIYUN_OSS_ENDPOINT", config.oss_endpoint.as_deref()),
|
||||
(
|
||||
"ALIYUN_OSS_ACCESS_KEY_ID",
|
||||
config.oss_access_key_id.as_deref(),
|
||||
),
|
||||
(
|
||||
"ALIYUN_OSS_ACCESS_KEY_SECRET",
|
||||
config.oss_access_key_secret.as_deref(),
|
||||
),
|
||||
];
|
||||
let has_any_oss_field = oss_fields
|
||||
.iter()
|
||||
.any(|(_, value)| value.is_some_and(|value| !value.trim().is_empty()));
|
||||
|
||||
if !has_any_oss_field {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let missing_fields = oss_fields
|
||||
.iter()
|
||||
.filter_map(|(name, value)| match value {
|
||||
Some(value) if !value.trim().is_empty() => None,
|
||||
_ => Some(*name),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
if !missing_fields.is_empty() {
|
||||
warn!(
|
||||
missing_fields = %missing_fields.join(","),
|
||||
"OSS 环境变量配置不完整,跳过 OSS 客户端初始化"
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let oss_config = OssConfig::new(
|
||||
config.oss_bucket.clone().unwrap_or_default(),
|
||||
config.oss_endpoint.clone().unwrap_or_default(),
|
||||
@@ -1085,6 +1111,17 @@ mod tests {
|
||||
assert!(state.creative_agent_gpt5_client().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_state_skips_oss_client_when_oss_config_is_partial() {
|
||||
let mut config = AppConfig::default();
|
||||
config.oss_bucket = Some("genarrative-assets".to_string());
|
||||
config.oss_endpoint = Some("oss-cn-hangzhou.aliyuncs.com".to_string());
|
||||
|
||||
let state = AppState::new(config).expect("state should build with partial oss config");
|
||||
|
||||
assert!(state.oss_client().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_state_builds_creative_agent_gpt5_client_from_apimart_settings() {
|
||||
let mut config = AppConfig::default();
|
||||
|
||||
Reference in New Issue
Block a user