Files
Readarr/src/NzbDrone.Core/Validation/Paths/FileExistsValidator.cs
Mark McDowall 84f22dbadc New: Require password confirmation when setting or changing password
(cherry picked from commit b248163df598dc611ee919d525eb7357256d73d5)

Closes #3089
2024-06-06 11:46:54 +03:00

30 lines
832 B
C#

using FluentValidation.Validators;
using NzbDrone.Common.Disk;
namespace NzbDrone.Core.Validation.Paths
{
public class FileExistsValidator : PropertyValidator
{
private readonly IDiskProvider _diskProvider;
public FileExistsValidator(IDiskProvider diskProvider)
{
_diskProvider = diskProvider;
}
protected override string GetDefaultMessageTemplate() => "File '{file}' does not exist";
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null)
{
return false;
}
context.MessageFormatter.AppendArgument("file", context.PropertyValue.ToString());
return _diskProvider.FileExists(context.PropertyValue.ToString());
}
}
}