feat(network): Added the GetIndexers network call for Sonarr
This commit is contained in:
@@ -3,7 +3,7 @@ use chrono::{DateTime, Utc};
|
|||||||
use strum::EnumIter;
|
use strum::EnumIter;
|
||||||
|
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
sonarr_models::{BlocklistItem, DownloadRecord, Episode, Series},
|
sonarr_models::{BlocklistItem, DownloadRecord, Episode, Indexer, Series},
|
||||||
stateful_list::StatefulList,
|
stateful_list::StatefulList,
|
||||||
stateful_table::StatefulTable,
|
stateful_table::StatefulTable,
|
||||||
stateful_tree::StatefulTree,
|
stateful_tree::StatefulTree,
|
||||||
@@ -27,6 +27,7 @@ pub struct SonarrData {
|
|||||||
pub downloads: StatefulTable<DownloadRecord>,
|
pub downloads: StatefulTable<DownloadRecord>,
|
||||||
pub episode_details_modal: Option<EpisodeDetailsModal>,
|
pub episode_details_modal: Option<EpisodeDetailsModal>,
|
||||||
pub quality_profile_map: BiMap<i64, String>,
|
pub quality_profile_map: BiMap<i64, String>,
|
||||||
|
pub indexers: StatefulTable<Indexer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for SonarrData {
|
impl Default for SonarrData {
|
||||||
@@ -42,6 +43,7 @@ impl Default for SonarrData {
|
|||||||
downloads: StatefulTable::default(),
|
downloads: StatefulTable::default(),
|
||||||
episode_details_modal: None,
|
episode_details_modal: None,
|
||||||
quality_profile_map: BiMap::new(),
|
quality_profile_map: BiMap::new(),
|
||||||
|
indexers: StatefulTable::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ mod tests {
|
|||||||
assert!(sonarr_data.downloads.is_empty());
|
assert!(sonarr_data.downloads.is_empty());
|
||||||
assert!(sonarr_data.episode_details_modal.is_none());
|
assert!(sonarr_data.episode_details_modal.is_none());
|
||||||
assert!(sonarr_data.quality_profile_map.is_empty());
|
assert!(sonarr_data.quality_profile_map.is_empty());
|
||||||
|
assert!(sonarr_data.indexers.is_empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,35 @@ pub struct EpisodeFile {
|
|||||||
pub media_info: Option<MediaInfo>,
|
pub media_info: Option<MediaInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct Indexer {
|
||||||
|
#[serde(deserialize_with = "super::from_i64")]
|
||||||
|
pub id: i64,
|
||||||
|
pub name: Option<String>,
|
||||||
|
pub implementation: Option<String>,
|
||||||
|
pub implementation_name: Option<String>,
|
||||||
|
pub config_contract: Option<String>,
|
||||||
|
pub supports_rss: bool,
|
||||||
|
pub supports_search: bool,
|
||||||
|
pub fields: Option<Vec<IndexerField>>,
|
||||||
|
pub enable_rss: bool,
|
||||||
|
pub enable_automatic_search: bool,
|
||||||
|
pub enable_interactive_search: bool,
|
||||||
|
pub protocol: String,
|
||||||
|
#[serde(deserialize_with = "super::from_i64")]
|
||||||
|
pub priority: i64,
|
||||||
|
#[serde(deserialize_with = "super::from_i64")]
|
||||||
|
pub download_client_id: i64,
|
||||||
|
pub tags: Vec<Number>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
|
||||||
|
pub struct IndexerField {
|
||||||
|
pub name: Option<String>,
|
||||||
|
pub value: Option<Value>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Default, Debug, Hash, Clone, PartialEq, Eq, Ord, PartialOrd)]
|
#[derive(Serialize, Deserialize, Default, Debug, Hash, Clone, PartialEq, Eq, Ord, PartialOrd)]
|
||||||
pub struct Language {
|
pub struct Language {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@@ -330,6 +359,7 @@ pub enum SonarrSerdeable {
|
|||||||
DownloadsResponse(DownloadsResponse),
|
DownloadsResponse(DownloadsResponse),
|
||||||
Episode(Episode),
|
Episode(Episode),
|
||||||
Episodes(Vec<Episode>),
|
Episodes(Vec<Episode>),
|
||||||
|
Indexers(Vec<Indexer>),
|
||||||
QualityProfiles(Vec<QualityProfile>),
|
QualityProfiles(Vec<QualityProfile>),
|
||||||
SeriesVec(Vec<Series>),
|
SeriesVec(Vec<Series>),
|
||||||
SystemStatus(SystemStatus),
|
SystemStatus(SystemStatus),
|
||||||
@@ -355,6 +385,7 @@ serde_enum_from!(
|
|||||||
DownloadsResponse(DownloadsResponse),
|
DownloadsResponse(DownloadsResponse),
|
||||||
Episode(Episode),
|
Episode(Episode),
|
||||||
Episodes(Vec<Episode>),
|
Episodes(Vec<Episode>),
|
||||||
|
Indexers(Vec<Indexer>),
|
||||||
QualityProfiles(Vec<QualityProfile>),
|
QualityProfiles(Vec<QualityProfile>),
|
||||||
SeriesVec(Vec<Series>),
|
SeriesVec(Vec<Series>),
|
||||||
SystemStatus(SystemStatus),
|
SystemStatus(SystemStatus),
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
RadarrEvent::GetCollections => self.get_collections().await.map(RadarrSerdeable::from),
|
RadarrEvent::GetCollections => self.get_collections().await.map(RadarrSerdeable::from),
|
||||||
RadarrEvent::GetDownloads => self.get_radarr_downloads().await.map(RadarrSerdeable::from),
|
RadarrEvent::GetDownloads => self.get_radarr_downloads().await.map(RadarrSerdeable::from),
|
||||||
RadarrEvent::GetHostConfig => self.get_host_config().await.map(RadarrSerdeable::from),
|
RadarrEvent::GetHostConfig => self.get_host_config().await.map(RadarrSerdeable::from),
|
||||||
RadarrEvent::GetIndexers => self.get_indexers().await.map(RadarrSerdeable::from),
|
RadarrEvent::GetIndexers => self.get_radarr_indexers().await.map(RadarrSerdeable::from),
|
||||||
RadarrEvent::GetLogs(events) => self
|
RadarrEvent::GetLogs(events) => self
|
||||||
.get_radarr_logs(events)
|
.get_radarr_logs(events)
|
||||||
.await
|
.await
|
||||||
@@ -1395,7 +1395,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_indexers(&mut self) -> Result<Vec<Indexer>> {
|
async fn get_radarr_indexers(&mut self) -> Result<Vec<Indexer>> {
|
||||||
info!("Fetching Radarr indexers");
|
info!("Fetching Radarr indexers");
|
||||||
let event = RadarrEvent::GetIndexers;
|
let event = RadarrEvent::GetIndexers;
|
||||||
|
|
||||||
|
|||||||
@@ -2261,7 +2261,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_handle_get_indexers_event() {
|
async fn test_handle_get_radarr_indexers_event() {
|
||||||
let indexers_response_json = json!([{
|
let indexers_response_json = json!([{
|
||||||
"enableRss": true,
|
"enableRss": true,
|
||||||
"enableAutomaticSearch": true,
|
"enableAutomaticSearch": true,
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ use crate::{
|
|||||||
models::{
|
models::{
|
||||||
servarr_data::sonarr::{modals::EpisodeDetailsModal, sonarr_data::ActiveSonarrBlock},
|
servarr_data::sonarr::{modals::EpisodeDetailsModal, sonarr_data::ActiveSonarrBlock},
|
||||||
sonarr_models::{
|
sonarr_models::{
|
||||||
BlocklistResponse, DownloadRecord, DownloadsResponse, Episode, LogResponse, QualityProfile,
|
BlocklistResponse, DownloadRecord, DownloadsResponse, Episode, Indexer, LogResponse,
|
||||||
Series, SonarrSerdeable, SystemStatus,
|
QualityProfile, Series, SonarrSerdeable, SystemStatus,
|
||||||
},
|
},
|
||||||
HorizontallyScrollableText, Route, Scrollable, ScrollableText,
|
HorizontallyScrollableText, Route, Scrollable, ScrollableText,
|
||||||
},
|
},
|
||||||
@@ -30,6 +30,7 @@ pub enum SonarrEvent {
|
|||||||
DeleteBlocklistItem(Option<i64>),
|
DeleteBlocklistItem(Option<i64>),
|
||||||
GetBlocklist,
|
GetBlocklist,
|
||||||
GetDownloads,
|
GetDownloads,
|
||||||
|
GetIndexers,
|
||||||
GetEpisodeDetails(Option<i64>),
|
GetEpisodeDetails(Option<i64>),
|
||||||
GetEpisodes(Option<i64>),
|
GetEpisodes(Option<i64>),
|
||||||
GetLogs(Option<u64>),
|
GetLogs(Option<u64>),
|
||||||
@@ -47,6 +48,7 @@ impl NetworkResource for SonarrEvent {
|
|||||||
SonarrEvent::GetBlocklist => "/blocklist?page=1&pageSize=10000",
|
SonarrEvent::GetBlocklist => "/blocklist?page=1&pageSize=10000",
|
||||||
SonarrEvent::GetDownloads => "/queue",
|
SonarrEvent::GetDownloads => "/queue",
|
||||||
SonarrEvent::GetEpisodes(_) | SonarrEvent::GetEpisodeDetails(_) => "/episode",
|
SonarrEvent::GetEpisodes(_) | SonarrEvent::GetEpisodeDetails(_) => "/episode",
|
||||||
|
SonarrEvent::GetIndexers => "/indexer",
|
||||||
SonarrEvent::GetLogs(_) => "/log",
|
SonarrEvent::GetLogs(_) => "/log",
|
||||||
SonarrEvent::GetQualityProfiles => "/qualityprofile",
|
SonarrEvent::GetQualityProfiles => "/qualityprofile",
|
||||||
SonarrEvent::GetStatus => "/system/status",
|
SonarrEvent::GetStatus => "/system/status",
|
||||||
@@ -86,6 +88,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.get_episode_details(episode_id)
|
.get_episode_details(episode_id)
|
||||||
.await
|
.await
|
||||||
.map(SonarrSerdeable::from),
|
.map(SonarrSerdeable::from),
|
||||||
|
SonarrEvent::GetIndexers => self.get_sonarr_indexers().await.map(SonarrSerdeable::from),
|
||||||
SonarrEvent::GetQualityProfiles => self
|
SonarrEvent::GetQualityProfiles => self
|
||||||
.get_sonarr_quality_profiles()
|
.get_sonarr_quality_profiles()
|
||||||
.await
|
.await
|
||||||
@@ -390,6 +393,21 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_sonarr_indexers(&mut self) -> Result<Vec<Indexer>> {
|
||||||
|
info!("Fetching Sonarr indexers");
|
||||||
|
let event = SonarrEvent::GetIndexers;
|
||||||
|
|
||||||
|
let request_props = self
|
||||||
|
.request_props_from(event, RequestMethod::Get, None::<()>, None, None)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
self
|
||||||
|
.handle_request::<(), Vec<Indexer>>(request_props, |indexers, mut app| {
|
||||||
|
app.data.sonarr_data.indexers.set_items(indexers);
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
async fn get_sonarr_logs(&mut self, events: Option<u64>) -> Result<LogResponse> {
|
async fn get_sonarr_logs(&mut self, events: Option<u64>) -> Result<LogResponse> {
|
||||||
info!("Fetching Sonarr logs");
|
info!("Fetching Sonarr logs");
|
||||||
let event = SonarrEvent::GetLogs(events);
|
let event = SonarrEvent::GetLogs(events);
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ mod test {
|
|||||||
use crate::app::App;
|
use crate::app::App;
|
||||||
use crate::models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock;
|
use crate::models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock;
|
||||||
use crate::models::sonarr_models::{
|
use crate::models::sonarr_models::{
|
||||||
BlocklistItem, DownloadRecord, DownloadsResponse, Episode, EpisodeFile, Language, LogResponse,
|
BlocklistItem, DownloadRecord, DownloadsResponse, Episode, EpisodeFile, Indexer, IndexerField,
|
||||||
MediaInfo, QualityProfile,
|
Language, LogResponse, MediaInfo, QualityProfile,
|
||||||
};
|
};
|
||||||
use crate::models::sonarr_models::{BlocklistResponse, Quality};
|
use crate::models::sonarr_models::{BlocklistResponse, Quality};
|
||||||
use crate::models::sonarr_models::{QualityWrapper, SystemStatus};
|
use crate::models::sonarr_models::{QualityWrapper, SystemStatus};
|
||||||
@@ -137,6 +137,11 @@ mod test {
|
|||||||
assert_str_eq!(event.resource(), "/series");
|
assert_str_eq!(event.resource(), "/series");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rstest]
|
||||||
|
fn test_resource_indexer(#[values(SonarrEvent::GetIndexers)] event: SonarrEvent) {
|
||||||
|
assert_str_eq!(event.resource(), "/indexer");
|
||||||
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
#[case(SonarrEvent::ClearBlocklist, "/blocklist/bulk")]
|
#[case(SonarrEvent::ClearBlocklist, "/blocklist/bulk")]
|
||||||
#[case(SonarrEvent::DeleteBlocklistItem(None), "/blocklist")]
|
#[case(SonarrEvent::DeleteBlocklistItem(None), "/blocklist")]
|
||||||
@@ -646,6 +651,65 @@ mod test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_get_sonarr_indexers_event() {
|
||||||
|
let indexers_response_json = json!([{
|
||||||
|
"enableRss": true,
|
||||||
|
"enableAutomaticSearch": true,
|
||||||
|
"enableInteractiveSearch": true,
|
||||||
|
"supportsRss": true,
|
||||||
|
"supportsSearch": true,
|
||||||
|
"protocol": "torrent",
|
||||||
|
"priority": 25,
|
||||||
|
"downloadClientId": 0,
|
||||||
|
"name": "Test Indexer",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "baseUrl",
|
||||||
|
"value": "https://test.com",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "apiKey",
|
||||||
|
"value": "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "seedCriteria.seedRatio",
|
||||||
|
"value": "1.2",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"implementationName": "Torznab",
|
||||||
|
"implementation": "Torznab",
|
||||||
|
"configContract": "TorznabSettings",
|
||||||
|
"tags": [1],
|
||||||
|
"id": 1
|
||||||
|
}]);
|
||||||
|
let response: Vec<Indexer> = serde_json::from_value(indexers_response_json.clone()).unwrap();
|
||||||
|
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||||
|
RequestMethod::Get,
|
||||||
|
None,
|
||||||
|
Some(indexers_response_json),
|
||||||
|
None,
|
||||||
|
SonarrEvent::GetIndexers,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||||
|
|
||||||
|
if let SonarrSerdeable::Indexers(indexers) = network
|
||||||
|
.handle_sonarr_event(SonarrEvent::GetIndexers)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
{
|
||||||
|
async_server.assert_async().await;
|
||||||
|
assert_eq!(
|
||||||
|
app_arc.lock().await.data.sonarr_data.indexers.items,
|
||||||
|
vec![indexer()]
|
||||||
|
);
|
||||||
|
assert_eq!(indexers, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_handle_get_episodes_event_uses_provided_series_id() {
|
async fn test_handle_get_episodes_event_uses_provided_series_id() {
|
||||||
let episodes_json = json!([
|
let episodes_json = json!([
|
||||||
@@ -1499,6 +1563,39 @@ mod test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn indexer() -> Indexer {
|
||||||
|
Indexer {
|
||||||
|
enable_rss: true,
|
||||||
|
enable_automatic_search: true,
|
||||||
|
enable_interactive_search: true,
|
||||||
|
supports_rss: true,
|
||||||
|
supports_search: true,
|
||||||
|
protocol: "torrent".to_owned(),
|
||||||
|
priority: 25,
|
||||||
|
download_client_id: 0,
|
||||||
|
name: Some("Test Indexer".to_owned()),
|
||||||
|
implementation_name: Some("Torznab".to_owned()),
|
||||||
|
implementation: Some("Torznab".to_owned()),
|
||||||
|
config_contract: Some("TorznabSettings".to_owned()),
|
||||||
|
tags: vec![Number::from(1)],
|
||||||
|
id: 1,
|
||||||
|
fields: Some(vec![
|
||||||
|
IndexerField {
|
||||||
|
name: Some("baseUrl".to_owned()),
|
||||||
|
value: Some(json!("https://test.com")),
|
||||||
|
},
|
||||||
|
IndexerField {
|
||||||
|
name: Some("apiKey".to_owned()),
|
||||||
|
value: Some(json!("")),
|
||||||
|
},
|
||||||
|
IndexerField {
|
||||||
|
name: Some("seedCriteria.seedRatio".to_owned()),
|
||||||
|
value: Some(json!("1.2")),
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn language() -> Language {
|
fn language() -> Language {
|
||||||
Language {
|
Language {
|
||||||
name: "English".to_owned(),
|
name: "English".to_owned(),
|
||||||
|
|||||||
Reference in New Issue
Block a user