mirror of
https://github.com/Radarr/Radarr
synced 2025-01-03 22:04:43 +00:00
fixed schema support for indexers
This commit is contained in:
parent
0eec2cd5f7
commit
4f9b745e70
3 changed files with 29 additions and 21 deletions
|
@ -63,15 +63,17 @@ private void UpdateIndexer(IndexerResource indexerResource)
|
||||||
{
|
{
|
||||||
var indexer = GetDefinition(indexerResource);
|
var indexer = GetDefinition(indexerResource);
|
||||||
|
|
||||||
ValidateIndexer(indexer.Settings);
|
ValidateIndexer(indexer);
|
||||||
|
|
||||||
_indexerService.Update(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)
|
if (!validationResult.IsValid)
|
||||||
{
|
{
|
||||||
|
@ -89,10 +91,7 @@ private IndexerDefinition GetDefinition(IndexerResource indexerResource)
|
||||||
var configContract = ReflectionExtensions.CoreAssembly.FindTypeByName(definition.ConfigContract);
|
var configContract = ReflectionExtensions.CoreAssembly.FindTypeByName(definition.ConfigContract);
|
||||||
definition.Settings = (IProviderConfig)SchemaBuilder.ReadFormSchema(indexerResource.Fields, configContract);
|
definition.Settings = (IProviderConfig)SchemaBuilder.ReadFormSchema(indexerResource.Fields, configContract);
|
||||||
|
|
||||||
if (indexerResource.Enable)
|
ValidateIndexer(definition);
|
||||||
{
|
|
||||||
ValidateIndexer(definition.Settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NzbDrone.Api.ClientSchema;
|
using NzbDrone.Api.ClientSchema;
|
||||||
using NzbDrone.Api.Mapping;
|
|
||||||
using NzbDrone.Core.Indexers;
|
using NzbDrone.Core.Indexers;
|
||||||
using Omu.ValueInjecter;
|
using Omu.ValueInjecter;
|
||||||
|
|
||||||
|
@ -20,24 +20,21 @@ public IndexerSchemaModule(IIndexerService indexerService)
|
||||||
private List<IndexerResource> GetSchema()
|
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)
|
foreach (var indexer in indexers)
|
||||||
{
|
{
|
||||||
var indexerResource = new IndexerResource();
|
var indexerResource = new IndexerResource();
|
||||||
indexerResource.InjectFrom(indexer);
|
indexerResource.InjectFrom(indexer);
|
||||||
indexerResource.Fields = SchemaBuilder.GenerateSchema(indexer.Settings);
|
indexerResource.Fields = SchemaBuilder.ToSchema(indexer.Settings);
|
||||||
|
|
||||||
result.Add(indexerResource);
|
result.Add(indexerResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;*/
|
return result;
|
||||||
|
|
||||||
return indexers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using NzbDrone.Common.Reflection;
|
||||||
using NzbDrone.Core.Lifecycle;
|
using NzbDrone.Core.Lifecycle;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@ public interface IProviderFactory<TProvider, TProviderDefinition>
|
||||||
TProviderDefinition Create(TProviderDefinition indexer);
|
TProviderDefinition Create(TProviderDefinition indexer);
|
||||||
void Update(TProviderDefinition indexer);
|
void Update(TProviderDefinition indexer);
|
||||||
void Delete(int id);
|
void Delete(int id);
|
||||||
|
List<TProviderDefinition> Templates();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class ProviderFactory<TProvider, TProviderDefinition> : IProviderFactory<TProvider, TProviderDefinition>, IHandle<ApplicationStartedEvent>
|
public abstract class ProviderFactory<TProvider, TProviderDefinition> : IProviderFactory<TProvider, TProviderDefinition>, IHandle<ApplicationStartedEvent>
|
||||||
|
@ -40,6 +42,16 @@ public List<TProviderDefinition> All()
|
||||||
return _providerRepository.All().ToList();
|
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()
|
public List<TProvider> GetAvailableProviders()
|
||||||
{
|
{
|
||||||
return All().Where(c => c.Enable && c.Settings.Validate().IsValid)
|
return All().Where(c => c.Enable && c.Settings.Validate().IsValid)
|
||||||
|
|
Loading…
Reference in a new issue