mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 02:37:08 -07:00
indexer specific setting validation
This commit is contained in:
parent
227e13d858
commit
e4fc0c57b3
11 changed files with 93 additions and 26 deletions
|
@ -1,11 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation.Internal;
|
||||
using NzbDrone.Api.ClientSchema;
|
||||
using NzbDrone.Api.Mapping;
|
||||
using NzbDrone.Api.REST;
|
||||
using NzbDrone.Api.Validation;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using Omu.ValueInjecter;
|
||||
using FluentValidation;
|
||||
|
@ -28,8 +26,6 @@ namespace NzbDrone.Api.Indexers
|
|||
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||||
SharedValidator.RuleFor(c => c.Implementation).NotEmpty();
|
||||
|
||||
SharedValidator.RuleForField<string>(c=>c.Fields,"Url").NotEmpty();
|
||||
|
||||
PostValidator.RuleFor(c => c.Fields).NotEmpty();
|
||||
}
|
||||
|
||||
|
@ -67,6 +63,9 @@ namespace NzbDrone.Api.Indexers
|
|||
var indexer = _indexerService.Get(indexerResource.Id);
|
||||
indexer.InjectFrom(indexerResource);
|
||||
indexer.Settings = SchemaDeserializer.DeserializeSchema(indexer.Settings, indexerResource.Fields);
|
||||
|
||||
ValidateSetting(indexer.Settings);
|
||||
|
||||
indexer = _indexerService.Update(indexer);
|
||||
|
||||
var response = indexer.InjectTo<IndexerResource>();
|
||||
|
@ -75,6 +74,17 @@ namespace NzbDrone.Api.Indexers
|
|||
return response;
|
||||
}
|
||||
|
||||
|
||||
private static void ValidateSetting(IIndexerSetting setting)
|
||||
{
|
||||
var validationResult = setting.Validate();
|
||||
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
throw new ValidationException(validationResult.Errors);
|
||||
}
|
||||
}
|
||||
|
||||
private Indexer GetIndexer(IndexerResource indexerResource)
|
||||
{
|
||||
var indexer = _indexerService.Schema()
|
||||
|
@ -90,6 +100,8 @@ namespace NzbDrone.Api.Indexers
|
|||
indexer.InjectFrom(indexerResource);
|
||||
indexer.Settings = SchemaDeserializer.DeserializeSchema(indexer.Settings, indexerResource.Fields);
|
||||
|
||||
ValidateSetting(indexer.Settings);
|
||||
|
||||
return indexer;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue