mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-20 21:54:58 -04:00
Provider testing improvements
New: Test button for indexers in UI Fixed: Testing download clients shows error messages in UI Fixed: Testing notifications shows error messages in UI
This commit is contained in:
@@ -23,7 +23,10 @@ namespace NzbDrone.Api
|
||||
: base(resource)
|
||||
{
|
||||
_providerFactory = providerFactory;
|
||||
|
||||
Get["schema"] = x => GetTemplates();
|
||||
Post["test"] = x => Test(ReadResourceFromRequest());
|
||||
|
||||
GetResourceAll = GetAll;
|
||||
GetResourceById = GetProviderById;
|
||||
CreateResource = CreateProvider;
|
||||
@@ -63,16 +66,26 @@ namespace NzbDrone.Api
|
||||
|
||||
private int CreateProvider(TProviderResource providerResource)
|
||||
{
|
||||
var provider = GetDefinition(providerResource);
|
||||
provider = _providerFactory.Create(provider);
|
||||
return provider.Id;
|
||||
var providerDefinition = GetDefinition(providerResource);
|
||||
|
||||
if (providerDefinition.Enable)
|
||||
{
|
||||
Test(providerDefinition);
|
||||
}
|
||||
|
||||
providerDefinition = _providerFactory.Create(providerDefinition);
|
||||
|
||||
return providerDefinition.Id;
|
||||
}
|
||||
|
||||
private void UpdateProvider(TProviderResource providerResource)
|
||||
{
|
||||
var providerDefinition = GetDefinition(providerResource);
|
||||
|
||||
Validate(providerDefinition);
|
||||
if (providerDefinition.Enable)
|
||||
{
|
||||
Test(providerDefinition);
|
||||
}
|
||||
|
||||
_providerFactory.Update(providerDefinition);
|
||||
}
|
||||
@@ -133,6 +146,25 @@ namespace NzbDrone.Api
|
||||
return result.AsResponse();
|
||||
}
|
||||
|
||||
private Response Test(TProviderResource providerResource)
|
||||
{
|
||||
var providerDefinition = GetDefinition(providerResource);
|
||||
|
||||
Test(providerDefinition);
|
||||
|
||||
return "{}";
|
||||
}
|
||||
|
||||
private void Test(TProviderDefinition providerDefinition)
|
||||
{
|
||||
var result = _providerFactory.Test(providerDefinition);
|
||||
|
||||
if (!result.IsValid)
|
||||
{
|
||||
throw new ValidationException(result.Errors);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Validate(TProviderDefinition definition)
|
||||
{
|
||||
var validationResult = definition.Settings.Validate();
|
||||
@@ -143,4 +175,4 @@ namespace NzbDrone.Api
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user