feat(readarr): refresh Readarr downloads and expose the command on the CLI
This commit is contained in:
6 files changed
+112
-1
No files matched your search
@@ -29,6 +29,8 @@ pub enum ReadarrRefreshCommand {
|
|||||||
)]
|
)]
|
||||||
author_id: i64,
|
author_id: i64,
|
||||||
},
|
},
|
||||||
|
#[command(about = "Refresh all downloads in Readarr")]
|
||||||
|
Downloads,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ReadarrRefreshCommand> for Command {
|
impl From<ReadarrRefreshCommand> for Command {
|
||||||
@@ -74,6 +76,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrRefreshCommand>
|
|||||||
.await?;
|
.await?;
|
||||||
serde_json::to_string_pretty(&resp)?
|
serde_json::to_string_pretty(&resp)?
|
||||||
}
|
}
|
||||||
|
ReadarrRefreshCommand::Downloads => {
|
||||||
|
let resp = self
|
||||||
|
.network
|
||||||
|
.handle_network_event(ReadarrEvent::UpdateDownloads.into())
|
||||||
|
.await?;
|
||||||
|
serde_json::to_string_pretty(&resp)?
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
|||||||
@@ -32,6 +32,14 @@ mod tests {
|
|||||||
assert_ok!(&result);
|
assert_ok!(&result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_refresh_downloads_has_no_arg_requirements() {
|
||||||
|
let result =
|
||||||
|
Cli::command().try_get_matches_from(["managarr", "readarr", "refresh", "downloads"]);
|
||||||
|
|
||||||
|
assert_ok!(&result);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_refresh_author_requires_author_id() {
|
fn test_refresh_author_requires_author_id() {
|
||||||
let result =
|
let result =
|
||||||
@@ -128,5 +136,27 @@ mod tests {
|
|||||||
|
|
||||||
assert_ok!(&result);
|
assert_ok!(&result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_refresh_downloads_command() {
|
||||||
|
let mut mock_network = MockNetworkTrait::new();
|
||||||
|
mock_network
|
||||||
|
.expect_handle_network_event()
|
||||||
|
.with(eq::<NetworkEvent>(ReadarrEvent::UpdateDownloads.into()))
|
||||||
|
.times(1)
|
||||||
|
.returning(|_| {
|
||||||
|
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
|
||||||
|
json!({"testResponse": "response"}),
|
||||||
|
)))
|
||||||
|
});
|
||||||
|
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
||||||
|
let refresh_command = ReadarrRefreshCommand::Downloads;
|
||||||
|
|
||||||
|
let result = ReadarrRefreshCommandHandler::with(&app_arc, refresh_command, &mut mock_network)
|
||||||
|
.handle()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
assert_ok!(&result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
use crate::models::readarr_models::DownloadsResponse;
|
use crate::models::readarr_models::DownloadsResponse;
|
||||||
|
use crate::models::servarr_models::CommandBody;
|
||||||
use crate::network::readarr_network::ReadarrEvent;
|
use crate::network::readarr_network::ReadarrEvent;
|
||||||
use crate::network::{Network, RequestMethod};
|
use crate::network::{Network, RequestMethod};
|
||||||
|
|
||||||
@@ -59,4 +61,22 @@ impl Network<'_, '_> {
|
|||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(in crate::network::readarr_network) async fn update_readarr_downloads(
|
||||||
|
&mut self,
|
||||||
|
) -> Result<Value> {
|
||||||
|
info!("Updating Readarr downloads");
|
||||||
|
let event = ReadarrEvent::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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -116,4 +116,49 @@ mod tests {
|
|||||||
stale_downloads
|
stale_downloads
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_update_readarr_downloads_event() {
|
||||||
|
let (mock, app, _server) = MockServarrApi::post()
|
||||||
|
.with_request_body(json!({ "name": "RefreshMonitoredDownloads" }))
|
||||||
|
.returns(json!({
|
||||||
|
"name": "RefreshMonitoredDownloads",
|
||||||
|
"commandName": "Refresh Monitored Downloads",
|
||||||
|
"status": "queued"
|
||||||
|
}))
|
||||||
|
.build_for(ReadarrEvent::UpdateDownloads)
|
||||||
|
.await;
|
||||||
|
app.lock().await.server_tabs.set_index(3);
|
||||||
|
let mut network = test_network(&app);
|
||||||
|
|
||||||
|
let result = network
|
||||||
|
.handle_readarr_event(ReadarrEvent::UpdateDownloads)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
mock.assert_async().await;
|
||||||
|
assert_ok!(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_update_readarr_downloads_event_failure() {
|
||||||
|
let (mock, app, _server) = MockServarrApi::post()
|
||||||
|
.with_request_body(json!({ "name": "RefreshMonitoredDownloads" }))
|
||||||
|
.returns(json!({
|
||||||
|
"name": "RefreshMonitoredDownloads",
|
||||||
|
"commandName": "Refresh Monitored Downloads",
|
||||||
|
"status": "queued"
|
||||||
|
}))
|
||||||
|
.status(500)
|
||||||
|
.build_for(ReadarrEvent::UpdateDownloads)
|
||||||
|
.await;
|
||||||
|
app.lock().await.server_tabs.set_index(3);
|
||||||
|
let mut network = test_network(&app);
|
||||||
|
|
||||||
|
let result = network
|
||||||
|
.handle_readarr_event(ReadarrEvent::UpdateDownloads)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
mock.assert_async().await;
|
||||||
|
assert_err!(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -65,6 +65,7 @@ pub enum ReadarrEvent {
|
|||||||
TriggerAutomaticBookSearch(i64),
|
TriggerAutomaticBookSearch(i64),
|
||||||
UpdateAllAuthors,
|
UpdateAllAuthors,
|
||||||
UpdateAndScanAuthor(i64),
|
UpdateAndScanAuthor(i64),
|
||||||
|
UpdateDownloads,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NetworkResource for ReadarrEvent {
|
impl NetworkResource for ReadarrEvent {
|
||||||
@@ -87,7 +88,8 @@ impl NetworkResource for ReadarrEvent {
|
|||||||
| ReadarrEvent::TriggerAutomaticAuthorSearch(_)
|
| ReadarrEvent::TriggerAutomaticAuthorSearch(_)
|
||||||
| ReadarrEvent::TriggerAutomaticBookSearch(_)
|
| ReadarrEvent::TriggerAutomaticBookSearch(_)
|
||||||
| ReadarrEvent::UpdateAllAuthors
|
| ReadarrEvent::UpdateAllAuthors
|
||||||
| ReadarrEvent::UpdateAndScanAuthor(_) => "/command",
|
| ReadarrEvent::UpdateAndScanAuthor(_)
|
||||||
|
| ReadarrEvent::UpdateDownloads => "/command",
|
||||||
ReadarrEvent::GetHostConfig | ReadarrEvent::GetSecurityConfig => "/config/host",
|
ReadarrEvent::GetHostConfig | ReadarrEvent::GetSecurityConfig => "/config/host",
|
||||||
ReadarrEvent::GetDiskSpace => "/diskspace",
|
ReadarrEvent::GetDiskSpace => "/diskspace",
|
||||||
ReadarrEvent::GetBookEditions(_) => "/edition",
|
ReadarrEvent::GetBookEditions(_) => "/edition",
|
||||||
@@ -254,6 +256,10 @@ impl Network<'_, '_> {
|
|||||||
.update_and_scan_author(author_id)
|
.update_and_scan_author(author_id)
|
||||||
.await
|
.await
|
||||||
.map(ReadarrSerdeable::from),
|
.map(ReadarrSerdeable::from),
|
||||||
|
ReadarrEvent::UpdateDownloads => self
|
||||||
|
.update_readarr_downloads()
|
||||||
|
.await
|
||||||
|
.map(ReadarrSerdeable::from),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ mod tests {
|
|||||||
#[case(ReadarrEvent::TriggerAutomaticBookSearch(1), "/command")]
|
#[case(ReadarrEvent::TriggerAutomaticBookSearch(1), "/command")]
|
||||||
#[case(ReadarrEvent::UpdateAllAuthors, "/command")]
|
#[case(ReadarrEvent::UpdateAllAuthors, "/command")]
|
||||||
#[case(ReadarrEvent::UpdateAndScanAuthor(1), "/command")]
|
#[case(ReadarrEvent::UpdateAndScanAuthor(1), "/command")]
|
||||||
|
#[case(ReadarrEvent::UpdateDownloads, "/command")]
|
||||||
#[case(ReadarrEvent::GetHostConfig, "/config/host")]
|
#[case(ReadarrEvent::GetHostConfig, "/config/host")]
|
||||||
#[case(ReadarrEvent::GetSecurityConfig, "/config/host")]
|
#[case(ReadarrEvent::GetSecurityConfig, "/config/host")]
|
||||||
#[case(ReadarrEvent::GetDiskSpace, "/diskspace")]
|
#[case(ReadarrEvent::GetDiskSpace, "/diskspace")]
|
||||||
|
|||||||
Reference in new issue
Block a user