fix: Modified the Sonarr DownloadRecord so that the episode_id is optional to prevent crashes for weird downloads

This commit is contained in:
2025-03-01 14:50:20 -07:00
parent 58723cf3e8
commit 847de75713
7 changed files with 52 additions and 18 deletions
+11 -5
View File
@@ -1,7 +1,7 @@
use anyhow::Result;
use indoc::formatdoc;
use log::{debug, info, warn};
use serde_json::{json, Value};
use serde_json::{json, Number, Value};
use urlencoding::encode;
use super::{Network, NetworkEvent, NetworkResource};
@@ -2321,10 +2321,16 @@ impl Network<'_, '_> {
fn get_episode_status(has_file: bool, downloads_vec: &[DownloadRecord], episode_id: i64) -> String {
if !has_file {
if let Some(download) = downloads_vec
.iter()
.find(|&download| download.episode_id == episode_id)
{
let default_episode_id = Number::from(-1i64);
if let Some(download) = downloads_vec.iter().find(|&download| {
download
.episode_id
.as_ref()
.unwrap_or(&default_episode_id)
.as_i64()
.unwrap()
== episode_id
}) {
if download.status == DownloadStatus::Downloading {
return "Downloading".to_owned();
}