Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions crates/nzb-web/src/sabnzbd_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,10 +1261,13 @@ fn handle_rename(state: &AppState, req: &SabApiRequest) -> Json<serde_json::Valu
/// Convert arr-protocol priority string to our Priority enum.
fn sab_priority_to_priority(s: &str) -> 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,
}
}
Expand Down Expand Up @@ -2180,6 +2183,35 @@ mod tests {
}
}

/// 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));
}
}

const SAMPLE_NZB: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">
<file poster="test@example.com" date="1234567890" subject="test.rar (1/2)">
Expand Down