feat(network): Support for deleting a series from Sonarr
This commit is contained in:
@@ -18,9 +18,10 @@ use crate::{
|
||||
QueueEvent, RootFolder, SecurityConfig, Tag, Update,
|
||||
},
|
||||
sonarr_models::{
|
||||
BlocklistResponse, DownloadRecord, DownloadsResponse, Episode, IndexerSettings, Series,
|
||||
SonarrCommandBody, SonarrHistoryItem, SonarrHistoryWrapper, SonarrRelease,
|
||||
SonarrReleaseDownloadBody, SonarrSerdeable, SonarrTask, SonarrTaskName, SystemStatus,
|
||||
BlocklistResponse, DeleteSeriesParams, DownloadRecord, DownloadsResponse, Episode,
|
||||
IndexerSettings, Series, SonarrCommandBody, SonarrHistoryItem, SonarrHistoryWrapper,
|
||||
SonarrRelease, SonarrReleaseDownloadBody, SonarrSerdeable, SonarrTask, SonarrTaskName,
|
||||
SystemStatus,
|
||||
},
|
||||
stateful_table::StatefulTable,
|
||||
HorizontallyScrollableText, Route, Scrollable, ScrollableText,
|
||||
@@ -43,6 +44,7 @@ pub enum SonarrEvent {
|
||||
DeleteDownload(Option<i64>),
|
||||
DeleteIndexer(Option<i64>),
|
||||
DeleteRootFolder(Option<i64>),
|
||||
DeleteSeries(Option<DeleteSeriesParams>),
|
||||
DeleteTag(i64),
|
||||
DownloadRelease(SonarrReleaseDownloadBody),
|
||||
GetAllIndexerSettings,
|
||||
@@ -116,7 +118,9 @@ impl NetworkResource for SonarrEvent {
|
||||
SonarrEvent::GetTasks => "/system/task",
|
||||
SonarrEvent::GetUpdates => "/update",
|
||||
SonarrEvent::HealthCheck => "/health",
|
||||
SonarrEvent::ListSeries | SonarrEvent::GetSeriesDetails(_) => "/series",
|
||||
SonarrEvent::ListSeries | SonarrEvent::GetSeriesDetails(_) | SonarrEvent::DeleteSeries(_) => {
|
||||
"/series"
|
||||
}
|
||||
SonarrEvent::MarkHistoryItemAsFailed(_) => "/history/failed",
|
||||
SonarrEvent::TestIndexer(_) => "/indexer/test",
|
||||
SonarrEvent::TestAllIndexers => "/indexer/testall",
|
||||
@@ -165,6 +169,9 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.delete_sonarr_root_folder(root_folder_id)
|
||||
.await
|
||||
.map(SonarrSerdeable::from),
|
||||
SonarrEvent::DeleteSeries(params) => {
|
||||
self.delete_series(params).await.map(SonarrSerdeable::from)
|
||||
}
|
||||
SonarrEvent::DeleteTag(tag_id) => self
|
||||
.delete_sonarr_tag(tag_id)
|
||||
.await
|
||||
@@ -498,6 +505,55 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn delete_series(
|
||||
&mut self,
|
||||
delete_series_params: Option<DeleteSeriesParams>,
|
||||
) -> Result<()> {
|
||||
let event = SonarrEvent::DeleteSeries(None);
|
||||
let (series_id, delete_files, add_import_exclusion) = if let Some(params) = delete_series_params
|
||||
{
|
||||
(
|
||||
params.id,
|
||||
params.delete_series_files,
|
||||
params.add_list_exclusion,
|
||||
)
|
||||
} else {
|
||||
let (series_id, _) = self.extract_series_id(None).await;
|
||||
let delete_files = self.app.lock().await.data.sonarr_data.delete_series_files;
|
||||
let add_import_exclusion = self.app.lock().await.data.sonarr_data.add_list_exclusion;
|
||||
|
||||
(series_id, delete_files, add_import_exclusion)
|
||||
};
|
||||
|
||||
info!("Deleting Sonarr series with ID: {series_id} with deleteFiles={delete_files} and addImportExclusion={add_import_exclusion}");
|
||||
|
||||
let request_props = self
|
||||
.request_props_from(
|
||||
event,
|
||||
RequestMethod::Delete,
|
||||
None::<()>,
|
||||
Some(format!("/{series_id}")),
|
||||
Some(format!(
|
||||
"deleteFiles={delete_files}&addImportExclusion={add_import_exclusion}"
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
|
||||
let resp = self
|
||||
.handle_request::<(), ()>(request_props, |_, _| ())
|
||||
.await;
|
||||
|
||||
self
|
||||
.app
|
||||
.lock()
|
||||
.await
|
||||
.data
|
||||
.sonarr_data
|
||||
.reset_delete_series_preferences();
|
||||
|
||||
resp
|
||||
}
|
||||
|
||||
async fn delete_sonarr_tag(&mut self, id: i64) -> Result<()> {
|
||||
info!("Deleting Sonarr tag with id: {id}");
|
||||
let event = SonarrEvent::DeleteTag(id);
|
||||
|
||||
Reference in New Issue
Block a user