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 crate::models::{
|
||||
sonarr_models::{BlocklistItem, DownloadRecord, Episode, Series},
|
||||
sonarr_models::{BlocklistItem, DownloadRecord, Episode, Indexer, Series},
|
||||
stateful_list::StatefulList,
|
||||
stateful_table::StatefulTable,
|
||||
stateful_tree::StatefulTree,
|
||||
@@ -27,6 +27,7 @@ pub struct SonarrData {
|
||||
pub downloads: StatefulTable<DownloadRecord>,
|
||||
pub episode_details_modal: Option<EpisodeDetailsModal>,
|
||||
pub quality_profile_map: BiMap<i64, String>,
|
||||
pub indexers: StatefulTable<Indexer>,
|
||||
}
|
||||
|
||||
impl Default for SonarrData {
|
||||
@@ -42,6 +43,7 @@ impl Default for SonarrData {
|
||||
downloads: StatefulTable::default(),
|
||||
episode_details_modal: None,
|
||||
quality_profile_map: BiMap::new(),
|
||||
indexers: StatefulTable::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ mod tests {
|
||||
assert!(sonarr_data.downloads.is_empty());
|
||||
assert!(sonarr_data.episode_details_modal.is_none());
|
||||
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>,
|
||||
}
|
||||
|
||||
#[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)]
|
||||
pub struct Language {
|
||||
pub name: String,
|
||||
@@ -330,6 +359,7 @@ pub enum SonarrSerdeable {
|
||||
DownloadsResponse(DownloadsResponse),
|
||||
Episode(Episode),
|
||||
Episodes(Vec<Episode>),
|
||||
Indexers(Vec<Indexer>),
|
||||
QualityProfiles(Vec<QualityProfile>),
|
||||
SeriesVec(Vec<Series>),
|
||||
SystemStatus(SystemStatus),
|
||||
@@ -355,6 +385,7 @@ serde_enum_from!(
|
||||
DownloadsResponse(DownloadsResponse),
|
||||
Episode(Episode),
|
||||
Episodes(Vec<Episode>),
|
||||
Indexers(Vec<Indexer>),
|
||||
QualityProfiles(Vec<QualityProfile>),
|
||||
SeriesVec(Vec<Series>),
|
||||
SystemStatus(SystemStatus),
|
||||
|
||||
@@ -193,7 +193,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
RadarrEvent::GetCollections => self.get_collections().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::GetIndexers => self.get_indexers().await.map(RadarrSerdeable::from),
|
||||
RadarrEvent::GetIndexers => self.get_radarr_indexers().await.map(RadarrSerdeable::from),
|
||||
RadarrEvent::GetLogs(events) => self
|
||||
.get_radarr_logs(events)
|
||||
.await
|
||||
@@ -1395,7 +1395,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn get_indexers(&mut self) -> Result<Vec<Indexer>> {
|
||||
async fn get_radarr_indexers(&mut self) -> Result<Vec<Indexer>> {
|
||||
info!("Fetching Radarr indexers");
|
||||
let event = RadarrEvent::GetIndexers;
|
||||
|
||||
|
||||
@@ -2261,7 +2261,7 @@ mod test {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_get_indexers_event() {
|
||||
async fn test_handle_get_radarr_indexers_event() {
|
||||
let indexers_response_json = json!([{
|
||||
"enableRss": true,
|
||||
"enableAutomaticSearch": true,
|
||||
|
||||
@@ -10,8 +10,8 @@ use crate::{
|
||||
models::{
|
||||
servarr_data::sonarr::{modals::EpisodeDetailsModal, sonarr_data::ActiveSonarrBlock},
|
||||
sonarr_models::{
|
||||
BlocklistResponse, DownloadRecord, DownloadsResponse, Episode, LogResponse, QualityProfile,
|
||||
Series, SonarrSerdeable, SystemStatus,
|
||||
BlocklistResponse, DownloadRecord, DownloadsResponse, Episode, Indexer, LogResponse,
|
||||
QualityProfile, Series, SonarrSerdeable, SystemStatus,
|
||||
},
|
||||
HorizontallyScrollableText, Route, Scrollable, ScrollableText,
|
||||
},
|
||||
@@ -30,6 +30,7 @@ pub enum SonarrEvent {
|
||||
DeleteBlocklistItem(Option<i64>),
|
||||
GetBlocklist,
|
||||
GetDownloads,
|
||||
GetIndexers,
|
||||
GetEpisodeDetails(Option<i64>),
|
||||
GetEpisodes(Option<i64>),
|
||||
GetLogs(Option<u64>),
|
||||
@@ -47,6 +48,7 @@ impl NetworkResource for SonarrEvent {
|
||||
SonarrEvent::GetBlocklist => "/blocklist?page=1&pageSize=10000",
|
||||
SonarrEvent::GetDownloads => "/queue",
|
||||
SonarrEvent::GetEpisodes(_) | SonarrEvent::GetEpisodeDetails(_) => "/episode",
|
||||
SonarrEvent::GetIndexers => "/indexer",
|
||||
SonarrEvent::GetLogs(_) => "/log",
|
||||
SonarrEvent::GetQualityProfiles => "/qualityprofile",
|
||||
SonarrEvent::GetStatus => "/system/status",
|
||||
@@ -86,6 +88,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.get_episode_details(episode_id)
|
||||
.await
|
||||
.map(SonarrSerdeable::from),
|
||||
SonarrEvent::GetIndexers => self.get_sonarr_indexers().await.map(SonarrSerdeable::from),
|
||||
SonarrEvent::GetQualityProfiles => self
|
||||
.get_sonarr_quality_profiles()
|
||||
.await
|
||||
@@ -390,6 +393,21 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.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> {
|
||||
info!("Fetching Sonarr logs");
|
||||
let event = SonarrEvent::GetLogs(events);
|
||||
|
||||
@@ -23,8 +23,8 @@ mod test {
|
||||
use crate::app::App;
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock;
|
||||
use crate::models::sonarr_models::{
|
||||
BlocklistItem, DownloadRecord, DownloadsResponse, Episode, EpisodeFile, Language, LogResponse,
|
||||
MediaInfo, QualityProfile,
|
||||
BlocklistItem, DownloadRecord, DownloadsResponse, Episode, EpisodeFile, Indexer, IndexerField,
|
||||
Language, LogResponse, MediaInfo, QualityProfile,
|
||||
};
|
||||
use crate::models::sonarr_models::{BlocklistResponse, Quality};
|
||||
use crate::models::sonarr_models::{QualityWrapper, SystemStatus};
|
||||
@@ -137,6 +137,11 @@ mod test {
|
||||
assert_str_eq!(event.resource(), "/series");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_resource_indexer(#[values(SonarrEvent::GetIndexers)] event: SonarrEvent) {
|
||||
assert_str_eq!(event.resource(), "/indexer");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(SonarrEvent::ClearBlocklist, "/blocklist/bulk")]
|
||||
#[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]
|
||||
async fn test_handle_get_episodes_event_uses_provided_series_id() {
|
||||
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 {
|
||||
Language {
|
||||
name: "English".to_owned(),
|
||||
|
||||
Reference in New Issue
Block a user