mirror of https://github.com/Sonarr/Sonarr
fixed schema support for indexers
This commit is contained in:
parent
0eec2cd5f7
commit
4f9b745e70
|
@ -63,15 +63,17 @@ namespace NzbDrone.Api.Indexers
|
|||
{
|
||||
var indexer = GetDefinition(indexerResource);
|
||||
|
||||
ValidateIndexer(indexer.Settings);
|
||||
ValidateIndexer(indexer);
|
||||
|
||||
_indexerService.Update(indexer);
|
||||
}
|
||||
|
||||
|
||||
private static void ValidateIndexer(IProviderConfig config)
|
||||
private static void ValidateIndexer(ProviderDefinition definition)
|
||||
{
|
||||
var validationResult = config.Validate();
|
||||
if (!definition.Enable) return;
|
||||
|
||||
var validationResult = definition.Settings.Validate();
|
||||
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
|
@ -89,10 +91,7 @@ namespace NzbDrone.Api.Indexers
|
|||
var configContract = ReflectionExtensions.CoreAssembly.FindTypeByName(definition.ConfigContract);
|
||||
definition.Settings = (IProviderConfig)SchemaBuilder.ReadFormSchema(indexerResource.Fields, configContract);
|
||||
|
||||
if (indexerResource.Enable)
|
||||
{
|
||||
ValidateIndexer(definition.Settings);
|
||||
}
|
||||
ValidateIndexer(definition);
|
||||
|
||||
return definition;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Api.ClientSchema;
|
||||
using NzbDrone.Api.Mapping;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using Omu.ValueInjecter;
|
||||
|
||||
|
@ -20,24 +20,21 @@ namespace NzbDrone.Api.Indexers
|
|||
private List<IndexerResource> GetSchema()
|
||||
{
|
||||
|
||||
var indexers = _indexerService.All().InjectTo<List<IndexerResource>>();
|
||||
var indexers = _indexerService.Templates().Where(c => c.Implementation =="Newznab");
|
||||
|
||||
/* var indexers = _indexerService.Schema();
|
||||
|
||||
var result = new List<IndexerResource>(indexers.Count);
|
||||
var result = new List<IndexerResource>(indexers.Count());
|
||||
|
||||
foreach (var indexer in indexers)
|
||||
{
|
||||
var indexerResource = new IndexerResource();
|
||||
indexerResource.InjectFrom(indexer);
|
||||
indexerResource.Fields = SchemaBuilder.GenerateSchema(indexer.Settings);
|
||||
foreach (var indexer in indexers)
|
||||
{
|
||||
var indexerResource = new IndexerResource();
|
||||
indexerResource.InjectFrom(indexer);
|
||||
indexerResource.Fields = SchemaBuilder.ToSchema(indexer.Settings);
|
||||
|
||||
result.Add(indexerResource);
|
||||
}
|
||||
result.Add(indexerResource);
|
||||
}
|
||||
|
||||
return result;*/
|
||||
|
||||
return indexers;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Reflection;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
|
@ -17,6 +18,7 @@ namespace NzbDrone.Core.ThingiProvider
|
|||
TProviderDefinition Create(TProviderDefinition indexer);
|
||||
void Update(TProviderDefinition indexer);
|
||||
void Delete(int id);
|
||||
List<TProviderDefinition> Templates();
|
||||
}
|
||||
|
||||
public abstract class ProviderFactory<TProvider, TProviderDefinition> : IProviderFactory<TProvider, TProviderDefinition>, IHandle<ApplicationStartedEvent>
|
||||
|
@ -40,6 +42,16 @@ namespace NzbDrone.Core.ThingiProvider
|
|||
return _providerRepository.All().ToList();
|
||||
}
|
||||
|
||||
public List<TProviderDefinition> Templates()
|
||||
{
|
||||
return _providers.Select(p => new TProviderDefinition()
|
||||
{
|
||||
ConfigContract = p.ConfigContract.Name,
|
||||
Implementation = p.GetType().Name,
|
||||
Settings = (IProviderConfig)Activator.CreateInstance(ReflectionExtensions.CoreAssembly.FindTypeByName(p.ConfigContract.Name))
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public List<TProvider> GetAvailableProviders()
|
||||
{
|
||||
return All().Where(c => c.Enable && c.Settings.Validate().IsValid)
|
||||
|
|
Loading…
Reference in New Issue