From 50c2753426664c1b9cabd0d495d7070b7933b86c Mon Sep 17 00:00:00 2001 From: TheDancingDeveloper Date: Tue, 11 Aug 2026 09:16:05 +0000 Subject: [PATCH] fix: correct SABnzbd priority numeric mapping (#71) sab_priority_to_priority mapped 0/1/2/-100/3 to Low/Normal/High/Force, shifted by one from SABnzbd's real numeric codes (constants.py: Low=-1, Normal=0, High=1, Force=2, Default=-100, Repair=3) and contradicting sab_priority_matches, which already used the correct table for queue filtering. Any client setting priority via addfile/addurl/priority-change got the wrong priority applied. --- crates/nzb-web/src/sabnzbd_compat.rs | 40 +++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/crates/nzb-web/src/sabnzbd_compat.rs b/crates/nzb-web/src/sabnzbd_compat.rs index 399e1dc..a6f26a9 100644 --- a/crates/nzb-web/src/sabnzbd_compat.rs +++ b/crates/nzb-web/src/sabnzbd_compat.rs @@ -1230,10 +1230,13 @@ fn handle_rename(state: &AppState, req: &SabApiRequest) -> Json Priority { match s.trim() { - "-100" | "3" => Priority::Force, - "2" => Priority::High, - "1" => Priority::Normal, - "0" => Priority::Low, + "-1" => Priority::Low, + "0" | "-100" => Priority::Normal, + "1" => Priority::High, + // SABnzbd's Force (2) and Repair (3) priorities both mean "jump the + // queue"; RustNZB has no separate Repair concept, so both map to + // our highest priority. + "2" | "3" => Priority::Force, _ => Priority::Normal, } } @@ -2148,4 +2151,33 @@ mod tests { sab_contract::golden(&contents); } } + + /// Numeric priority codes per SABnzbd 5.1.x `sabnzbd/constants.py`: + /// FORCE_PRIORITY=2, HIGH_PRIORITY=1, NORMAL_PRIORITY=0, LOW_PRIORITY=-1, + /// DEFAULT_PRIORITY=-100 (displayed/treated as Normal), REPAIR_PRIORITY=3. + #[test] + fn sab_priority_to_priority_matches_upstream_numeric_codes() { + assert_eq!(sab_priority_to_priority("-1"), Priority::Low); + assert_eq!(sab_priority_to_priority("0"), Priority::Normal); + assert_eq!(sab_priority_to_priority("1"), Priority::High); + assert_eq!(sab_priority_to_priority("2"), Priority::Force); + assert_eq!(sab_priority_to_priority("3"), Priority::Force); + assert_eq!(sab_priority_to_priority("-100"), Priority::Normal); + } + + /// The numeric codes accepted when *setting* a priority must agree with + /// the codes `sab_priority_matches` uses when *filtering* the queue by + /// priority -- a prior regression let these two tables diverge silently. + #[test] + fn sab_priority_to_priority_agrees_with_sab_priority_matches() { + for (priority, numeric) in [ + (Priority::Low, "-1"), + (Priority::Normal, "0"), + (Priority::High, "1"), + (Priority::Force, "2"), + ] { + assert_eq!(sab_priority_to_priority(numeric), priority); + assert!(sab_priority_matches(priority, numeric)); + } + } }