mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-27 22:57:09 -04:00
933c23ce57
(cherry picked from commit a117001de673e80abd90d54a34a7c86292b3a649)
32 lines
894 B
C#
32 lines
894 B
C#
using FluentValidation;
|
|
using FluentValidation.Validators;
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
namespace NzbDrone.Core.Validation
|
|
{
|
|
public static class UrlValidation
|
|
{
|
|
public static IRuleBuilderOptions<T, string> IsValidUrl<T>(this IRuleBuilder<T, string> ruleBuilder)
|
|
{
|
|
return ruleBuilder.SetValidator(new UrlValidator());
|
|
}
|
|
}
|
|
|
|
public class UrlValidator : PropertyValidator
|
|
{
|
|
protected override string GetDefaultMessageTemplate() => "Invalid Url: '{url}'";
|
|
|
|
protected override bool IsValid(PropertyValidatorContext context)
|
|
{
|
|
if (context.PropertyValue == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
context.MessageFormatter.AppendArgument("url", context.PropertyValue.ToString());
|
|
|
|
return context.PropertyValue.ToString().IsValidUrl();
|
|
}
|
|
}
|
|
}
|