Skip to content

Commit

Permalink
🐛 Fix for type mismatch on rare occasions
Browse files Browse the repository at this point in the history
  • Loading branch information
ThijmenGThN authored Mar 14, 2024
2 parents e6acce2 + 95234a5 commit fdedb2e
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ use serde::Deserialize;

use crate::{logger, parser, render, system};

#[derive(Deserialize)]
struct Response {
records: Vec<Record>,
}

#[derive(Deserialize)]
struct Record {
id: u32,
size: f64,
movie: Option<NestedRecord>,
series: Option<NestedRecord>,
timeleft: Option<String>,
}

#[derive(Deserialize)]
struct NestedRecord {
title: String,
}

#[derive(Debug, Deserialize, Clone)]
pub struct Torrent {
pub id: u32,
pub name: String,
pub size: u64,
pub eta: u64,
}

// Obtains Torrents from Radarr or Sonarr.
pub fn get(url: &String, platform: &String) -> Vec<Torrent> {
// Request active torrents in queue from the Radarr or Sonarr API.
Expand Down Expand Up @@ -66,7 +93,7 @@ pub fn get(url: &String, platform: &String) -> Vec<Torrent> {
torrents.push(Torrent {
id: record.id,
name,
size: record.size,
size: record.size as u64,
eta: timeleft_ms,
});
});
Expand Down Expand Up @@ -167,32 +194,3 @@ pub fn delete(url: &String) {
}
}
}

// ----- STRUCTS -----

#[derive(Deserialize)]
struct Response {
records: Vec<Record>,
}

#[derive(Deserialize)]
struct Record {
id: u32,
size: u64,
movie: Option<NestedRecord>,
series: Option<NestedRecord>,
timeleft: Option<String>,
}

#[derive(Deserialize)]
struct NestedRecord {
title: String,
}

#[derive(Debug, Deserialize, Clone)]
pub struct Torrent {
pub id: u32,
pub name: String,
pub size: u64,
pub eta: u64,
}

0 comments on commit fdedb2e

Please sign in to comment.