d25ab69d13
Use a shared API request limiter across recursive upload and download traversal so folder detail fetches, file listings, folder auth, and transfers can run concurrently under one budget. Refactor the traversal loops into task-driven pipelines while preserving skip-if-exists, excludes, cleanup, and current output behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
44 lines
1.4 KiB
Rust
44 lines
1.4 KiB
Rust
use std::sync::LazyLock;
|
|
|
|
pub struct Settings {
|
|
/// Base directory for config and cache files.
|
|
/// Controlled by `MDRS_CLIENT_CONFIG_DIRNAME` env var (default: `~/.mdrs-client`).
|
|
pub config_dirname: std::path::PathBuf,
|
|
/// Maximum number of concurrent MDRS API requests used by upload/download.
|
|
/// Controlled by `MDRS_CLIENT_CONCURRENT` env var (default: 10).
|
|
pub concurrent: usize,
|
|
}
|
|
|
|
impl Settings {
|
|
fn load() -> Self {
|
|
let config_dirname = std::env::var("MDRS_CLIENT_CONFIG_DIRNAME")
|
|
.ok()
|
|
.map(|s| {
|
|
if s.starts_with("~/") {
|
|
dirs::home_dir()
|
|
.unwrap_or_else(|| std::path::PathBuf::from("."))
|
|
.join(&s[2..])
|
|
} else {
|
|
std::path::PathBuf::from(&s)
|
|
}
|
|
})
|
|
.unwrap_or_else(|| {
|
|
dirs::home_dir()
|
|
.unwrap_or_else(|| std::path::PathBuf::from("."))
|
|
.join(".mdrs-client")
|
|
});
|
|
|
|
let concurrent = std::env::var("MDRS_CLIENT_CONCURRENT")
|
|
.ok()
|
|
.and_then(|s| s.parse::<usize>().ok())
|
|
.unwrap_or(10);
|
|
|
|
Settings {
|
|
config_dirname,
|
|
concurrent,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub static SETTINGS: LazyLock<Settings> = LazyLock::new(Settings::load);
|