feat(network): Support for updating Sonarr downloads
This commit is contained in:
@@ -273,7 +273,10 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.await
|
.await
|
||||||
.map(RadarrSerdeable::from),
|
.map(RadarrSerdeable::from),
|
||||||
RadarrEvent::UpdateCollections => self.update_collections().await.map(RadarrSerdeable::from),
|
RadarrEvent::UpdateCollections => self.update_collections().await.map(RadarrSerdeable::from),
|
||||||
RadarrEvent::UpdateDownloads => self.update_downloads().await.map(RadarrSerdeable::from),
|
RadarrEvent::UpdateDownloads => self
|
||||||
|
.update_radarr_downloads()
|
||||||
|
.await
|
||||||
|
.map(RadarrSerdeable::from),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2214,8 +2217,8 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_downloads(&mut self) -> Result<Value> {
|
async fn update_radarr_downloads(&mut self) -> Result<Value> {
|
||||||
info!("Updating downloads");
|
info!("Updating Radarr downloads");
|
||||||
let event = RadarrEvent::UpdateDownloads;
|
let event = RadarrEvent::UpdateDownloads;
|
||||||
let body = CommandBody {
|
let body = CommandBody {
|
||||||
name: "RefreshMonitoredDownloads".to_owned(),
|
name: "RefreshMonitoredDownloads".to_owned(),
|
||||||
|
|||||||
@@ -1301,7 +1301,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_handle_update_downloads_event() {
|
async fn test_handle_update_radarr_downloads_event() {
|
||||||
let (async_server, app_arc, _server) = mock_servarr_api(
|
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||||
RequestMethod::Post,
|
RequestMethod::Post,
|
||||||
Some(json!({
|
Some(json!({
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ pub enum SonarrEvent {
|
|||||||
TriggerAutomaticSeriesSearch(Option<i64>),
|
TriggerAutomaticSeriesSearch(Option<i64>),
|
||||||
UpdateAllSeries,
|
UpdateAllSeries,
|
||||||
UpdateAndScanSeries(Option<i64>),
|
UpdateAndScanSeries(Option<i64>),
|
||||||
|
UpdateDownloads,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NetworkResource for SonarrEvent {
|
impl NetworkResource for SonarrEvent {
|
||||||
@@ -102,7 +103,8 @@ impl NetworkResource for SonarrEvent {
|
|||||||
| SonarrEvent::TriggerAutomaticSeasonSearch(_)
|
| SonarrEvent::TriggerAutomaticSeasonSearch(_)
|
||||||
| SonarrEvent::TriggerAutomaticEpisodeSearch(_)
|
| SonarrEvent::TriggerAutomaticEpisodeSearch(_)
|
||||||
| SonarrEvent::UpdateAllSeries
|
| SonarrEvent::UpdateAllSeries
|
||||||
| SonarrEvent::UpdateAndScanSeries(_) => "/command",
|
| SonarrEvent::UpdateAndScanSeries(_)
|
||||||
|
| SonarrEvent::UpdateDownloads => "/command",
|
||||||
SonarrEvent::GetRootFolders
|
SonarrEvent::GetRootFolders
|
||||||
| SonarrEvent::DeleteRootFolder(_)
|
| SonarrEvent::DeleteRootFolder(_)
|
||||||
| SonarrEvent::AddRootFolder(_) => "/rootfolder",
|
| SonarrEvent::AddRootFolder(_) => "/rootfolder",
|
||||||
@@ -267,6 +269,10 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.update_and_scan_series(series_id)
|
.update_and_scan_series(series_id)
|
||||||
.await
|
.await
|
||||||
.map(SonarrSerdeable::from),
|
.map(SonarrSerdeable::from),
|
||||||
|
SonarrEvent::UpdateDownloads => self
|
||||||
|
.update_sonarr_downloads()
|
||||||
|
.await
|
||||||
|
.map(SonarrSerdeable::from),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1568,6 +1574,22 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn update_sonarr_downloads(&mut self) -> Result<Value> {
|
||||||
|
info!("Updating Sonarr downloads");
|
||||||
|
let event = SonarrEvent::UpdateDownloads;
|
||||||
|
let body = CommandBody {
|
||||||
|
name: "RefreshMonitoredDownloads".to_owned(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let request_props = self
|
||||||
|
.request_props_from(event, RequestMethod::Post, Some(body), None, None)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
self
|
||||||
|
.handle_request::<CommandBody, Value>(request_props, |_, _| ())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
async fn extract_series_id(&mut self, series_id: Option<i64>) -> (i64, String) {
|
async fn extract_series_id(&mut self, series_id: Option<i64>) -> (i64, String) {
|
||||||
let series_id = if let Some(id) = series_id {
|
let series_id = if let Some(id) = series_id {
|
||||||
id
|
id
|
||||||
|
|||||||
@@ -170,7 +170,8 @@ mod test {
|
|||||||
SonarrEvent::TriggerAutomaticSeasonSearch(None),
|
SonarrEvent::TriggerAutomaticSeasonSearch(None),
|
||||||
SonarrEvent::TriggerAutomaticSeriesSearch(None),
|
SonarrEvent::TriggerAutomaticSeriesSearch(None),
|
||||||
SonarrEvent::UpdateAllSeries,
|
SonarrEvent::UpdateAllSeries,
|
||||||
SonarrEvent::UpdateAndScanSeries(None)
|
SonarrEvent::UpdateAndScanSeries(None),
|
||||||
|
SonarrEvent::UpdateDownloads
|
||||||
)]
|
)]
|
||||||
event: SonarrEvent,
|
event: SonarrEvent,
|
||||||
) {
|
) {
|
||||||
@@ -4578,6 +4579,30 @@ mod test {
|
|||||||
async_server.assert_async().await;
|
async_server.assert_async().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_update_sonarr_downloads_event() {
|
||||||
|
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||||
|
RequestMethod::Post,
|
||||||
|
Some(json!({
|
||||||
|
"name": "RefreshMonitoredDownloads"
|
||||||
|
})),
|
||||||
|
Some(json!({})),
|
||||||
|
None,
|
||||||
|
SonarrEvent::UpdateDownloads,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||||
|
|
||||||
|
assert!(network
|
||||||
|
.handle_sonarr_event(SonarrEvent::UpdateDownloads)
|
||||||
|
.await
|
||||||
|
.is_ok());
|
||||||
|
|
||||||
|
async_server.assert_async().await;
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_extract_series_id() {
|
async fn test_extract_series_id() {
|
||||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||||
|
|||||||
Reference in New Issue
Block a user