feat(network): Support for starting a Sonarr task
This commit is contained in:
@@ -10,12 +10,13 @@ use crate::{
|
||||
sonarr_data::ActiveSonarrBlock,
|
||||
},
|
||||
servarr_models::{
|
||||
AddRootFolderBody, DiskSpace, HostConfig, Indexer, LogResponse, QualityProfile, QueueEvent,
|
||||
Release, RootFolder, SecurityConfig, Tag, Update,
|
||||
AddRootFolderBody, CommandBody, DiskSpace, HostConfig, Indexer, LogResponse, QualityProfile,
|
||||
QueueEvent, Release, RootFolder, SecurityConfig, Tag, Update,
|
||||
},
|
||||
sonarr_models::{
|
||||
BlocklistResponse, DownloadRecord, DownloadsResponse, Episode, IndexerSettings, Series,
|
||||
SonarrHistoryItem, SonarrHistoryWrapper, SonarrSerdeable, SonarrTask, SystemStatus,
|
||||
SonarrHistoryItem, SonarrHistoryWrapper, SonarrSerdeable, SonarrTask, SonarrTaskName,
|
||||
SystemStatus,
|
||||
},
|
||||
stateful_table::StatefulTable,
|
||||
HorizontallyScrollableText, Route, Scrollable, ScrollableText,
|
||||
@@ -65,6 +66,7 @@ pub enum SonarrEvent {
|
||||
HealthCheck,
|
||||
ListSeries,
|
||||
MarkHistoryItemAsFailed(i64),
|
||||
StartTask(Option<SonarrTaskName>),
|
||||
}
|
||||
|
||||
impl NetworkResource for SonarrEvent {
|
||||
@@ -95,6 +97,7 @@ impl NetworkResource for SonarrEvent {
|
||||
SonarrEvent::HealthCheck => "/health",
|
||||
SonarrEvent::ListSeries | SonarrEvent::GetSeriesDetails(_) => "/series",
|
||||
SonarrEvent::MarkHistoryItemAsFailed(_) => "/history/failed",
|
||||
SonarrEvent::StartTask(_) => "/command",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,6 +220,10 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.mark_sonarr_history_item_as_failed(history_item_id)
|
||||
.await
|
||||
.map(SonarrSerdeable::from),
|
||||
SonarrEvent::StartTask(task_name) => self
|
||||
.start_sonarr_task(task_name)
|
||||
.await
|
||||
.map(SonarrSerdeable::from),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1274,6 +1281,36 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn start_sonarr_task(&mut self, task: Option<SonarrTaskName>) -> Result<Value> {
|
||||
let event = SonarrEvent::StartTask(None);
|
||||
let task_name = if let Some(t_name) = task {
|
||||
t_name
|
||||
} else {
|
||||
self
|
||||
.app
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.tasks
|
||||
.current_selection()
|
||||
.task_name
|
||||
}
|
||||
.to_string();
|
||||
|
||||
info!("Starting Sonarr task: {task_name}");
|
||||
|
||||
let body = CommandBody { name: task_name };
|
||||
|
||||
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) {
|
||||
let series_id = if let Some(id) = series_id {
|
||||
id
|
||||
|
||||
Reference in New Issue
Block a user