fix(web): persist agent drivers under data dir (#2147)
This commit is contained in:
1 parent
55bfa11bd1
commit
b330b00335
1 file changed
+26
-2
@@ -32,6 +32,14 @@ fn web_body_limit_bytes() -> usize {
|
||||
mb.saturating_mul(1024 * 1024)
|
||||
}
|
||||
|
||||
fn web_agent_dir(data_dir: &std::path::Path) -> std::path::PathBuf {
|
||||
web_agent_dir_from_env(data_dir, std::env::var("DBX_AGENT_DIR").ok())
|
||||
}
|
||||
|
||||
fn web_agent_dir_from_env(data_dir: &std::path::Path, agent_dir: Option<String>) -> std::path::PathBuf {
|
||||
agent_dir.map(std::path::PathBuf::from).unwrap_or_else(|| data_dir.join("agents"))
|
||||
}
|
||||
|
||||
fn normalize_public_base_path(value: Option<String>) -> String {
|
||||
let trimmed = value
|
||||
.unwrap_or_else(|| "/".to_string())
|
||||
@@ -53,7 +61,7 @@ fn normalize_public_base_path(value: Option<String>) -> String {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::normalize_public_base_path;
|
||||
use super::{normalize_public_base_path, web_agent_dir_from_env};
|
||||
|
||||
#[test]
|
||||
fn normalize_public_base_path_defaults_to_root() {
|
||||
@@ -74,6 +82,21 @@ mod tests {
|
||||
fn normalize_public_base_path_rejects_invalid_characters() {
|
||||
normalize_public_base_path(Some("/dbx admin".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn web_agent_dir_defaults_under_data_dir() {
|
||||
let data_dir = std::path::PathBuf::from("/app/data");
|
||||
assert_eq!(web_agent_dir_from_env(&data_dir, None), data_dir.join("agents"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn web_agent_dir_uses_explicit_env_override() {
|
||||
let data_dir = std::path::PathBuf::from("/app/data");
|
||||
assert_eq!(
|
||||
web_agent_dir_from_env(&data_dir, Some("/custom/agents".to_string())),
|
||||
std::path::PathBuf::from("/custom/agents")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mq-admin")]
|
||||
@@ -148,9 +171,10 @@ async fn main() {
|
||||
let db_path = data_dir.join("dbx.db");
|
||||
let storage = Storage::open(&db_path).await.expect("Failed to open storage");
|
||||
storage.migrate_from_json(&data_dir).await.expect("Failed to migrate JSON data");
|
||||
Arc::new(AppState::new_with_plugin_dir_and_app_version(
|
||||
Arc::new(AppState::new_with_plugin_and_agent_dir_and_app_version(
|
||||
storage,
|
||||
data_dir.join("plugins"),
|
||||
web_agent_dir(&data_dir),
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
))
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user