New: Add Test all functionality to API (Clients/Indexers/Lists)

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
pull/528/head
Qstick 6 years ago
parent 1d1aca8fb7
commit 4347e92bef

@ -107,6 +107,7 @@
<Compile Include="Profiles\Metadata\MetadataValidator.cs" /> <Compile Include="Profiles\Metadata\MetadataValidator.cs" />
<Compile Include="Profiles\Quality\QualityCutoffValidator.cs" /> <Compile Include="Profiles\Quality\QualityCutoffValidator.cs" />
<Compile Include="Profiles\Quality\QualityItemsValidator.cs" /> <Compile Include="Profiles\Quality\QualityItemsValidator.cs" />
<Compile Include="ProviderTestAllResult.cs" />
<Compile Include="TrackFiles\TrackFileListResource.cs" /> <Compile Include="TrackFiles\TrackFileListResource.cs" />
<Compile Include="TrackFiles\MediaInfoResource.cs" /> <Compile Include="TrackFiles\MediaInfoResource.cs" />
<Compile Include="Indexers\ReleaseModuleBase.cs" /> <Compile Include="Indexers\ReleaseModuleBase.cs" />

@ -28,6 +28,7 @@ namespace Lidarr.Api.V1
Get["schema"] = x => GetTemplates(); Get["schema"] = x => GetTemplates();
Post["test"] = x => Test(ReadResourceFromRequest(true)); Post["test"] = x => Test(ReadResourceFromRequest(true));
Post["testall"] = x => TestAll();
Post["action/{action}"] = x => RequestAction(x.action, ReadResourceFromRequest(true)); Post["action/{action}"] = x => RequestAction(x.action, ReadResourceFromRequest(true));
GetResourceAll = GetAll; GetResourceAll = GetAll;
@ -144,6 +145,27 @@ namespace Lidarr.Api.V1
return "{}"; return "{}";
} }
private Response TestAll()
{
var providerDefinitions = _providerFactory.All()
.Where(c => c.Settings.Validate().IsValid && c.Enable)
.ToList();
var result = new List<ProviderTestAllResult>();
foreach (var definition in providerDefinitions)
{
var validationResult = _providerFactory.Test(definition);
result.Add(new ProviderTestAllResult
{
Id = definition.Id,
ValidationFailures = validationResult.Errors.ToList()
});
}
return result.AsResponse(result.Any(c => !c.IsValid) ? HttpStatusCode.BadRequest : HttpStatusCode.OK);
}
private Response RequestAction(string action, TProviderResource providerResource) private Response RequestAction(string action, TProviderResource providerResource)
{ {
var providerDefinition = GetDefinition(providerResource, true, false); var providerDefinition = GetDefinition(providerResource, true, false);

@ -0,0 +1,18 @@
using System.Collections.Generic;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
namespace Lidarr.Api.V1
{
public class ProviderTestAllResult
{
public int Id { get; set; }
public bool IsValid => ValidationFailures.Empty();
public List<ValidationFailure> ValidationFailures { get; set; }
public ProviderTestAllResult()
{
ValidationFailures = new List<ValidationFailure>();
}
}
}
Loading…
Cancel
Save