1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-22 22:15:17 -04:00

new: smarter validation for newznab indexer settings

This commit is contained in:
kayone
2013-12-01 13:33:53 -08:00
parent 53cebdee17
commit be3ec7ddb8
8 changed files with 98 additions and 7 deletions
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
@@ -10,9 +11,25 @@ namespace NzbDrone.Core.Indexers.Newznab
{
public class NewznabSettingsValidator : AbstractValidator<NewznabSettings>
{
private static readonly string[] ApiKeyWhiteList =
{
"nzbs.org",
"nzb.su",
"dognzb.cr",
"nzbplanet.net",
"nzbid.org",
"nzbndx.com",
};
private static bool ShouldHaveApiKey(NewznabSettings settings)
{
return ApiKeyWhiteList.Any(c => settings.Url.ToLowerInvariant().Contains(c));
}
public NewznabSettingsValidator()
{
RuleFor(c => c.Url).ValidRootUrl();
RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey);
}
}