1
0
mirror of https://github.com/Sonarr/Sonarr synced 2025-10-05 23:52:45 +02:00

Add v5 Blocklist endpoints

This commit is contained in:
Mark McDowall
2025-09-30 16:41:55 -07:00
parent a5ea19ddfb
commit bc4ad574fc
5 changed files with 128 additions and 8 deletions

View File

@@ -0,0 +1,6 @@
namespace Sonarr.Api.V5.Blocklist;
public class BlocklistBulkResource
{
public required List<int> Ids { get; set; }
}

View File

@@ -0,0 +1,70 @@
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Core.Blocklisting;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Indexers;
using Sonarr.Http;
using Sonarr.Http.Extensions;
using Sonarr.Http.REST.Attributes;
namespace Sonarr.Api.V5.Blocklist;
[V5ApiController]
public class BlocklistController : Controller
{
private readonly IBlocklistService _blocklistService;
private readonly ICustomFormatCalculationService _formatCalculator;
public BlocklistController(IBlocklistService blocklistService,
ICustomFormatCalculationService formatCalculator)
{
_blocklistService = blocklistService;
_formatCalculator = formatCalculator;
}
[HttpGet]
[Produces("application/json")]
public PagingResource<BlocklistResource> GetBlocklist([FromQuery] PagingRequestResource paging, [FromQuery] int[]? seriesIds = null, [FromQuery] DownloadProtocol[]? protocols = null)
{
var pagingResource = new PagingResource<BlocklistResource>(paging);
var pagingSpec = pagingResource.MapToPagingSpec<BlocklistResource, NzbDrone.Core.Blocklisting.Blocklist>(
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"date",
"indexer",
"series.sortTitle",
"sourceTitle"
},
"date",
SortDirection.Descending);
if (seriesIds?.Any() == true)
{
pagingSpec.FilterExpressions.Add(b => seriesIds.Contains(b.SeriesId));
}
if (protocols?.Any() == true)
{
pagingSpec.FilterExpressions.Add(b => protocols.Contains(b.Protocol));
}
return pagingSpec.ApplyToPage(b => _blocklistService.Paged(pagingSpec), b => BlocklistResourceMapper.MapToResource(b, _formatCalculator));
}
[RestDeleteById]
public ActionResult DeleteBlocklist(int id)
{
_blocklistService.Delete(id);
return NoContent();
}
[HttpDelete("bulk")]
[Produces("application/json")]
public ActionResult Remove([FromBody] BlocklistBulkResource resource)
{
_blocklistService.Delete(resource.Ids);
return NoContent();
}
}

View File

@@ -0,0 +1,49 @@
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Languages;
using NzbDrone.Core.Qualities;
using Sonarr.Api.V5.CustomFormats;
using Sonarr.Api.V5.Series;
using Sonarr.Http.REST;
namespace Sonarr.Api.V5.Blocklist;
public class BlocklistResource : RestResource
{
public int SeriesId { get; set; }
public required List<int> EpisodeIds { get; set; }
public required string SourceTitle { get; set; }
public required List<Language> Languages { get; set; }
public required QualityModel Quality { get; set; }
public required List<CustomFormatResource> CustomFormats { get; set; }
public DateTime Date { get; set; }
public DownloadProtocol Protocol { get; set; }
public string? Indexer { get; set; }
public string? Message { get; set; }
public string? Source { get; set; }
public required SeriesResource Series { get; set; }
}
public static class BlocklistResourceMapper
{
public static BlocklistResource MapToResource(this NzbDrone.Core.Blocklisting.Blocklist model, ICustomFormatCalculationService formatCalculator)
{
return new BlocklistResource
{
Id = model.Id,
SeriesId = model.SeriesId,
EpisodeIds = model.EpisodeIds,
SourceTitle = model.SourceTitle,
Languages = model.Languages,
Quality = model.Quality,
CustomFormats = formatCalculator.ParseCustomFormat(model, model.Series).ToResource(false),
Date = model.Date,
Protocol = model.Protocol,
Indexer = model.Indexer,
Message = model.Message,
Source = model.Source,
Series = model.Series.ToResource()
};
}
}

View File

@@ -76,7 +76,7 @@ namespace Sonarr.Api.V5.Queue
{
Remove(pendingRelease, message, blocklist);
return Deleted();
return NoContent();
}
var trackedDownload = GetTrackedDownload(id);
@@ -89,7 +89,7 @@ namespace Sonarr.Api.V5.Queue
Remove(trackedDownload, message, removeFromClient, blocklist, skipRedownload, changeCategory);
_trackedDownloadService.StopTracking(trackedDownload.DownloadItem.DownloadId);
return Deleted();
return NoContent();
}
[HttpDelete("bulk")]
@@ -130,7 +130,7 @@ namespace Sonarr.Api.V5.Queue
_trackedDownloadService.StopTracking(trackedDownloadIds);
return new { };
return NoContent();
}
[HttpGet]

View File

@@ -167,10 +167,5 @@ namespace Sonarr.Http.REST
var result = GetResourceById(id);
return CreatedAtAction(nameof(GetResourceByIdWithErrorHandler), new { id = id }, result);
}
protected ActionResult Deleted()
{
return NoContent();
}
}
}