mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-19 21:46:43 -04:00
Add v5 Indexer endpoints
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
using NzbDrone.Core.Indexers;
|
||||||
|
using Sonarr.Api.V5.Provider;
|
||||||
|
|
||||||
|
namespace Sonarr.Api.V5.Indexers;
|
||||||
|
|
||||||
|
public class IndexerBulkResource : ProviderBulkResource<IndexerBulkResource>
|
||||||
|
{
|
||||||
|
public bool? EnableRss { get; set; }
|
||||||
|
public bool? EnableAutomaticSearch { get; set; }
|
||||||
|
public bool? EnableInteractiveSearch { get; set; }
|
||||||
|
public int? Priority { get; set; }
|
||||||
|
public int? SeasonSearchMaximumSingleEpisodeAge { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class IndexerBulkResourceMapper : ProviderBulkResourceMapper<IndexerBulkResource, IndexerDefinition>
|
||||||
|
{
|
||||||
|
public override List<IndexerDefinition> UpdateModel(IndexerBulkResource resource, List<IndexerDefinition> existingDefinitions)
|
||||||
|
{
|
||||||
|
existingDefinitions.ForEach(existing =>
|
||||||
|
{
|
||||||
|
existing.EnableRss = resource.EnableRss ?? existing.EnableRss;
|
||||||
|
existing.EnableAutomaticSearch = resource.EnableAutomaticSearch ?? existing.EnableAutomaticSearch;
|
||||||
|
existing.EnableInteractiveSearch = resource.EnableInteractiveSearch ?? existing.EnableInteractiveSearch;
|
||||||
|
existing.Priority = resource.Priority ?? existing.Priority;
|
||||||
|
existing.SeasonSearchMaximumSingleEpisodeAge = resource.SeasonSearchMaximumSingleEpisodeAge ?? existing.SeasonSearchMaximumSingleEpisodeAge;
|
||||||
|
});
|
||||||
|
|
||||||
|
return existingDefinitions;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using NzbDrone.Core.Indexers;
|
||||||
|
using NzbDrone.Core.Validation;
|
||||||
|
using NzbDrone.SignalR;
|
||||||
|
using Sonarr.Api.V5.Provider;
|
||||||
|
using Sonarr.Http;
|
||||||
|
|
||||||
|
namespace Sonarr.Api.V5.Indexers;
|
||||||
|
|
||||||
|
[V5ApiController]
|
||||||
|
public class IndexerController : ProviderControllerBase<IndexerResource, IndexerBulkResource, IIndexer, IndexerDefinition>
|
||||||
|
{
|
||||||
|
public static readonly IndexerResourceMapper ResourceMapper = new();
|
||||||
|
public static readonly IndexerBulkResourceMapper BulkResourceMapper = new();
|
||||||
|
|
||||||
|
public IndexerController(IBroadcastSignalRMessage signalRBroadcaster,
|
||||||
|
IndexerFactory indexerFactory,
|
||||||
|
DownloadClientExistsValidator downloadClientExistsValidator)
|
||||||
|
: base(signalRBroadcaster, indexerFactory, "indexer", ResourceMapper, BulkResourceMapper)
|
||||||
|
{
|
||||||
|
SharedValidator.RuleFor(c => c.Priority).InclusiveBetween(1, 50);
|
||||||
|
SharedValidator.RuleFor(c => c.SeasonSearchMaximumSingleEpisodeAge).GreaterThanOrEqualTo(0);
|
||||||
|
SharedValidator.RuleFor(c => c.DownloadClientId).SetValidator(downloadClientExistsValidator);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using Sonarr.Http;
|
||||||
|
|
||||||
|
namespace Sonarr.Api.V5.Indexers;
|
||||||
|
|
||||||
|
[V5ApiController]
|
||||||
|
public class IndexerFlagController : Controller
|
||||||
|
{
|
||||||
|
[HttpGet]
|
||||||
|
public List<IndexerFlagResource> GetAll()
|
||||||
|
{
|
||||||
|
return Enum.GetValues(typeof(IndexerFlags)).Cast<IndexerFlags>().Select(f => new IndexerFlagResource
|
||||||
|
{
|
||||||
|
Id = (int)f,
|
||||||
|
Name = f.ToString()
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Sonarr.Http.REST;
|
||||||
|
|
||||||
|
namespace Sonarr.Api.V5.Indexers;
|
||||||
|
|
||||||
|
public class IndexerFlagResource : RestResource
|
||||||
|
{
|
||||||
|
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
|
||||||
|
public new int Id { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
public string? NameLower => Name?.ToLowerInvariant();
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using NzbDrone.Core.Indexers;
|
||||||
|
using Sonarr.Api.V5.Provider;
|
||||||
|
|
||||||
|
namespace Sonarr.Api.V5.Indexers;
|
||||||
|
|
||||||
|
public class IndexerResource : ProviderResource<IndexerResource>
|
||||||
|
{
|
||||||
|
public bool EnableRss { get; set; }
|
||||||
|
public bool EnableAutomaticSearch { get; set; }
|
||||||
|
public bool EnableInteractiveSearch { get; set; }
|
||||||
|
public bool SupportsRss { get; set; }
|
||||||
|
public bool SupportsSearch { get; set; }
|
||||||
|
public DownloadProtocol Protocol { get; set; }
|
||||||
|
public int Priority { get; set; }
|
||||||
|
public int SeasonSearchMaximumSingleEpisodeAge { get; set; }
|
||||||
|
public int DownloadClientId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class IndexerResourceMapper : ProviderResourceMapper<IndexerResource, IndexerDefinition>
|
||||||
|
{
|
||||||
|
public override IndexerResource ToResource(IndexerDefinition definition)
|
||||||
|
{
|
||||||
|
var resource = base.ToResource(definition);
|
||||||
|
|
||||||
|
resource.EnableRss = definition.EnableRss;
|
||||||
|
resource.EnableAutomaticSearch = definition.EnableAutomaticSearch;
|
||||||
|
resource.EnableInteractiveSearch = definition.EnableInteractiveSearch;
|
||||||
|
resource.SupportsRss = definition.SupportsRss;
|
||||||
|
resource.SupportsSearch = definition.SupportsSearch;
|
||||||
|
resource.Protocol = definition.Protocol;
|
||||||
|
resource.Priority = definition.Priority;
|
||||||
|
resource.SeasonSearchMaximumSingleEpisodeAge = definition.SeasonSearchMaximumSingleEpisodeAge;
|
||||||
|
resource.DownloadClientId = definition.DownloadClientId;
|
||||||
|
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IndexerDefinition ToModel(IndexerResource resource, IndexerDefinition? existingDefinition)
|
||||||
|
{
|
||||||
|
var definition = base.ToModel(resource, existingDefinition);
|
||||||
|
|
||||||
|
definition.EnableRss = resource.EnableRss;
|
||||||
|
definition.EnableAutomaticSearch = resource.EnableAutomaticSearch;
|
||||||
|
definition.EnableInteractiveSearch = resource.EnableInteractiveSearch;
|
||||||
|
definition.Priority = resource.Priority;
|
||||||
|
definition.SeasonSearchMaximumSingleEpisodeAge = resource.SeasonSearchMaximumSingleEpisodeAge;
|
||||||
|
definition.DownloadClientId = resource.DownloadClientId;
|
||||||
|
|
||||||
|
return definition;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user