feat(torrents): add aggregate upload limit control

This commit is contained in:
NimBold
2026-08-02 23:36:48 +03:30
parent b2c86a2ec4
commit cba485ef44
16 changed files with 466 additions and 95 deletions
+22
View File
@@ -475,6 +475,10 @@ fn validate_settings(settings: &mut PersistedSettings) {
settings.max_concurrent_downloads = settings.max_concurrent_downloads.min(12);
settings.per_server_connections = settings.per_server_connections.clamp(1, 16);
settings.max_automatic_retries = settings.max_automatic_retries.clamp(0, 10);
settings.torrent_overall_upload_limit = crate::normalize_speed_limit_for_aria2(
&settings.torrent_overall_upload_limit,
)
.unwrap_or_default();
settings.torrent_max_open_files = crate::queue::normalize_torrent_max_open_files(
settings.torrent_max_open_files,
)
@@ -692,6 +696,7 @@ fn default_settings() -> PersistedSettings {
approved_download_roots: Vec::new(),
max_concurrent_downloads: 3,
global_speed_limit: String::new(),
torrent_overall_upload_limit: String::new(),
speed_limit_preset_values: vec![1.0, 5.0, 10.0],
logs_enabled: false,
is_sidebar_visible: true,
@@ -793,6 +798,7 @@ mod tests {
"state": {
"maxConcurrentDownloads": 7,
"globalSpeedLimit": "2M",
"torrentOverallUploadLimit": "1.5M",
"sidebarPosition": "right",
"scheduler": {
"enabled": true,
@@ -811,6 +817,7 @@ mod tests {
assert_eq!(settings.max_concurrent_downloads, 7);
assert_eq!(settings.global_speed_limit, "2M");
assert_eq!(settings.torrent_overall_upload_limit, "1.5M");
assert_eq!(settings.sidebar_position, "right");
assert_eq!(settings.speed_limit_preset_values, vec![1.0, 5.0, 10.0]);
assert!(!settings.logs_enabled);
@@ -836,6 +843,7 @@ mod tests {
assert_eq!(settings.max_concurrent_downloads, 5);
assert_eq!(settings.global_speed_limit, "512K");
assert!(settings.torrent_overall_upload_limit.is_empty());
assert_eq!(settings.last_custom_speed_limit_unit, "MB/s");
assert_eq!(settings.speed_limit_preset_values, vec![1.0, 5.0, 10.0]);
assert!(!settings.logs_enabled);
@@ -858,6 +866,20 @@ mod tests {
assert!(settings.logs_enabled);
assert!(!settings.scheduler.enabled);
assert!(settings.global_speed_limit.is_empty());
assert!(settings.torrent_overall_upload_limit.is_empty());
}
#[test]
fn normalizes_invalid_torrent_overall_upload_limit_to_unlimited() {
let stored = json!({
"state": {
"torrentOverallUploadLimit": "not-a-rate"
}
});
let settings = decode_stored_settings(&Value::String(stored.to_string())).unwrap();
assert!(settings.torrent_overall_upload_limit.is_empty());
}
#[test]