feat(readarr): trigger an automatic book search and expose the command on the CLI
This commit is contained in:
6 files changed
+159
-1
No files matched your search
@@ -1,8 +1,11 @@
|
||||
use anyhow::Result;
|
||||
use log::info;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::models::Route;
|
||||
use crate::models::readarr_models::{Book, BookFile, Edition, ReadarrHistoryItem};
|
||||
use crate::models::readarr_models::{
|
||||
Book, BookFile, Edition, ReadarrCommandBody, ReadarrHistoryItem,
|
||||
};
|
||||
use crate::models::servarr_data::readarr::readarr_data::ActiveReadarrBlock;
|
||||
use crate::network::readarr_network::ReadarrEvent;
|
||||
use crate::network::{Network, RequestMethod};
|
||||
@@ -159,4 +162,25 @@ impl Network<'_, '_> {
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub(in crate::network::readarr_network) async fn trigger_automatic_book_search(
|
||||
&mut self,
|
||||
book_id: i64,
|
||||
) -> Result<Value> {
|
||||
let event = ReadarrEvent::TriggerAutomaticBookSearch(book_id);
|
||||
info!("Searching indexers for book with ID: {book_id}");
|
||||
let body = ReadarrCommandBody {
|
||||
name: "BookSearch".to_owned(),
|
||||
book_ids: Some(vec![book_id]),
|
||||
..ReadarrCommandBody::default()
|
||||
};
|
||||
|
||||
let request_props = self
|
||||
.request_props_from(event, RequestMethod::Post, Some(body), None, None)
|
||||
.await;
|
||||
|
||||
self
|
||||
.handle_request::<ReadarrCommandBody, Value>(request_props, |_, _| ())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -769,4 +769,47 @@ mod tests {
|
||||
stale_history_items
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_trigger_automatic_book_search_event() {
|
||||
let (mock, app, _server) = MockServarrApi::post()
|
||||
.with_request_body(json!({
|
||||
"name": "BookSearch",
|
||||
"bookIds": [1]
|
||||
}))
|
||||
.returns(json!({}))
|
||||
.build_for(ReadarrEvent::TriggerAutomaticBookSearch(1))
|
||||
.await;
|
||||
app.lock().await.server_tabs.set_index(3);
|
||||
let mut network = test_network(&app);
|
||||
|
||||
let result = network
|
||||
.handle_readarr_event(ReadarrEvent::TriggerAutomaticBookSearch(1))
|
||||
.await;
|
||||
|
||||
mock.assert_async().await;
|
||||
assert_ok!(result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_trigger_automatic_book_search_event_failure() {
|
||||
let (mock, app, _server) = MockServarrApi::post()
|
||||
.with_request_body(json!({
|
||||
"name": "BookSearch",
|
||||
"bookIds": [1]
|
||||
}))
|
||||
.returns(json!({"name": "BookSearch", "status": "queued"}))
|
||||
.status(500)
|
||||
.build_for(ReadarrEvent::TriggerAutomaticBookSearch(1))
|
||||
.await;
|
||||
app.lock().await.server_tabs.set_index(3);
|
||||
let mut network = test_network(&app);
|
||||
|
||||
let result = network
|
||||
.handle_readarr_event(ReadarrEvent::TriggerAutomaticBookSearch(1))
|
||||
.await;
|
||||
|
||||
mock.assert_async().await;
|
||||
assert_err!(result);
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,7 @@ pub enum ReadarrEvent {
|
||||
StartTask(ReadarrTaskName),
|
||||
ToggleAuthorMonitoring(i64),
|
||||
TriggerAutomaticAuthorSearch(i64),
|
||||
TriggerAutomaticBookSearch(i64),
|
||||
UpdateAllAuthors,
|
||||
UpdateAndScanAuthor(i64),
|
||||
}
|
||||
@@ -75,6 +76,7 @@ impl NetworkResource for ReadarrEvent {
|
||||
ReadarrEvent::GetQueuedEvents
|
||||
| ReadarrEvent::StartTask(_)
|
||||
| ReadarrEvent::TriggerAutomaticAuthorSearch(_)
|
||||
| ReadarrEvent::TriggerAutomaticBookSearch(_)
|
||||
| ReadarrEvent::UpdateAllAuthors
|
||||
| ReadarrEvent::UpdateAndScanAuthor(_) => "/command",
|
||||
ReadarrEvent::GetHostConfig | ReadarrEvent::GetSecurityConfig => "/config/host",
|
||||
@@ -213,6 +215,10 @@ impl Network<'_, '_> {
|
||||
.trigger_automatic_author_search(author_id)
|
||||
.await
|
||||
.map(ReadarrSerdeable::from),
|
||||
ReadarrEvent::TriggerAutomaticBookSearch(book_id) => self
|
||||
.trigger_automatic_book_search(book_id)
|
||||
.await
|
||||
.map(ReadarrSerdeable::from),
|
||||
ReadarrEvent::UpdateAllAuthors => self.update_all_authors().await.map(ReadarrSerdeable::from),
|
||||
ReadarrEvent::UpdateAndScanAuthor(author_id) => self
|
||||
.update_and_scan_author(author_id)
|
||||
|
||||
@@ -28,6 +28,7 @@ mod tests {
|
||||
#[case(ReadarrEvent::GetQueuedEvents, "/command")]
|
||||
#[case(ReadarrEvent::StartTask(Default::default()), "/command")]
|
||||
#[case(ReadarrEvent::TriggerAutomaticAuthorSearch(1), "/command")]
|
||||
#[case(ReadarrEvent::TriggerAutomaticBookSearch(1), "/command")]
|
||||
#[case(ReadarrEvent::UpdateAllAuthors, "/command")]
|
||||
#[case(ReadarrEvent::UpdateAndScanAuthor(1), "/command")]
|
||||
#[case(ReadarrEvent::GetHostConfig, "/config/host")]
|
||||
|
||||
Reference in new issue
Block a user